repo stringlengths 1 99 | file stringlengths 13 215 | code stringlengths 12 59.2M | file_length int64 12 59.2M | avg_line_length float64 3.82 1.48M | max_line_length int64 12 2.51M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
PiMAE | PiMAE-main/Pretrain/models/Point_MAE.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import timm
from timm.models.layers import DropPath, trunc_normal_
import numpy as np
from .build import MODELS
from utils import misc
from utils.checkpoint import get_missing_parameters_message, get_unexpected_parameters_message
from utils.logger impor... | 22,407 | 37.108844 | 128 | py |
PiMAE | PiMAE-main/Pretrain/models/models_mae.py | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
# --------------------------------------------------------
# References:
# timm: https://github.com/rwightman/pytorch-image... | 11,390 | 38.010274 | 145 | py |
PiMAE | PiMAE-main/Pretrain/models/multimae_utils.py | # Copyright (c) EPFL VILAB.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
# --------------------------------------------------------
# Based on timm, DeiT, DINO, MoCo-v3, BEiT, MAE-priv and MAE code bases
# https://github.... | 10,160 | 39.003937 | 122 | py |
PiMAE | PiMAE-main/Pretrain/models/transformer.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Modified from DETR Transformer class.
Copy-paste from torch.nn.Transformer with modifications:
* positional encodings are passed in MHattention
* extra LN at the end of encoder is removed
* decoder returns a stack of activations fro... | 17,490 | 39.116972 | 119 | py |
PiMAE | PiMAE-main/Pretrain/models/build.py | from utils import registry
#
import math
from functools import partial
import numpy as np
import torch
import torch.nn as nn
import sys
import third_party.models_mae as models_mae
from models.pimae import PiMAE
from tools import builder
MODELS = registry.Registry('models')
def build_model_from_cfg(cfg, **kwargs)... | 897 | 17.708333 | 121 | py |
PiMAE | PiMAE-main/Pretrain/utils_detr/ap_calculator.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
""" Helper functions and class to calculate Average Precisions for 3D object detection.
"""
import logging
import os
import sys
from collectio... | 17,579 | 37.980044 | 125 | py |
PiMAE | PiMAE-main/Pretrain/utils_detr/pc_util.py | # Copyright (c) Facebook, Inc. and its affiliates.
""" Utility functions for processing point clouds.
Author: Charles R. Qi and Or Litany
"""
import os
import sys
import torch
# Point cloud IO
import numpy as np
from plyfile import PlyData, PlyElement
# Mesh IO
import trimesh
# -----------------------------------... | 9,538 | 31.335593 | 88 | py |
PiMAE | PiMAE-main/Pretrain/utils_detr/box_ops3d.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Utilities for bounding box manipulation and GIoU.
"""
import torch
from torchvision.ops.boxes import box_area
from typing import List
try:
from box_intersection import batch_intersect
except ImportError:
print("Could not import cythonize... | 29,623 | 37.572917 | 152 | py |
PiMAE | PiMAE-main/Pretrain/utils_detr/misc.py | # Copyright (c) Facebook, Inc. and its affiliates.
import torch
import numpy as np
from collections import deque
from typing import List
from utils_detr.dist import is_distributed, barrier, all_reduce_sum
def my_worker_init_fn(worker_id):
np.random.seed(np.random.get_state()[1][0] + worker_id)
@torch.jit.ignore... | 2,652 | 25.267327 | 89 | py |
PiMAE | PiMAE-main/Pretrain/utils_detr/logger.py | # Copyright (c) Facebook, Inc. and its affiliates.
import torch
try:
from tensorboardX import SummaryWriter
except ImportError:
print("Cannot import tensorboard. Will log to txt files only.")
SummaryWriter = None
from utils.dist import is_primary
class Logger(object):
def __init__(self, log_dir=Non... | 890 | 26.84375 | 67 | py |
PiMAE | PiMAE-main/Pretrain/utils_detr/box_util.py | # Copyright (c) Facebook, Inc. and its affiliates.
""" Helper functions for calculating 2D and 3D bounding box IoU.
Collected and written by Charles R. Qi
Last modified: Apr 2021 by Ishan Misra
"""
import torch
import numpy as np
from scipy.spatial import ConvexHull, Delaunay
from utils_detr.misc import to_list_1d, t... | 25,282 | 33.258808 | 116 | py |
PiMAE | PiMAE-main/Pretrain/utils_detr/download_weights.py | # Copyright (c) Facebook, Inc. and its affiliates.
import os
from urllib import request
import torch
import pickle
## Define the weights you want and where to store them
dataset = "scannet"
encoder = "_masked" # or ""
epoch = 1080
base_url = "https://dl.fbaipublicfiles.com/3detr/checkpoints"
local_dir = "/tmp/"
###... | 1,144 | 29.945946 | 69 | py |
PiMAE | PiMAE-main/Pretrain/utils_detr/dist.py | # Copyright (c) Facebook, Inc. and its affiliates.
import pickle
import torch
import torch.distributed as dist
def is_distributed():
if not dist.is_available() or not dist.is_initialized():
return False
return True
def get_rank():
if not is_distributed():
return 0
return dist.get_ra... | 5,165 | 28.186441 | 97 | py |
PiMAE | PiMAE-main/Pretrain/utils_detr/io.py | # Copyright (c) Facebook, Inc. and its affiliates.
import torch
import os
from utils.dist import is_primary
def save_checkpoint(
checkpoint_dir,
model_no_ddp,
optimizer,
epoch,
args,
best_val_metrics,
filename=None,
):
if not is_primary():
return
if filename is None:
... | 1,531 | 24.966102 | 87 | py |
PiMAE | PiMAE-main/Pretrain/datasets/sunrgbd.py | # Copyright (c) Facebook, Inc. and its affiliates.
"""
Modified from https://github.com/facebookresearch/votenet
Dataset for 3D object detection on SUN RGB-D (with support of vote supervision).
A sunrgbd oriented bounding box is parameterized by (cx,cy,cz), (l,w,h) -- (dx,dy,dz) in upright depth coord
(Z is up, Y i... | 12,843 | 39.012461 | 120 | py |
PiMAE | PiMAE-main/Pretrain/datasets/scannet.py | # Copyright (c) Facebook, Inc. and its affiliates.
"""
Modified from https://github.com/facebookresearch/votenet
Dataset for object bounding box regression.
An axis aligned bounding box is parameterized by (cx,cy,cz) and (dx,dy,dz)
where (cx,cy,cz) is the center point of the box, dx is the x-axis length of the box.
"... | 13,686 | 36.705234 | 90 | py |
PiMAE | PiMAE-main/Pretrain/datasets/data_transforms.py | import numpy as np
import torch
import random
class PointcloudRotate(object):
def __call__(self, pc):
bsize = pc.size()[0]
for i in range(bsize):
rotation_angle = np.random.uniform() * 2 * np.pi
cosval = np.cos(rotation_angle)
sinval = np.sin(rotation_angle)
... | 4,190 | 34.820513 | 131 | py |
PiMAE | PiMAE-main/Pretrain/extensions/chamfer_dist/test.py | # -*- coding: utf-8 -*-
# @Author: Haozhe Xie
# @Date: 2019-12-10 10:38:01
# @Last Modified by: Haozhe Xie
# @Last Modified time: 2019-12-26 14:21:36
# @Email: cshzxie@gmail.com
#
# Note:
# - Replace float -> double, kFloat -> kDouble in chamfer.cu
import os
import sys
import torch
import unittest
from torch.au... | 950 | 23.384615 | 105 | py |
PiMAE | PiMAE-main/Pretrain/extensions/chamfer_dist/setup.py | # -*- coding: utf-8 -*-
# @Author: Haozhe Xie
# @Date: 2019-08-07 20:54:24
# @Last Modified by: Haozhe Xie
# @Last Modified time: 2019-12-10 10:04:25
# @Email: cshzxie@gmail.com
from setuptools import setup
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
setup(name='chamfer',
version='2... | 515 | 24.8 | 67 | py |
PiMAE | PiMAE-main/Pretrain/extensions/chamfer_dist/__init__.py | # -*- coding: utf-8 -*-
# @Author: Thibault GROUEIX
# @Date: 2019-08-07 20:54:24
# @Last Modified by: Haozhe Xie
# @Last Modified time: 2019-12-18 15:06:25
# @Email: cshzxie@gmail.com
import torch
import chamfer
class ChamferFunction(torch.autograd.Function):
@staticmethod
def forward(ctx, xyz1, xyz2):... | 2,753 | 31.023256 | 95 | py |
PiMAE | PiMAE-main/Pretrain/extensions/emd/emd.py | import torch
import emd_cuda
class EarthMoverDistanceFunction(torch.autograd.Function):
@staticmethod
def forward(ctx, xyz1, xyz2):
xyz1 = xyz1.contiguous()
xyz2 = xyz2.contiguous()
assert xyz1.is_cuda and xyz2.is_cuda, "Only support cuda currently."
match = emd_cuda.approxmatc... | 2,076 | 27.452055 | 88 | py |
PiMAE | PiMAE-main/Pretrain/extensions/emd/setup.py | """Setup extension
Notes:
If extra_compile_args is provided, you need to provide different instances for different extensions.
Refer to https://github.com/pytorch/pytorch/issues/20169
"""
from setuptools import setup
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
setup(
name='emd_e... | 642 | 21.964286 | 104 | py |
PiMAE | PiMAE-main/Pretrain/extensions/emd/test_emd_loss.py | import torch
import numpy as np
import time
from emd import earth_mover_distance
# gt
p1 = torch.from_numpy(np.array([[[1.7, -0.1, 0.1], [0.1, 1.2, 0.3]]], dtype=np.float32)).cuda()
p1 = p1.repeat(3, 1, 1)
p2 = torch.from_numpy(np.array([[[0.3, 1.8, 0.2], [1.2, -0.2, 0.3]]], dtype=np.float32)).cuda()
p2 = p2.repeat(3,... | 1,223 | 25.608696 | 95 | py |
PiMAE | PiMAE-main/Pretrain/utils/parser.py | import os
import argparse
from pathlib import Path
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument('--wandb', action='store_true',
help='Use wandb to record training or not')
parser.set_defaults(wandb=False)
# joint mae arguments
parser.add_argument('-... | 5,129 | 37 | 133 | py |
PiMAE | PiMAE-main/Pretrain/utils/checkpoint.py | #!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
import copy
import logging
import os
from collections import defaultdict
import torch
import torch.nn as nn
from typing import Any
from typing import Optional, List, Dict, NamedTuple, Tuple, Iterable
from termcolor import ... | 4,056 | 29.503759 | 85 | py |
PiMAE | PiMAE-main/Pretrain/utils/matcher.py | import numpy as np
import cv2
import os
import scipy.io as sio # to load .mat files for depth points
def flip_axis_to_camera(pc):
''' Flip X-right,Y-forward,Z-up to X-right,Y-down,Z-forward
Input and output are both (N,3) array
'''
pc2 = np.copy(pc)
pc2[:,[0,1,2]] = pc2[:,[0,2,1]] # cam X,Y,Z ... | 1,409 | 30.333333 | 70 | py |
PiMAE | PiMAE-main/Pretrain/utils/dist_utils.py | import os
import torch
import torch.multiprocessing as mp
from torch import distributed as dist
def init_dist(launcher, backend='nccl', **kwargs):
if mp.get_start_method(allow_none=True) is None:
mp.set_start_method('spawn')
if launcher == 'pytorch':
_init_dist_pytorch(backend, **kwargs)
... | 1,497 | 26.236364 | 71 | py |
PiMAE | PiMAE-main/Pretrain/utils/misc.py | import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import random
import torch
import torch.nn as nn
import torch.nn.functional as F
import os
from collections import abc
from pointnet2_ops import pointnet2_utils
def fps(data, number):
'''
data B N 3
number i... | 7,915 | 30.791165 | 150 | py |
PiMAE | PiMAE-main/Pretrain/utils/logger.py | import logging
import torch.distributed as dist
logger_initialized = {}
def get_root_logger(log_file=None, log_level=logging.INFO, name='main'):
"""Get root logger and add a keyword filter to it.
The logger will be initialized if it has not been initialized. By default a
StreamHandler will be added. If `l... | 4,922 | 37.76378 | 79 | py |
PiMAE | PiMAE-main/Downstream/MonoDETR/tools/train_val.py | import warnings
warnings.filterwarnings("ignore")
import os
import sys
import torch
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
ROOT_DIR = os.path.dirname(BASE_DIR)
sys.path.append(ROOT_DIR)
import yaml
import argparse
import datetime
from lib.helpers.model_helper import build_model
from lib.helpers.datal... | 3,852 | 33.097345 | 108 | py |
PiMAE | PiMAE-main/Downstream/MonoDETR/utils/misc.py | # ------------------------------------------------------------------------
# DETR (https://github.com/facebookresearch/detr)
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
# ------------------------------------------------------------------------
"""
Misc functions, including distributed helpe... | 15,656 | 31.823899 | 116 | py |
PiMAE | PiMAE-main/Downstream/MonoDETR/utils/box_ops.py | # ------------------------------------------------------------------------
# DETR (https://github.com/facebookresearch/detr)
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
# ------------------------------------------------------------------------
"""
Utilities for bounding box manipulation and... | 2,932 | 28.33 | 110 | py |
PiMAE | PiMAE-main/Downstream/3detr/main.py | # Copyright (c) Facebook, Inc. and its affiliates.
import argparse
import os
import sys
import pickle
import numpy as np
import torch
from torch.multiprocessing import set_start_method
from torch.utils.data import DataLoader, DistributedSampler
# 3DETR codebase specific imports
from datasets import build_dataset
fro... | 15,801 | 34.59009 | 134 | py |
PiMAE | PiMAE-main/Downstream/3detr/engine.py | # Copyright (c) Facebook, Inc. and its affiliates.
import torch
import datetime
import logging
import math
import time
import sys
from torch.distributed.distributed_c10d import reduce
from utils.ap_calculator import APCalculator
from utils.misc import SmoothedValue
from utils.dist import (
all_gather_dict,
all... | 7,402 | 32.65 | 202 | py |
PiMAE | PiMAE-main/Downstream/3detr/test_subset.py | # Copyright (c) Facebook, Inc. and its affiliates.
import argparse
import os
import sys
import pickle
import numpy as np
import torch
from torch.multiprocessing import set_start_method
from torch.utils.data import DataLoader, DistributedSampler
# 3DETR codebase specific imports
from datasets import build_dataset
fro... | 15,946 | 34.755605 | 134 | py |
PiMAE | PiMAE-main/Downstream/3detr/criterion.py | # Copyright (c) Facebook, Inc. and its affiliates.
import torch
import torch.nn as nn
import numpy as np
import torch.nn.functional as F
from utils.box_util import generalized_box3d_iou
from utils.dist import all_reduce_average
from utils.misc import huber_loss
from scipy.optimize import linear_sum_assignment
class M... | 15,927 | 39.120907 | 118 | py |
PiMAE | PiMAE-main/Downstream/3detr/main_load.py | # Copyright (c) Facebook, Inc. and its affiliates.
import argparse
import os
import sys
import pickle
import numpy as np
import torch
from torch.multiprocessing import set_start_method
from torch.utils.data import DataLoader, DistributedSampler
# 3DETR codebase specific imports
from datasets import build_dataset
fro... | 18,579 | 35.719368 | 135 | py |
PiMAE | PiMAE-main/Downstream/3detr/optimizer.py | # Copyright (c) Facebook, Inc. and its affiliates.
import torch
def build_optimizer(args, model):
param_groups = [
{"params": [p for n, p in model.named_parameters() if "encoder" not in n.split('.') and p.requires_grad]},
{
"params": [p for n, p in model.named_parameters() if "encoder... | 1,514 | 35.071429 | 114 | py |
PiMAE | PiMAE-main/Downstream/3detr/models/model_3detr.py | # Copyright (c) Facebook, Inc. and its affiliates.
import math
from functools import partial
import numpy as np
import torch
import torch.nn as nn
from third_party.pointnet2.pointnet2_modules import PointnetSAModuleVotes
from third_party.pointnet2.pointnet2_utils import furthest_point_sample
from utils.pc_util import ... | 16,744 | 38.586288 | 114 | py |
PiMAE | PiMAE-main/Downstream/3detr/models/position_embedding.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Various positional encodings for the transformer.
"""
import math
import torch
from torch import nn
import numpy as np
from utils.pc_util import shift_scale_points
class PositionEmbeddingCoordsSine(nn.Module):
def __init__(
self,
... | 4,850 | 33.65 | 103 | py |
PiMAE | PiMAE-main/Downstream/3detr/models/transformer.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Modified from DETR Transformer class.
Copy-paste from torch.nn.Transformer with modifications:
* positional encodings are passed in MHattention
* extra LN at the end of encoder is removed
* decoder returns a stack of activations fro... | 16,324 | 40.43401 | 119 | py |
PiMAE | PiMAE-main/Downstream/3detr/models/helpers.py | # Copyright (c) Facebook, Inc. and its affiliates.
import torch.nn as nn
from functools import partial
import copy
class BatchNormDim1Swap(nn.BatchNorm1d):
"""
Used for nn.Transformer that uses a HW x N x C rep
"""
def forward(self, x):
"""
x: HW x N x C
permute to N x C x HW
... | 3,180 | 26.188034 | 78 | py |
PiMAE | PiMAE-main/Downstream/3detr/datasets/sunrgbd.py | # Copyright (c) Facebook, Inc. and its affiliates.
"""
Modified from https://github.com/facebookresearch/votenet
Dataset for 3D object detection on SUN RGB-D (with support of vote supervision).
A sunrgbd oriented bounding box is parameterized by (cx,cy,cz), (l,w,h) -- (dx,dy,dz) in upright depth coord
(Z is up, Y i... | 15,877 | 37.632603 | 108 | py |
PiMAE | PiMAE-main/Downstream/3detr/datasets/scannet.py | # Copyright (c) Facebook, Inc. and its affiliates.
"""
Modified from https://github.com/facebookresearch/votenet
Dataset for object bounding box regression.
An axis aligned bounding box is parameterized by (cx,cy,cz) and (dx,dy,dz)
where (cx,cy,cz) is the center point of the box, dx is the x-axis length of the box.
"... | 13,729 | 36.928177 | 98 | py |
PiMAE | PiMAE-main/Downstream/3detr/utils/ap_calculator.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
""" Helper functions and class to calculate Average Precisions for 3D object detection.
"""
import logging
import os
import sys
from collectio... | 17,876 | 37.863043 | 125 | py |
PiMAE | PiMAE-main/Downstream/3detr/utils/pc_util.py | # Copyright (c) Facebook, Inc. and its affiliates.
""" Utility functions for processing point clouds.
Author: Charles R. Qi and Or Litany
"""
import os
import sys
import torch
# Point cloud IO
import numpy as np
from plyfile import PlyData, PlyElement
# Mesh IO
import trimesh
# -----------------------------------... | 9,538 | 31.335593 | 88 | py |
PiMAE | PiMAE-main/Downstream/3detr/utils/box_ops3d.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Utilities for bounding box manipulation and GIoU.
"""
import torch
from torchvision.ops.boxes import box_area
from typing import List
try:
from box_intersection import batch_intersect
except ImportError:
print("Could not import cythonize... | 29,623 | 37.572917 | 152 | py |
PiMAE | PiMAE-main/Downstream/3detr/utils/misc.py | # Copyright (c) Facebook, Inc. and its affiliates.
import torch
import numpy as np
from collections import deque
from typing import List
from utils.dist import is_distributed, barrier, all_reduce_sum
def my_worker_init_fn(worker_id):
np.random.seed(np.random.get_state()[1][0] + worker_id)
@torch.jit.ignore
def ... | 2,647 | 25.217822 | 89 | py |
PiMAE | PiMAE-main/Downstream/3detr/utils/logger.py | # Copyright (c) Facebook, Inc. and its affiliates.
import torch
try:
from tensorboardX import SummaryWriter
except ImportError:
print("Cannot import tensorboard. Will log to txt files only.")
SummaryWriter = None
from utils.dist import is_primary
class Logger(object):
def __init__(self, log_dir=Non... | 890 | 26.84375 | 67 | py |
PiMAE | PiMAE-main/Downstream/3detr/utils/box_util.py | # Copyright (c) Facebook, Inc. and its affiliates.
""" Helper functions for calculating 2D and 3D bounding box IoU.
Collected and written by Charles R. Qi
Last modified: Apr 2021 by Ishan Misra
"""
import torch
import numpy as np
from scipy.spatial import ConvexHull, Delaunay
from utils.misc import to_list_1d, to_lis... | 25,277 | 33.252033 | 116 | py |
PiMAE | PiMAE-main/Downstream/3detr/utils/download_weights.py | # Copyright (c) Facebook, Inc. and its affiliates.
import os
from urllib import request
import torch
import pickle
## Define the weights you want and where to store them
dataset = "scannet"
encoder = "_masked" # or ""
epoch = 1080
base_url = "https://dl.fbaipublicfiles.com/3detr/checkpoints"
local_dir = "/tmp/"
###... | 1,144 | 29.945946 | 69 | py |
PiMAE | PiMAE-main/Downstream/3detr/utils/dist.py | # Copyright (c) Facebook, Inc. and its affiliates.
import pickle
import torch
import torch.distributed as dist
def is_distributed():
if not dist.is_available() or not dist.is_initialized():
return False
return True
def get_rank():
if not is_distributed():
return 0
return dist.get_ra... | 5,165 | 28.186441 | 97 | py |
PiMAE | PiMAE-main/Downstream/3detr/utils/io.py | # Copyright (c) Facebook, Inc. and its affiliates.
import torch
import os
from utils.dist import is_primary
def save_checkpoint(
checkpoint_dir,
model_no_ddp,
optimizer,
epoch,
args,
best_val_metrics,
filename=None,
):
if not is_primary():
return
if filename is None:
... | 1,531 | 24.966102 | 87 | py |
PiMAE | PiMAE-main/Downstream/detr/main.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import argparse
import datetime
import json
import random
import time
from pathlib import Path
import numpy as np
import torch
from torch.utils.data import DataLoader, DistributedSampler
import datasets
import util.misc as utils
from datasets impo... | 14,178 | 47.064407 | 175 | py |
PiMAE | PiMAE-main/Downstream/detr/engine.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Train and eval functions used in main.py
"""
import math
import os
import sys
from typing import Iterable
import torch
import util.misc as utils
from datasets.coco_eval import CocoEvaluator
from datasets.panoptic_eval import PanopticEvaluator
... | 6,635 | 42.372549 | 103 | py |
PiMAE | PiMAE-main/Downstream/detr/hubconf.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import torch
from models.backbone import Backbone, Joiner
from models.detr import DETR, PostProcess
from models.position_encoding import PositionEmbeddingSine
from models.segmentation import DETRsegm, PostProcessPanoptic
from models.transformer imp... | 6,265 | 36.076923 | 117 | py |
PiMAE | PiMAE-main/Downstream/detr/converter.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Helper script to convert models trained with the main version of DETR to be used with the Detectron2 version.
"""
import json
import argparse
import numpy as np
import torch
def parse_args():
parser = argparse.ArgumentParser("D2 model con... | 2,591 | 36.028571 | 114 | py |
PiMAE | PiMAE-main/Downstream/detr/train_net.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
DETR Training Script.
This script is a simplified version of the training script in detectron2/tools.
"""
import os
import sys
import itertools
# fmt: off
sys.path.insert(1, os.path.join(sys.path[0], '..'))
# fmt: on
import time
from typing i... | 5,793 | 36.380645 | 185 | py |
PiMAE | PiMAE-main/Downstream/detr/models/detr.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
DETR model and criterion classes.
"""
import torch
import torch.nn.functional as F
from torch import nn
from util import box_ops
from util.misc import (NestedTensor, nested_tensor_from_tensor_list,
accuracy, get_world_siz... | 17,249 | 46.002725 | 113 | py |
PiMAE | PiMAE-main/Downstream/detr/models/transformer_3detr.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Modified from DETR Transformer class.
Copy-paste from torch.nn.Transformer with modifications:
* positional encodings are passed in MHattention
* extra LN at the end of encoder is removed
* decoder returns a stack of activations fro... | 16,413 | 40.035 | 119 | py |
PiMAE | PiMAE-main/Downstream/detr/models/matcher.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Modules to compute the matching cost and solve the corresponding LSAP.
"""
import torch
from scipy.optimize import linear_sum_assignment
from torch import nn
from util.box_ops import box_cxcywh_to_xyxy, generalized_box_iou
class HungarianMatc... | 4,250 | 47.862069 | 119 | py |
PiMAE | PiMAE-main/Downstream/detr/models/models_mae.py | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
# --------------------------------------------------------
# References:
# timm: https://github.com/rwightman/pytorch-image... | 2,176 | 29.236111 | 101 | py |
PiMAE | PiMAE-main/Downstream/detr/models/segmentation.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
This file provides the definition of the convolutional heads used to predict masks, as well as the losses
"""
import io
from collections import defaultdict
from typing import List, Optional
import torch
import torch.nn as nn
import torch.nn.fun... | 15,573 | 41.785714 | 120 | py |
PiMAE | PiMAE-main/Downstream/detr/models/position_encoding.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Various positional encodings for the transformer.
"""
import math
import torch
from torch import nn
from util.misc import NestedTensor
class PositionEmbeddingSine(nn.Module):
"""
This is a more standard version of the position embeddi... | 3,361 | 36.355556 | 103 | py |
PiMAE | PiMAE-main/Downstream/detr/models/backbone.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Backbone modules.
"""
from collections import OrderedDict
import copy
import torch
import torch.nn.functional as F
import torchvision
from torch import nn
from torchvision.models._utils import IntermediateLayerGetter
from typing import Dict, Li... | 10,740 | 38.634686 | 138 | py |
PiMAE | PiMAE-main/Downstream/detr/models/transformer.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
DETR Transformer class.
Copy-paste from torch.nn.Transformer with modifications:
* positional encodings are passed in MHattention
* extra LN at the end of encoder is removed
* decoder returns a stack of activations from all decoding... | 13,069 | 39.092025 | 98 | py |
PiMAE | PiMAE-main/Downstream/detr/models/helpers.py | # Copyright (c) Facebook, Inc. and its affiliates.
import torch.nn as nn
from functools import partial
import copy
class BatchNormDim1Swap(nn.BatchNorm1d):
"""
Used for nn.Transformer that uses a HW x N x C rep
"""
def forward(self, x):
"""
x: HW x N x C
permute to N x C x HW
... | 3,180 | 26.188034 | 78 | py |
PiMAE | PiMAE-main/Downstream/detr/models/transformer_orig.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
DETR Transformer class.
Copy-paste from torch.nn.Transformer with modifications:
* positional encodings are passed in MHattention
* extra LN at the end of encoder is removed
* decoder returns a stack of activations from all decoding... | 13,069 | 39.092025 | 98 | py |
PiMAE | PiMAE-main/Downstream/detr/d2/train_net.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
DETR Training Script.
This script is a simplified version of the training script in detectron2/tools.
"""
import os
import sys
import itertools
# fmt: off
sys.path.insert(1, os.path.join(sys.path[0], '..'))
# fmt: on
import time
from typing i... | 5,793 | 36.380645 | 185 | py |
PiMAE | PiMAE-main/Downstream/detr/d2/detr/detr.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import logging
import math
from typing import List
import numpy as np
import torch
import torch.distributed as dist
import torch.nn.functional as F
from scipy.optimize import linear_sum_assignment
from torch import nn
from detectron2.layers import... | 12,508 | 40.55814 | 118 | py |
PiMAE | PiMAE-main/Downstream/detr/d2/detr/dataset_mapper.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import copy
import logging
import numpy as np
import torch
from detectron2.data import detection_utils as utils
from detectron2.data import transforms as T
from detectron2.data.transforms import TransformGen
__all__ = ["DetrDatasetMapper"]
def ... | 4,570 | 36.162602 | 111 | py |
PiMAE | PiMAE-main/Downstream/detr/util/plot_utils.py | """
Plotting utilities to visualize training logs.
"""
import torch
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from pathlib import Path, PurePath
def plot_logs(logs, fields=('class_error', 'loss_bbox_unscaled', 'mAP'), ewm_col=0, log_name='log.txt'):
'''
Func... | 4,514 | 40.805556 | 120 | py |
PiMAE | PiMAE-main/Downstream/detr/util/misc.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Misc functions, including distributed helpers.
Mostly copy-paste from torchvision references.
"""
import os
import subprocess
import time
from collections import defaultdict, deque
import datetime
import pickle
from packaging import version
fro... | 15,356 | 31.744136 | 116 | py |
PiMAE | PiMAE-main/Downstream/detr/util/box_ops.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Utilities for bounding box manipulation and GIoU.
"""
import torch
from torchvision.ops.boxes import box_area
def box_cxcywh_to_xyxy(x):
x_c, y_c, w, h = x.unbind(-1)
b = [(x_c - 0.5 * w), (y_c - 0.5 * h),
(x_c + 0.5 * w), (y_... | 2,561 | 27.786517 | 110 | py |
PiMAE | PiMAE-main/Downstream/detr/datasets/__init__.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import torch.utils.data
import torchvision
from .coco import build as build_coco
def get_coco_api_from_dataset(dataset):
for _ in range(10):
# if isinstance(dataset, torchvision.datasets.CocoDetection):
# break
if ... | 979 | 34 | 70 | py |
PiMAE | PiMAE-main/Downstream/detr/datasets/coco_eval.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
COCO evaluator that works in distributed mode.
Mostly copy-paste from https://github.com/pytorch/vision/blob/edfd5a7/references/detection/coco_eval.py
The difference is that there is less copy-pasting from pycocotools
in the end of the file, as... | 8,735 | 32.860465 | 103 | py |
PiMAE | PiMAE-main/Downstream/detr/datasets/coco_panoptic.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import json
from pathlib import Path
import numpy as np
import torch
from PIL import Image
from panopticapi.utils import rgb2id
from util.box_ops import masks_to_boxes
from .coco import make_coco_transforms
class CocoPanoptic:
def __init__(... | 3,723 | 36.24 | 111 | py |
PiMAE | PiMAE-main/Downstream/detr/datasets/coco.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
COCO dataset which returns image_id for evaluation.
Mostly copy-paste from https://github.com/pytorch/vision/blob/13b35ff/references/detection/coco_utils.py
"""
from pathlib import Path
import torch
import torch.utils.data
import torchvision
f... | 5,394 | 31.896341 | 118 | py |
PiMAE | PiMAE-main/Downstream/detr/datasets/transforms.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""
Transforms and data augmentation for both image + bbox.
"""
import random
import PIL
import torch
import torchvision.transforms as T
import torchvision.transforms.functional as F
from util.box_ops import box_xyxy_to_cxcywh
from util.misc impor... | 8,524 | 29.776173 | 104 | py |
STDAN | STDAN-main/codes/test.py | '''
test STDAN models on arbitrary datasets
'''
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
import os.path as osp
import glob
import logging
import numpy as np
import cv2
import torch
import time
import utils.util as util
import data.util as data_util
import models.modules.sttrans as sttrans
def main():
s... | 10,428 | 38.805344 | 149 | py |
STDAN | STDAN-main/codes/test_vimeo.py | '''
test STDAN on Vimeo-Slow, Vimeo-Medium and Vimeo-Fast datasets
'''
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
import os.path as osp
import glob
import logging
import numpy as np
import cv2
import torch
import utils.util as util
import data.util as data_util
import models.modules.sttrans as sttrans
def ma... | 9,823 | 38.612903 | 145 | py |
STDAN | STDAN-main/codes/train.py | import os
import math
import argparse
import random
import logging
import torch
import torch.distributed as dist
import torch.multiprocessing as mp
from data.data_sampler import DistIterSampler
import options.options as option
from utils import util
from data import create_dataloader, create_dataset
from models impor... | 7,992 | 38.766169 | 100 | py |
STDAN | STDAN-main/codes/models/lr_scheduler.py | import math
from collections import Counter
from collections import defaultdict
import torch
from torch.optim.lr_scheduler import _LRScheduler
class MultiStepLR_Restart(_LRScheduler):
def __init__(self, optimizer, milestones, restarts=None, weights=None, gamma=0.1,
clear_state=False, last_epoch=-... | 5,612 | 38.251748 | 100 | py |
STDAN | STDAN-main/codes/models/base_model.py | import os
from collections import OrderedDict
import torch
import torch.nn as nn
from torch.nn.parallel import DistributedDataParallel
class BaseModel():
def __init__(self, opt):
self.opt = opt
self.device = torch.device('cuda' if opt['gpu_ids'] is not None else 'cpu')
self.is_train = opt[... | 4,672 | 37.303279 | 96 | py |
STDAN | STDAN-main/codes/models/VideoSR_base_model.py | import logging
from collections import OrderedDict
import torch
import torch.nn as nn
from torch.nn.parallel import DataParallel, DistributedDataParallel
import models.networks as networks
import models.lr_scheduler as lr_scheduler
from .base_model import BaseModel
from models.modules.loss import CharbonnierLoss, LapL... | 5,736 | 39.118881 | 100 | py |
STDAN | STDAN-main/codes/models/modules/def_enc_dec.py | import torch
import torch.nn as nn
from models.modules.DCNv2_latest.dcn_v2 import DSP_sep2
class STDFA(nn.Module):
def __init__(self, in_chans, embed_dim, patch_size, topk):
super(STDFA, self).__init__()
self.embed_dim = embed_dim
self.patch_size = patch_size
self.topk = topk
... | 8,661 | 33.648 | 95 | py |
STDAN | STDAN-main/codes/models/modules/trans_enc_dec.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from .rstb import (
RSTB,
PatchEmbed,
PatchUnEmbed,
)
from timm.models.layers import trunc_normal_
class Spatial_decoder(nn.Module):
def __init__(
self,
img_size=64,
patch_size=1,
in_chans=3,
em... | 4,179 | 29.735294 | 88 | py |
STDAN | STDAN-main/codes/models/modules/loss.py | import torch
import torch.nn as nn
import numpy as np
import torch.nn.functional as fnn
from torch.autograd import Variable
class CharbonnierLoss(nn.Module):
"""Charbonnier Loss (L1)"""
def __init__(self, eps=1e-6):
super(CharbonnierLoss, self).__init__()
self.eps = eps
def forward(self, ... | 2,817 | 34.225 | 91 | py |
STDAN | STDAN-main/codes/models/modules/sttrans.py | """ network architecture for Space-Time Video Super-Resolution """
import math
import torch
import torch.nn as nn
from .dconv import PCD_Align_modified
from .def_enc_dec import STDFA
from .trans_enc_dec import Spatial_decoder
class STTrans2(nn.Module):
def __init__(
self,
scale=1,
n_inp... | 6,854 | 31.799043 | 85 | py |
STDAN | STDAN-main/codes/models/modules/module_util.py | import torch
import torch.nn as nn
import torch.nn.init as init
import torch.nn.functional as F
def initialize_weights(net_l, scale=1):
if not isinstance(net_l, list):
net_l = [net_l]
for net in net_l:
for m in net.modules():
if isinstance(m, nn.Conv2d):
init.kaimin... | 2,671 | 31.987654 | 88 | py |
STDAN | STDAN-main/codes/models/modules/dconv.py | from typing import List
import torch
import torch.nn as nn
import torch.nn.functional as F
from models.modules.DCNv2_latest.dcn_v2 import (
ModulatedDeformConv,
modulated_deform_conv,
)
from torch.nn.modules.utils import _pair
class ModulatedDeformConvPack(ModulatedDeformConv):
def __init__(self, *a... | 21,716 | 35.996593 | 88 | py |
STDAN | STDAN-main/codes/models/modules/rstb.py | import torch
import torch.nn as nn
import torch.utils.checkpoint as checkpoint
from torch.nn.init import trunc_normal_
from typing import Tuple
#####
# RSTB
#####
class RSTB(nn.Module):
"""Residual Swin Transformer Block (RSTB).
https://github.com/JingyunLiang/SwinIR/blob/main/models/network_swinir.py
Ar... | 22,384 | 33.491525 | 112 | py |
STDAN | STDAN-main/codes/models/modules/DCNv2_latest/setup.py | #!/usr/bin/env python
import glob
import os
import torch
from setuptools import find_packages, setup
from torch.utils.cpp_extension import CUDA_HOME, CppExtension, CUDAExtension
requirements = ["torch", "torchvision"]
def get_extensions():
this_dir = os.path.dirname(os.path.abspath(__file__))
extensions_di... | 1,929 | 28.242424 | 76 | py |
STDAN | STDAN-main/codes/models/modules/DCNv2_latest/dcn_v2.py | #!/usr/bin/env python
from __future__ import absolute_import, division, print_function
import math
import logging
import torch
from torch import nn
from torch.autograd import Function
from torch.autograd.function import once_differentiable
from torch.nn.modules.utils import _pair
import _ext as _backend
logger = logg... | 13,251 | 29.255708 | 100 | py |
STDAN | STDAN-main/codes/utils/util.py | # this code is modified from https://github.com/xinntao/EDVR/blob/master/codes/utils/util.py
import os
import sys
import time
import math
import torch.nn.functional as F
from datetime import datetime
import random
import logging
from collections import OrderedDict
import numpy as np
import cv2
import torch
from torchvi... | 12,096 | 32.980337 | 130 | py |
STDAN | STDAN-main/codes/data/data_sampler.py | """
Modified from torch.utils.data.distributed.DistributedSampler
Support enlarging the dataset for *iter-oriented* training, for saving time when restart the
dataloader after each epoch
"""
import math
import torch
from torch.utils.data.sampler import Sampler
import torch.distributed as dist
class DistIterSampler(Sa... | 2,297 | 33.818182 | 92 | py |
STDAN | STDAN-main/codes/data/util.py | import os
import pickle
import random
import numpy as np
import cv2
import torch
import math
####################
# Files & IO
####################
###################### get image path list ######################
IMG_EXTENSIONS = ['.jpg', '.JPG', '.jpeg', '.JPEG', '.png', '.PNG', '.ppm', '.PPM', '.bmp', '.BMP']
de... | 11,925 | 34.284024 | 99 | py |
STDAN | STDAN-main/codes/data/Vimeo7_dataset.py | '''
Vimeo7 dataset
support reading images from lmdb, image folder and memcached
'''
from PIL import Image
import os.path as osp
import random
import pickle
import logging
import numpy as np
import cv2
import lmdb
import torch
import torch.utils.data as data
import data.util as util
import time
try:
import mc # ... | 11,519 | 41.043796 | 147 | py |
STDAN | STDAN-main/codes/data/__init__.py | '''create dataset and dataloader'''
import logging
import torch
import torch.utils.data
def create_dataloader(dataset, dataset_opt, opt, sampler):
phase = dataset_opt['phase']
if phase == 'train':
if opt['dist']:
world_size = torch.distributed.get_world_size()
num_workers = dat... | 1,589 | 38.75 | 100 | py |
location-mode-prediction | location-mode-prediction-main/main.py | import torch, os
import argparse
import numpy as np
import pandas as pd
import json
from datetime import datetime
from easydict import EasyDict as edict
from utils.utils import (
load_config,
setup_seed,
get_trainedNets,
get_test_result,
get_dataloaders,
get_models,
)
setup_seed(42)
def sin... | 2,241 | 25.690476 | 112 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.