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 |
|---|---|---|---|---|---|---|
EasyMocap | EasyMocap-master/easymocap/estimator/HRNet/modules.py | import torch
from torch import nn
class Bottleneck(nn.Module):
expansion = 4
def __init__(self, inplanes, planes, stride=1, downsample=None, bn_momentum=0.1):
super(Bottleneck, self).__init__()
self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False)
self.bn1 = nn.BatchNorm... | 2,199 | 29.136986 | 101 | py |
EasyMocap | EasyMocap-master/easymocap/estimator/HRNet/hrnet_api.py | '''
@ Date: 2020-06-04 12:47:04
@ LastEditors: Qing Shuai
@ LastEditTime: 2022-04-19 17:02:57
@ Author: Qing Shuai
@ Mail: s_q@zju.edu.cn
'''
from os.path import join
import cv2
import numpy as np
import torch
from torchvision.transforms import transforms
from .hrnet import HRNet
COCO17_IN_BODY25 = [0... | 21,657 | 40.096774 | 216 | py |
EasyMocap | EasyMocap-master/easymocap/estimator/YOLOv4/yolo.py | '''
@ Date: 2020-12-10 16:39:51
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
@ LastEditTime: 2022-04-21 23:53:40
@ FilePath: /EasyMocapPublic/easymocap/estimator/YOLOv4/yolo.py
'''
from .darknet2pytorch import Darknet
import cv2
import torch
from os.path import join
import os
import numpy as np
def load_cl... | 5,305 | 31.956522 | 134 | py |
EasyMocap | EasyMocap-master/easymocap/estimator/YOLOv4/darknet2pytorch.py | import torch.nn as nn
import torch.nn.functional as F
import numpy as np
from .region_loss import RegionLoss
from .yolo_layer import YoloLayer
from .config import *
from .torch_utils import *
class Mish(torch.nn.Module):
def __init__(self):
super().__init__()
def forward(self, x):
x = x * (to... | 20,626 | 38.974806 | 119 | py |
EasyMocap | EasyMocap-master/easymocap/estimator/YOLOv4/config.py | import torch
from .torch_utils import convert2cpu
def parse_cfg(cfgfile):
blocks = []
fp = open(cfgfile, 'r')
block = None
line = fp.readline()
while line != '':
line = line.rstrip()
if line == '' or line[0] == '#':
line = fp.readline()
continue
elif ... | 10,768 | 40.74031 | 118 | py |
EasyMocap | EasyMocap-master/easymocap/estimator/YOLOv4/torch_utils.py | import sys
import os
import time
import math
import torch
import numpy as np
from torch.autograd import Variable
def bbox_ious(boxes1, boxes2, x1y1x2y2=True):
if x1y1x2y2:
mx = torch.min(boxes1[0], boxes2[0])
Mx = torch.max(boxes1[2], boxes2[2])
my = torch.min(boxes1[1], boxes2[1])
... | 2,728 | 26.565657 | 86 | py |
EasyMocap | EasyMocap-master/easymocap/estimator/YOLOv4/region_loss.py | import torch.nn as nn
import torch.nn.functional as F
from .torch_utils import *
def build_targets(pred_boxes, target, anchors, num_anchors, num_classes, nH, nW, noobject_scale, object_scale,
sil_thresh, seen):
nB = target.size(0)
nA = num_anchors
nC = num_classes
anchor_step = len(a... | 9,652 | 48.25 | 120 | py |
EasyMocap | EasyMocap-master/easymocap/estimator/YOLOv4/yolo_layer.py | import torch.nn as nn
import torch.nn.functional as F
from .torch_utils import *
def yolo_forward(output, conf_thresh, num_classes, anchors, num_anchors, scale_x_y, only_objectness=1,
validation=False):
# Output would be invalid if it does not satisfy this assert
# assert (output.... | 12,311 | 37.117647 | 161 | py |
EasyMocap | EasyMocap-master/easymocap/smplmodel/body_model.py | '''
@ Date: 2020-11-18 14:04:10
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
@ LastEditTime: 2021-08-28 16:37:55
@ FilePath: /EasyMocap/easymocap/smplmodel/body_model.py
'''
import torch
import torch.nn as nn
from .lbs import batch_rodrigues
from .lbs import lbs, dqs
import os.path as osp
import pickle
impo... | 18,238 | 42.220379 | 141 | py |
EasyMocap | EasyMocap-master/easymocap/smplmodel/body_param.py | '''
@ Date: 2020-11-20 13:34:54
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
@ LastEditTime: 2021-05-25 19:21:12
@ FilePath: /EasyMocap/easymocap/smplmodel/body_param.py
'''
import numpy as np
from os.path import join
def merge_params(param_list, share_shape=True):
output = {}
for key in ['poses', ... | 3,451 | 40.590361 | 143 | py |
EasyMocap | EasyMocap-master/easymocap/smplmodel/lbs.py | # -*- coding: utf-8 -*-
# Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (MPG) is
# holder of all proprietary rights on this computer program.
# You can only use this computer program if you have closed
# a license agreement with MPG or you get the right to use the computer
# program from someone who is... | 18,117 | 35.750507 | 125 | py |
EasyMocap | EasyMocap-master/easymocap/neuralbody/trainer/recorder.py | '''
@ Date: 2021-09-05 20:11:27
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
@ LastEditTime: 2021-09-05 20:11:27
@ FilePath: /EasyMocap/easymocap/neuralbody/trainer/recorder.py
'''
from collections import deque, defaultdict
import torch
from tensorboardX import SummaryWriter
import os
from termcolor import... | 4,285 | 31.225564 | 113 | py |
EasyMocap | EasyMocap-master/easymocap/neuralbody/trainer/dataloader.py | '''
@ Date: 2021-07-20 12:32:29
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
@ LastEditTime: 2021-09-05 20:19:11
@ FilePath: /EasyMocap/easymocap/neuralbody/trainer/dataloader.py
'''
from easymocap.config.baseconfig import load_object
import torch
def make_data_sampler(cfg, dataset, shuffle, is_distributed... | 3,742 | 36.808081 | 80 | py |
EasyMocap | EasyMocap-master/easymocap/neuralbody/trainer/lr_sheduler.py | '''
@ Date: 2021-09-05 20:07:55
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
@ LastEditTime: 2021-09-05 20:10:02
@ FilePath: /EasyMocap/easymocap/neuralbody/trainer/lr_sheduler.py
'''
import torch
from collections import Counter
from bisect import bisect_right
class WarmupMultiStepLR(torch.optim.lr_schedul... | 3,636 | 35.37 | 80 | py |
EasyMocap | EasyMocap-master/easymocap/neuralbody/trainer/samplers.py | # copy from neuralbody
from torch.utils.data.sampler import Sampler
from torch.utils.data.sampler import BatchSampler
import numpy as np
import torch
import math
import torch.distributed as dist
class ImageSizeBatchSampler(Sampler):
def __init__(self, sampler, batch_size, drop_last, sampler_meta):
self.sa... | 4,918 | 32.462585 | 86 | py |
EasyMocap | EasyMocap-master/easymocap/neuralbody/trainer/optimizer.py | '''
@ Date: 2021-09-05 20:05:42
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
@ LastEditTime: 2021-09-05 20:05:42
@ FilePath: /EasyMocap/easymocap/neuralbody/trainer/optimizer.py
'''
import torch
_optimizer_factory = {
'adam': torch.optim.Adam,
'sgd': torch.optim.SGD
}
def Optimizer(net, cfg):
... | 794 | 24.645161 | 88 | py |
EasyMocap | EasyMocap-master/easymocap/neuralbody/trainer/net_loader.py | '''
@ Date: 2021-09-05 20:12:41
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
@ LastEditTime: 2021-09-05 20:12:42
@ FilePath: /EasyMocap/easymocap/neuralbody/trainer/net_load.py
'''
import os
from termcolor import colored
import torch
def load_model(net,
optim,
scheduler,
... | 3,300 | 30.141509 | 78 | py |
EasyMocap | EasyMocap-master/easymocap/neuralbody/dataset/mirror.py | '''
@ Date: 2022-07-15 19:25:33
@ Author: Qing Shuai
@ Mail: s_q@zju.edu.cn
@ LastEditors: Qing Shuai
@ LastEditTime: 2022-07-15 21:00:40
@ FilePath: /EasyMocapPublic/easymocap/neuralbody/dataset/mirror.py
'''
from os.path import join
import numpy as np
import cv2
from tqdm import trange
import copy
from .m... | 9,346 | 39.995614 | 115 | py |
EasyMocap | EasyMocap-master/easymocap/neuralbody/renderer/render_base.py | import numpy as np
import cv2
import torch.nn as nn
import torch
import time
import json
from ..model.base import augment_z_vals, concat
_time_ = 0
def tic():
global _time_
_time_ = time.time()
def toc(name):
global _time_
print('{:15s}: {:.1f}'.format(name, 1000*(time.time() - _time_)))
_time_ = ... | 18,632 | 43.154028 | 138 | py |
EasyMocap | EasyMocap-master/easymocap/neuralbody/renderer/lpips.py | import numpy as np
import cv2
import torch
import torchvision
class VGGPerceptualLoss(torch.nn.Module):
def __init__(self, resize=False):
super(VGGPerceptualLoss, self).__init__()
blocks = []
blocks.append(torchvision.models.vgg16(pretrained=True).features[:4].eval())
blocks.append(... | 3,021 | 42.171429 | 98 | py |
EasyMocap | EasyMocap-master/easymocap/neuralbody/renderer/render_wrapper.py | '''
@ Date: 2021-09-05 20:24:16
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
@ LastEditTime: 2021-09-05 21:25:08
@ FilePath: /EasyMocap/easymocap/neuralbody/renderer/render_wrapper.py
'''
import torch
import torch.nn as nn
from ...config import load_object
class RenderWrapper(nn.Module):
def __init__(s... | 1,897 | 38.541667 | 91 | py |
EasyMocap | EasyMocap-master/easymocap/neuralbody/renderer/render_loss.py | '''
@ Date: 2021-09-05 20:24:24
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
@ LastEditTime: 2021-09-05 21:34:16
@ FilePath: /EasyMocap/easymocap/neuralbody/renderer/render_loss.py
'''
import torch
import torch.nn as nn
import torch.nn.functional as F
from ...config import load_object
class LossRGB(nn.Modu... | 12,302 | 32.892562 | 113 | py |
EasyMocap | EasyMocap-master/easymocap/neuralbody/model/base.py | '''
@ Date: 2021-09-03 16:56:14
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
@ LastEditTime: 2021-09-05 21:17:25
@ FilePath: /EasyMocap/easymocap/neuralbody/model/base.py
'''
import torch
import torch.nn as nn
from torch import searchsorted
def augment_z_vals(z_vals, perturb=1):
# get intervals between... | 7,749 | 36.439614 | 113 | py |
EasyMocap | EasyMocap-master/easymocap/neuralbody/model/nerfplus.py | import torch
import torch.nn as nn
from .nerf import Nerf, EmbedMLP, MultiLinear
from os.path import join
from ...mytools.file_utils import read_json
import numpy as np
def create_dynamic_embedding(mode, embed):
if mode == 'dense':
embedding = nn.Embedding(embed.shape[0], embed.shape[1])
elif mode == '... | 7,178 | 36.984127 | 90 | py |
EasyMocap | EasyMocap-master/easymocap/neuralbody/model/nerf.py | '''
@ Date: 2021-09-03 17:12:29
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
@ LastEditTime: 2021-09-05 19:58:54
@ FilePath: /EasyMocap/easymocap/neuralbody/model/nerf.py
'''
from .base import Base
from .embedder import get_embedder
import torch.nn.functional as F
import torch
import torch.nn as nn
class N... | 10,194 | 36.208029 | 143 | py |
EasyMocap | EasyMocap-master/easymocap/neuralbody/model/neuralbody.py | '''
@ Date: 2021-09-03 16:52:42
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
@ LastEditTime: 2021-09-03 22:41:50
@ FilePath: /EasyMocap/easymocap/neuralbody/model/neuralbody.py
'''
from .nerf import Nerf, EmbedMLP
import torch
import spconv
try:
if spconv.__version__.split('.')[0] == '2':
import... | 15,295 | 37.24 | 133 | py |
EasyMocap | EasyMocap-master/easymocap/neuralbody/model/embedder.py | import torch
class Embedder:
def __init__(self, **kwargs):
self.kwargs = kwargs
self.create_embedding_fn()
def create_embedding_fn(self):
embed_fns = []
d = self.kwargs['input_dims']
out_dim = 0
if self.kwargs['include_input']:
embed_fns.append(lambd... | 1,448 | 29.829787 | 76 | py |
EasyMocap | EasyMocap-master/easymocap/neuralbody/model/compose.py | from ...config.baseconfig import load_object
import torch
import torch.nn as nn
from copy import deepcopy
class ComposedModel(nn.Module):
def __init__(self, models) -> None:
super().__init__()
models = deepcopy(models)
for key in ['human', 'ball']:
if 'all' + key in models.keys(... | 4,211 | 39.5 | 139 | py |
EasyMocap | EasyMocap-master/easymocap/datasets/base.py | # This file provides the base class for dataset
from os.path import join
import os
from glob import glob
import numpy as np
from easymocap.dataset.config import coco17tobody25
from ..mytools.vis_base import merge, plot_keypoints_auto, plot_keypoints_total
from ..mytools.camera_utils import Undistort, unproj, read_cam... | 52,014 | 42.931588 | 171 | py |
EasyMocap | EasyMocap-master/easymocap/bodymodel/base.py | '''
@ Date: 2022-03-17 19:23:59
@ Author: Qing Shuai
@ Mail: s_q@zju.edu.cn
@ LastEditors: Qing Shuai
@ LastEditTime: 2022-07-15 12:15:46
@ FilePath: /EasyMocapPublic/easymocap/bodymodel/base.py
'''
import numpy as np
import torch
from ..mytools.file_utils import myarray2string
class Model(torch.nn.Module... | 4,168 | 29.881481 | 75 | py |
EasyMocap | EasyMocap-master/easymocap/bodymodel/smplx.py | import torch
import torch.nn as nn
from .base import Model
from .smpl import SMPLModel, SMPLLayerEmbedding, read_pickle, to_tensor
from os.path import join
import numpy as np
def read_hand(path, use_pca, use_flat_mean, num_pca_comps):
data = read_pickle(path)
mean = data['hands_mean'].reshape(1, -1).astype(np.... | 11,377 | 42.761538 | 137 | py |
EasyMocap | EasyMocap-master/easymocap/bodymodel/lbs.py | # -*- coding: utf-8 -*-
# Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (MPG) is
# holder of all proprietary rights on this computer program.
# You can only use this computer program if you have closed
# a license agreement with MPG or you get the right to use the computer
# program from someone who is... | 18,467 | 35.862275 | 125 | py |
EasyMocap | EasyMocap-master/easymocap/bodymodel/smpl.py | from .base import Model, Params
from .lbs import lbs, batch_rodrigues
import os
import numpy as np
import torch
def to_tensor(array, dtype=torch.float32, device=torch.device('cpu')):
if 'torch.tensor' not in str(type(array)):
return torch.tensor(array, dtype=dtype).to(device)
else:
return array... | 19,113 | 42.539863 | 141 | py |
EasyMocap | EasyMocap-master/easymocap/multistage/base.py | # 这个脚本用于通用的多阶段的优化
import numpy as np
import torch
from ..annotator.file_utils import read_json
from ..mytools import Timer
from .lossbase import print_table
from ..config.baseconfig import load_object
from ..bodymodel.base import Params
from torch.utils.data import DataLoader
from tqdm import tqdm
def dict_of_numpy_t... | 13,766 | 43.125 | 146 | py |
EasyMocap | EasyMocap-master/easymocap/multistage/torchgeometry.py | """
useful functions to perform conversion between rotation in different format(quaternion, rotation_matrix, euler_angle, axis_angle)
quaternion representation: (w,x,y,z)
code reference: torchgeometry, kornia, https://github.com/MandyMo/pytorch_HMR.
"""
import torch
from torch.nn import functional as F
import numpy as... | 18,068 | 33.94971 | 129 | py |
EasyMocap | EasyMocap-master/easymocap/multistage/initialize.py | import numpy as np
import cv2
from ..dataset.config import CONFIG
from ..config import load_object
from ..mytools.debug_utils import log, mywarn, myerror
import torch
from tqdm import tqdm, trange
def svd_rot(src, tgt, reflection=False, debug=False):
# optimum rotation matrix of Y
A = np.matmul(src.transpose(0... | 6,382 | 35.474286 | 116 | py |
EasyMocap | EasyMocap-master/easymocap/multistage/init_pose.py | '''
@ Date: 2022-04-02 13:59:50
@ Author: Qing Shuai
@ Mail: s_q@zju.edu.cn
@ LastEditors: Qing Shuai
@ LastEditTime: 2022-07-13 16:34:21
@ FilePath: /EasyMocapPublic/easymocap/multistage/init_pose.py
'''
import os
import numpy as np
import cv2
from tqdm import tqdm
from os.path import join
import torch
fro... | 1,176 | 31.694444 | 70 | py |
EasyMocap | EasyMocap-master/easymocap/multistage/base_ops.py | '''
@ Date: 2022-08-12 20:34:15
@ Author: Qing Shuai
@ Mail: s_q@zju.edu.cn
@ LastEditors: Qing Shuai
@ LastEditTime: 2022-08-18 14:47:23
@ FilePath: /EasyMocapPublic/easymocap/multistage/base_ops.py
'''
import torch
class BeforeAfterBase:
def __init__(self, model) -> None:
pass
def start(... | 1,128 | 27.948718 | 70 | py |
EasyMocap | EasyMocap-master/easymocap/multistage/gmm.py | import pickle
import os
from os.path import join
import numpy as np
import torch
from .lossbase import LossBase
def create_prior_from_cmu(n_gaussians, epsilon=1e-15):
"""Load the gmm from the CMU motion database."""
from os.path import dirname
np_dtype = np.float32
with open(join(dirname(__file__), 'gm... | 5,843 | 36.703226 | 91 | py |
EasyMocap | EasyMocap-master/easymocap/multistage/init_cnn.py | '''
@ Date: 2022-04-26 17:54:28
@ Author: Qing Shuai
@ Mail: s_q@zju.edu.cn
@ LastEditors: Qing Shuai
@ LastEditTime: 2022-08-30 19:47:04
@ FilePath: /EasyMocapPublic/easymocap/multistage/init_cnn.py
'''
import os
import numpy as np
import cv2
from tqdm import tqdm
from os.path import join
import torch
from... | 4,336 | 41.106796 | 132 | py |
EasyMocap | EasyMocap-master/easymocap/multistage/before_after.py | import torch
class Remove:
def __init__(self, key, index=[], ranges=[]) -> None:
self.key = key
self.ranges = ranges
self.index = index
def before(self, body_params):
val = body_params[self.key]
if self.ranges[0] == 0:
val_zeros = torch.zeros_like(val[:, :se... | 1,807 | 30.719298 | 99 | py |
EasyMocap | EasyMocap-master/easymocap/multistage/totalfitting.py | '''
@ Date: 2022-07-28 14:39:23
@ Author: Qing Shuai
@ Mail: s_q@zju.edu.cn
@ LastEditors: Qing Shuai
@ LastEditTime: 2022-08-12 21:42:12
@ FilePath: /EasyMocapPublic/easymocap/multistage/totalfitting.py
'''
import torch
from ..bodymodel.lbs import batch_rodrigues
from .torchgeometry import rotation_matrix... | 3,764 | 37.814433 | 144 | py |
EasyMocap | EasyMocap-master/easymocap/multistage/lossbase.py | import numpy as np
import torch.nn as nn
import torch
from ..bodymodel.lbs import batch_rodrigues
class LossBase(nn.Module):
def __init__(self):
super().__init__()
def __str__(self) -> str:
return '# lack of comment'
def check_at_start(self, **kwargs):
pass
def ch... | 23,006 | 36.470684 | 135 | py |
EasyMocap | EasyMocap-master/easymocap/multistage/fitting.py | '''
@ Date: 2022-03-22 16:11:44
@ Author: Qing Shuai
@ Mail: s_q@zju.edu.cn
@ LastEditors: Qing Shuai
@ LastEditTime: 2022-07-25 11:51:50
@ FilePath: /EasyMocapPublic/easymocap/multistage/fitting.py
'''
# This function provides a realtime fitting interface
from collections import namedtuple
from time import... | 77,813 | 42.913093 | 189 | py |
EasyMocap | EasyMocap-master/easymocap/multistage/synchronization.py | '''
@ Date: 2022-03-11 12:13:01
@ Author: Qing Shuai
@ Mail: s_q@zju.edu.cn
@ LastEditors: Qing Shuai
@ LastEditTime: 2022-08-11 21:52:00
@ FilePath: /EasyMocapPublic/easymocap/multistage/synchronization.py
'''
import numpy as np
import torch
class AddTime:
def __init__(self, gt) -> None:
self.... | 2,727 | 33.531646 | 102 | py |
EasyMocap | EasyMocap-master/easymocap/multistage/mirror.py | '''
@ Date: 2022-07-12 11:55:47
@ Author: Qing Shuai
@ Mail: s_q@zju.edu.cn
@ LastEditors: Qing Shuai
@ LastEditTime: 2022-07-14 17:57:48
@ FilePath: /EasyMocapPublic/easymocap/multistage/mirror.py
'''
import numpy as np
import torch
from ..dataset.mirror import flipPoint2D, flipSMPLPoses, flipSMPLParams
fr... | 10,635 | 39.750958 | 123 | py |
EasyMocap | EasyMocap-master/easymocap/pyfitting/lossfactory.py | '''
@ Date: 2020-11-19 17:46:04
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
@ LastEditTime: 2021-04-14 11:46:56
@ FilePath: /EasyMocap/easymocap/pyfitting/lossfactory.py
'''
import numpy as np
import torch
from .operation import projection, batch_rodrigues
funcl2 = lambda x: torch.sum(x**2)
funcl1 = lambd... | 16,808 | 39.116945 | 132 | py |
EasyMocap | EasyMocap-master/easymocap/pyfitting/lbfgs.py | import torch
from functools import reduce
from torch.optim.optimizer import Optimizer
def _cubic_interpolate(x1, f1, g1, x2, f2, g2, bounds=None):
# ported from https://github.com/torch/optim/blob/master/polyinterp.lua
# Compute bounds of interpolation area
if bounds is not None:
xmin_bound, xmax_... | 16,776 | 34.544492 | 91 | py |
EasyMocap | EasyMocap-master/easymocap/pyfitting/optimize.py | '''
@ Date: 2020-06-26 12:06:25
@ LastEditors: Qing Shuai
@ LastEditTime: 2020-06-26 12:08:37
@ Author: Qing Shuai
@ Mail: s_q@zju.edu.cn
'''
import numpy as np
import os
from tqdm import tqdm
import torch
import json
def rel_change(prev_val, curr_val):
return (prev_val - curr_val) / max([np.ab... | 4,716 | 35.007634 | 101 | py |
EasyMocap | EasyMocap-master/easymocap/pyfitting/optimize_mirror.py | '''
@ Date: 2021-03-05 15:21:33
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
@ LastEditTime: 2021-03-31 23:02:58
@ FilePath: /EasyMocap/easymocap/pyfitting/optimize_mirror.py
'''
from .optimize_simple import _optimizeSMPL, deepcopy_tensor, get_prepare_smplx, dict_of_tensor_to_numpy
from .lossfactory import ... | 13,632 | 42.006309 | 138 | py |
EasyMocap | EasyMocap-master/easymocap/pyfitting/optimize_simple.py | '''
@ Date: 2020-11-19 10:49:26
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
@ LastEditTime: 2021-05-25 19:51:12
@ FilePath: /EasyMocap/easymocap/pyfitting/optimize_simple.py
'''
import numpy as np
import torch
from .lbfgs import LBFGS
from .optimize import FittingMonitor, grad_require, FittingLog
from .lo... | 14,845 | 40.937853 | 126 | py |
EasyMocap | EasyMocap-master/easymocap/pyfitting/operation.py | '''
@ Date: 2020-11-19 11:39:45
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
@ LastEditTime: 2021-01-20 15:06:28
@ FilePath: /EasyMocap/code/pyfitting/operation.py
'''
import torch
def batch_rodrigues(rot_vecs, epsilon=1e-8, dtype=torch.float32):
''' Calculates the rotation matrices for a batch of rota... | 2,455 | 32.189189 | 78 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/basetopdown.py | import os
from os.path import join
import numpy as np
import cv2
import torch
import torch.nn as nn
import pickle
import math
def rotate_2d(pt_2d, rot_rad):
x = pt_2d[0]
y = pt_2d[1]
sn, cs = np.sin(rot_rad), np.cos(rot_rad)
xx = x * cs - y * sn
yy = x * sn + y * cs
return np.array([xx, yy], dt... | 11,155 | 35.10356 | 127 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/hrnet/hrnet.py | import torch
from torch import nn
from .modules import BasicBlock, Bottleneck
class StageModule(nn.Module):
def __init__(self, stage, output_branches, c, bn_momentum):
super(StageModule, self).__init__()
self.stage = stage
self.output_branches = output_branches
self.branches = nn.... | 9,841 | 43.940639 | 117 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/hrnet/modules.py | import torch
from torch import nn
class Bottleneck(nn.Module):
expansion = 4
def __init__(self, inplanes, planes, stride=1, downsample=None, bn_momentum=0.1):
super(Bottleneck, self).__init__()
self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False)
self.bn1 = nn.BatchNorm... | 2,199 | 29.136986 | 101 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/hrnet/myhrnet.py | import os
import numpy as np
import math
import cv2
import torch
from ..basetopdown import BaseTopDownModelCache
from .hrnet import HRNet
def get_max_preds(batch_heatmaps):
'''
get predictions from score maps
heatmaps: numpy.ndarray([batch_size, num_joints, height, width])
'''
assert isinstance(bat... | 5,541 | 39.75 | 216 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/vitpose/layers.py | import torch
import math
import collections.abc
from itertools import repeat
import warnings
import torch.nn as nn
def drop_path(x, drop_prob: float = 0., training: bool = False, scale_by_keep: bool = True):
"""Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
This is th... | 3,859 | 38.387755 | 108 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/vitpose/vit_moe.py | # Copyright (c) OpenMMLab. All rights reserved.
import os
import numpy as np
import torch
from functools import partial
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.checkpoint as checkpoint
from .layers import drop_path, to_2tuple, trunc_normal_
def drop_path(x, drop_prob: float = 0., trai... | 22,987 | 36.809211 | 158 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/hmr/models.py | '''
Date: 2021-10-25 11:51:29 am
Author: dihuangdh
Descriptions:
-----
LastEditTime: 2021-10-25 11:51:58 am
LastEditors: dihuangdh
'''
import torch
import torch.nn as nn
import torchvision.models.resnet as resnet
import numpy as np
import math
class Bottleneck(nn.Module):
""" Redefinition of Bottleneck residual... | 5,885 | 32.827586 | 83 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/hmr/hmr_api.py | '''
Date: 2021-10-25 11:51:37 am
Author: dihuangdh
Descriptions:
-----
LastEditTime: 2021-10-25 1:50:40 pm
LastEditors: dihuangdh
'''
import torch
from torchvision.transforms import Normalize
import numpy as np
import cv2
from .models import hmr
class constants:
FOCAL_LENGTH = 5000.
IMG_RES = 224
# Me... | 9,421 | 35.804688 | 126 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/hmr/hmr.py | import os
import numpy as np
import torch
from ..basetopdown import BaseTopDownModelCache, gdown_models
import pickle
from .models import hmr
class MyHMR(BaseTopDownModelCache):
def __init__(self, ckpt, url=None):
super().__init__('handhmr', bbox_scale=1., res_input=224)
self.model = hmr()
... | 1,244 | 34.571429 | 96 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/pare/pare.py | import os
import torch
import torch.nn as nn
from .config import update_hparams
# from .head import PareHead, SMPLHead, SMPLCamHead
from .head import PareHead
from .backbone.utils import get_backbone_info
from .backbone.hrnet import hrnet_w32
from os.path import join
from easymocap.multistage.torchgeometry import rotat... | 11,235 | 41.722433 | 118 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/pare/backbone/hrnet.py | # ------------------------------------------------------------------------------
# Copyright (c) Microsoft
# Licensed under the MIT License.
# Written by Bin Xiao (Bin.Xiao@microsoft.com)
# ------------------------------------------------------------------------------
import os
import torch
import torch.nn as nn
# fro... | 23,761 | 36.657686 | 117 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/pare/backbone/resnet.py | import torch
import torch.nn as nn
try:
from torch.hub import load_state_dict_from_url
except ImportError:
from torchvision.models.utils import load_state_dict_from_url
__all__ = ['ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101',
'resnet152', 'resnext50_32x4d', 'resnext101_32x8d',
... | 14,250 | 39.030899 | 107 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/pare/backbone/mobilenet.py | from torch import nn
try:
from torch.hub import load_state_dict_from_url
except ImportError:
from torchvision.models.utils import load_state_dict_from_url
__all__ = ['MobileNetV2', 'mobilenet_v2']
model_urls = {
'mobilenet_v2': 'https://download.pytorch.org/models/mobilenet_v2-b0353104.pth',
}
def _ma... | 7,081 | 35.885417 | 116 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/pare/head/pare_head.py | # -*- coding: utf-8 -*-
# Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (MPG) is
# holder of all proprietary rights on this computer program.
# You can only use this computer program if you have closed
# a license agreement with MPG or you get the right to use the computer
# program from someone who is... | 39,550 | 41.711663 | 125 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/pare/head/smpl_head.py | # -*- coding: utf-8 -*-
# Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (MPG) is
# holder of all proprietary rights on this computer program.
# You can only use this computer program if you have closed
# a license agreement with MPG or you get the right to use the computer
# program from someone who is... | 4,165 | 38.67619 | 103 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/pare/head/smpl_cam_head.py | # -*- coding: utf-8 -*-
# Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (MPG) is
# holder of all proprietary rights on this computer program.
# You can only use this computer program if you have closed
# a license agreement with MPG or you get the right to use the computer
# program from someone who is... | 4,487 | 32.744361 | 81 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/pare/head/hmr_head.py | # -*- coding: utf-8 -*-
# Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (MPG) is
# holder of all proprietary rights on this computer program.
# You can only use this computer program if you have closed
# a license agreement with MPG or you get the right to use the computer
# program from someone who is... | 7,647 | 36.674877 | 93 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/pare/layers/softargmax.py | # -*- coding: utf-8 -*-
# Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (MPG) is
# holder of all proprietary rights on this computer program.
# You can only use this computer program if you have closed
# a license agreement with MPG or you get the right to use the computer
# program from someone who is... | 5,775 | 36.506494 | 128 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/pare/layers/nonlocalattention.py | # -*- coding: utf-8 -*-
# Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (MPG) is
# holder of all proprietary rights on this computer program.
# You can only use this computer program if you have closed
# a license agreement with MPG or you get the right to use the computer
# program from someone who is... | 1,699 | 28.824561 | 77 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/pare/layers/coattention.py | # -*- coding: utf-8 -*-
# Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (MPG) is
# holder of all proprietary rights on this computer program.
# You can only use this computer program if you have closed
# a license agreement with MPG or you get the right to use the computer
# program from someone who is... | 4,782 | 36.661417 | 96 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/pare/layers/keypoint_attention.py | # -*- coding: utf-8 -*-
# Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (MPG) is
# holder of all proprietary rights on this computer program.
# You can only use this computer program if you have closed
# a license agreement with MPG or you get the right to use the computer
# program from someone who is... | 2,347 | 40.928571 | 118 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/pare/layers/locallyconnected2d.py | # -*- coding: utf-8 -*-
# Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (MPG) is
# holder of all proprietary rights on this computer program.
# You can only use this computer program if you have closed
# a license agreement with MPG or you get the right to use the computer
# program from someone who is... | 1,892 | 37.632653 | 104 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/pare/layers/interpolate.py | # -*- coding: utf-8 -*-
# Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (MPG) is
# holder of all proprietary rights on this computer program.
# You can only use this computer program if you have closed
# a license agreement with MPG or you get the right to use the computer
# program from someone who is... | 1,493 | 41.685714 | 118 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/pare/layers/non_local/dot_product.py | import torch
from torch import nn
from torch.nn import functional as F
class _NonLocalBlockND(nn.Module):
def __init__(self, in_channels, inter_channels=None, dimension=3, sub_sample=True, bn_layer=True):
super(_NonLocalBlockND, self).__init__()
assert dimension in [1, 2, 3]
self.dimensi... | 5,525 | 35.117647 | 102 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/pare/utils/geometry.py | import torch
import numpy as np
from torch.nn import functional as F
"""
Useful geometric operations, e.g. Perspective projection and a differentiable Rodrigues formula
Parts of the code are taken from https://github.com/MandyMo/pytorch_HMR
"""
def batch_rot2aa(Rs):
"""
Rs is B x 3 x 3
void cMathUtil::Ro... | 23,924 | 32.137119 | 126 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/hand2d/resnet.py | # Copyright (c) Facebook, Inc. and its 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.
#
import os
import os.path as osp
import torch
import torch.nn as nn
from torchvision.models.resnet import BasicBlock, Bott... | 5,884 | 35.552795 | 99 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/hand2d/hand2d.py | import os
import cv2
import torch
import torch.nn as nn
import numpy as np
import math
# https://download.openmmlab.com/mmpose/hand/hrnetv2/hrnetv2_w18_rhd2d_256x256-95b20dd8_20210330.pth
# https://download.openmmlab.com/mmpose/hand/dark/hrnetv2_w18_onehand10k_256x256_dark-a2f80c64_20210330.pth
from ..basetopdown impor... | 3,797 | 41.674157 | 118 | py |
EasyMocap | EasyMocap-master/myeasymocap/backbone/yolo/yolo.py | import torch
import numpy as np
import os
import cv2
from os.path import join
import pickle
def check_modelpath(paths):
if isinstance(paths, str):
assert os.path.exists(paths), paths
return paths
elif isinstance(paths, list):
for path in paths:
if os.path.exists(path):
... | 11,829 | 35.288344 | 112 | py |
EasyMocap | EasyMocap-master/myeasymocap/io/model.py | import os
import torch
import numpy as np
from easymocap.bodymodel.smpl import SMPLModel
from easymocap.mytools.debug_utils import log
def try_to_download_SMPL(model_dir):
cmd = 'wget https://www.dropbox.com/s/aeulffqzb3zmh8x/pare-github-data.zip'
os.system(cmd)
os.makedirs(model_dir, exist_ok=True)
c... | 5,419 | 42.015873 | 143 | py |
EasyMocap | EasyMocap-master/myeasymocap/operations/loss.py | import torch
import torch.nn as nn
import numpy as np
class GMoF(nn.Module):
def __init__(self, rho=1):
super(GMoF, self).__init__()
self.rho2 = rho * rho
def extra_repr(self):
return 'rho = {}'.format(self.rho)
def forward(self, est, gt=None, conf=None):
if gt is not None... | 9,662 | 38.280488 | 136 | py |
EasyMocap | EasyMocap-master/myeasymocap/operations/merge.py | import numpy as np
import cv2
import scipy
import torch
class MultilView_Merge:
def __init__(self) -> None:
pass
def forward(self, data,ax=0):
'''
data - dict
data[key] (nv,...)
'''
results={}
for key in data.keys():
results[key] = data[key].m... | 7,545 | 38.098446 | 119 | py |
EasyMocap | EasyMocap-master/myeasymocap/operations/optimizer.py | import torch
import torch.nn as nn
from easymocap.config import Config, load_object
from easymocap.mytools.debug_utils import log
def dict_of_numpy_to_tensor(body_params, device):
params_ = {}
for key, val in body_params.items():
if isinstance(val, dict):
params_[key] = dict_of_numpy_to_ten... | 6,863 | 39.140351 | 141 | py |
misinfo-baselines | misinfo-baselines-main/custom_predictor.py | from allennlp.predictors.predictor import Predictor
from typing import List, Dict
from overrides import overrides
import numpy
from allennlp.common.util import JsonDict
from allennlp.data import Instance
from allennlp.predictors.predictor import Predictor
from allennlp.data.fields import LabelField
from allennlp.dat... | 6,032 | 40.040816 | 109 | py |
misinfo-baselines | misinfo-baselines-main/src/modules/pooling/pooling.py | import torch
from torch import nn
from allennlp.common import Registrable
class Pooling(Registrable, nn.Module):
default_implementation = 'mean'
def forward(self, logits_ensemble: torch.Tensor):
raise NotImplementedError() | 240 | 25.777778 | 53 | py |
misinfo-baselines | misinfo-baselines-main/src/modules/pooling/mean.py | import torch
from src.modules.pooling.pooling import Pooling
@Pooling.register('mean')
class MeanPooling(Pooling):
def forward(self, logits_ensemble: torch.Tensor):
return logits_ensemble.mean(dim=1) | 212 | 29.428571 | 53 | py |
misinfo-baselines | misinfo-baselines-main/src/modules/pooling/attention.py | import torch
from torch import nn
from torch.nn import functional as F
from allennlp.nn import util
from src.modules.pooling.pooling import Pooling
import torchsnooper
@Pooling.register('attention')
class AttentionPooling(Pooling):
def __init__(
self,
num_models: int,
**kwargs
):
... | 588 | 25.772727 | 80 | py |
misinfo-baselines | misinfo-baselines-main/src/models/basic_classifier_with_metrics.py | from typing import Dict, Optional
from overrides import overrides
import torch
from allennlp.data import TextFieldTensors, Vocabulary
from allennlp.models import Model, BasicClassifier
from allennlp.nn import util
from src.training.multilabel_f1 import SKLearnF1Score
import torchsnooper
@Model.register("metrics_cla... | 1,992 | 35.236364 | 106 | py |
misinfo-baselines | misinfo-baselines-main/src/models/ensemble.py | # See:
# https://github.com/allenai/allennlp/blob/v0.9.0/allennlp/models/ensemble.py
# https://github.com/allenai/allennlp-models/blob/2b9ca77aebf21cb965207752989a4201a96d42f5/allennlp_models/rc/models/bidaf_ensemble.py
from typing import Dict, Optional, List
from overrides import overrides
import torch
from torch im... | 2,989 | 36.848101 | 134 | py |
herculens | herculens-main/test/modeling_test.py | # Testing modeling workflows
#
# Copyright (c) 2023, herculens developers and contributors
import numpy as np
import numpy.testing as npt
import pytest
import matplotlib.pyplot as plt
import time
from copy import deepcopy
from functools import partial
import jax
import jax.numpy as jnp
# uncomment for double precis... | 11,726 | 42.594796 | 130 | py |
herculens | herculens-main/herculens/info.py | """PACKAGE INFO
This module provides some basic information about the package.
"""
# Set the package release version
version_info = (0, 0, 1)
__version__ = '.'.join(str(c) for c in version_info)
# Set the package details
__author__ = 'Austin Peel, Aymeric Galan'
__email__ = 'austin.peel@epfl.ch'
__year__ = '2021'
_... | 992 | 26.583333 | 72 | py |
herculens | herculens-main/herculens/LightModel/light_model_base.py | # Describes a light model, as a list of light profiles
#
# Copyright (c) 2023, herculens developers and contributors
# Copyright (c) 2018, Simon Birrer & lenstronomy contributors
# based on the LightModel module from lenstronomy (version 1.9.3)
__author__ = 'sibirrer', 'austinpeel', 'aymgal'
import numpy as np
impo... | 5,083 | 35.314286 | 122 | py |
herculens | herculens-main/herculens/LightModel/light_model.py | # High-level interface to a light model
#
# Copyright (c) 2023, herculens developers and contributors
# Copyright (c) 2018, Simon Birrer & lenstronomy contributors
# based on the LightModel module from lenstronomy (version 1.9.3)
__author__ = 'sibirrer', 'austinpeel', 'aymgal'
import numpy as np
import jax.numpy as... | 3,514 | 36.795699 | 97 | py |
herculens | herculens-main/herculens/LightModel/Profiles/sersic.py | # Defines Sersic profiles
#
# Copyright (c) 2021, herculens developers and contributors
# Copyright (c) 2018, Simon Birrer & lenstronomy contributors
# based on the LightModel.Profiles module from lenstronomy (version 1.9.3)
__author__ = 'sibirrer', 'jiwoncpark', 'austinpeel', 'aymgal'
import numpy as np
import jax... | 7,211 | 38.195652 | 127 | py |
herculens | herculens-main/herculens/LightModel/Profiles/uniform.py | # Defines a uniform profile
#
# Copyright (c) 2021, herculens developers and contributors
__author__ = 'austinpeel', 'aymgal'
import jax.numpy as jnp
__all__ = ['Uniform']
class Uniform(object):
"""
class for uniform light profile
"""
param_names = ['amp']
lower_limit_default = {'amp': -100}... | 715 | 17.358974 | 59 | py |
herculens | herculens-main/herculens/LightModel/Profiles/gaussian.py | # Defines a gaussian profile
#
# Copyright (c) 2021, herculens developers and contributors
# Copyright (c) 2018, Simon Birrer & lenstronomy contributors
# based on the LightModel.Profiles module from lenstronomy (version 1.9.3)
__author__ = 'sibirrer', 'austinpeel', 'aymgal'
import numpy as np
import jax.numpy as j... | 4,790 | 35.853846 | 113 | py |
herculens | herculens-main/herculens/LightModel/Profiles/pixelated.py | # Defines a pixelated profile
#
# Copyright (c) 2023, herculens developers and contributors
__author__ = 'austinpeel', 'aymgal'
import warnings
import numpy as np
import jax.numpy as jnp
from jax import grad, jacfwd, jacrev, vmap
from herculens.Util import util
__all__= ['Pixelated']
class Pixelated(object):
... | 7,708 | 40.896739 | 134 | py |
herculens | herculens-main/herculens/LightModel/Profiles/shapelets.py | # Defines a pixelated profile
#
# Copyright (c) 2021, herculens developers and contributors
__author__ = 'aymgal'
import jax.numpy as jnp
__all__= ['Shapelets']
class Shapelets(object):
"""Surface brightness with a set of basis functions"""
param_names = ['beta', 'center_x', 'center_y', 'amps']
lower... | 1,599 | 35.363636 | 116 | py |
herculens | herculens-main/herculens/Util/param_util.py | # Utility functions
#
# Copyright (c) 2021, herculens developers and contributors
# Copyright (c) 2018, Simon Birrer & lenstronomy contributors
# based on the Util module from lenstronomy (version 1.9.3)
__author__ = 'sibirrer', 'austinpeel', 'aymgal'
import numpy as np
import jax.numpy as jnp
from jax import lax
... | 6,191 | 29.96 | 101 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.