python_code stringlengths 0 4.04M | repo_name stringlengths 8 58 | file_path stringlengths 5 147 |
|---|---|---|
#!/usr/bin/env python3
# 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.
"""
To run bandits example in multiprocess mode:
$ python3 examples/bandits/membership_inference.py --multiprocess
T... | CrypTen-main | examples/bandits/membership_inference.py |
#!/usr/bin/env python3
# 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.
"""
To run bandits example in multiprocess mode:
$ python3 examples/bandits/launcher.py --multiprocess
To run bandit... | CrypTen-main | examples/bandits/launcher.py |
#!/usr/bin/env python3
# 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.
import logging
import os
import random
import shutil
import tempfile
import time
import warnings
import crypten
impor... | CrypTen-main | examples/tfe_benchmarks/tfe_benchmarks.py |
#!/usr/bin/env python3
# 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.
"""
To run tfe_benchmarks example in multiprocess mode:
$ python3 examples/tfe_benchmarks/launcher.py --multiprocess
... | CrypTen-main | examples/tfe_benchmarks/launcher.py |
#!/usr/bin/env python3
# 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.
import logging
import tempfile
import crypten
import torch
import torchvision.datasets as datasets
import torchvision... | CrypTen-main | examples/mpc_imagenet/mpc_imagenet.py |
#!/usr/bin/env python3
# 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.
"""
To run tfe_benchmarks example in multiprocess mode:
$ python3 examples/mpc_imagenet/launcher.py --multiprocess
T... | CrypTen-main | examples/mpc_imagenet/launcher.py |
#!/usr/bin/env python3
# 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.
"""
To run mpc_linear_svm example in multiprocess mode:
$ python3 examples/mpc_linear_svm/launcher.py --multiprocess
... | CrypTen-main | examples/mpc_linear_svm/launcher.py |
#!/usr/bin/env python3
# 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.
import logging
import time
import crypten
import torch
from examples.meters import AverageMeter
def train_linear_sv... | CrypTen-main | examples/mpc_linear_svm/mpc_linear_svm.py |
#!/usr/bin/env python3
# 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.
import tempfile
import crypten
import crypten.communicator as comm
import torch
import torch.nn as nn
import torch.nn... | CrypTen-main | examples/mpc_autograd_cnn/mpc_autograd_cnn.py |
#!/usr/bin/env python3
# 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.
"""
To run mpc_autograd_cnn example:
$ python examples/mpc_autograd_cnn/launcher.py
To run mpc_linear_svm example on ... | CrypTen-main | examples/mpc_autograd_cnn/launcher.py |
#!/usr/bin/env python3
# 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.
"""
Generate function and model benchmarks
To Run:
$ python benchmark.py
# Only function benchmarks
$ python benchmar... | CrypTen-main | benchmarks/benchmark.py |
#!/usr/bin/env python3
# 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.
"""
Contains models used for benchmarking
"""
from dataclasses import dataclass
from typing import Any
import crypte... | CrypTen-main | benchmarks/models.py |
CrypTen-main | benchmarks/__init__.py | |
#!/usr/bin/env python3
# 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.
"""
A script to run historical benchmarks.
- writes monthly data to 'dash_app/data/`
- example: 'dash_app/data/201... | CrypTen-main | benchmarks/run_historical_benchmarks.py |
#!/usr/bin/env python3
# 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.
"""
Profiler with snakeviz for probing inference / training call stack
Run via Jupyter
"""
from benchmark import Mod... | CrypTen-main | benchmarks/profiler.py |
#!/usr/bin/env python3
# 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.
"""
Contains data used for training / testing model benchmarks
"""
import os
from pathlib import Path
import crypten
... | CrypTen-main | benchmarks/data.py |
CrypTen-main | benchmarks/dash_app/__init__.py | |
#!/usr/bin/env python3
# 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.
import pathlib
import dash
import dash_core_components as dcc
import dash_html_components as html
import numpy as np
... | CrypTen-main | benchmarks/dash_app/app.py |
#!/usr/bin/env python3
# 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.
import os
import pandas as pd
def get_aggregated_data(base_dir, subdirs):
"""Aggregate dataframe for model and... | CrypTen-main | benchmarks/dash_app/load_data.py |
CrypTen-main | configs/__init__.py | |
#!/usr/bin/env python3
# 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.
import os
import subprocess
import uuid
from argparse import ArgumentParser, REMAINDER
"""
Wrapper to launch MPC scr... | CrypTen-main | scripts/distributed_launcher.py |
#!/usr/bin/env python3
# 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.
"""
This file is a tool to run MPC distributed training over AWS.
To run distributed training, first multiple AWS inst... | CrypTen-main | scripts/aws_launcher.py |
#!/usr/bin/env python3
# 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.
import argparse
import os
import torch
from torchvision import datasets, transforms
def _get_norm_mnist(dir, reduce... | CrypTen-main | tutorials/mnist_utils.py |
# Copyright (c) Facebook, Inc. and its affiliates.
import cv2
import sys
import numpy as np
from utils import (
initialize_render, merge_meshes,
load_motion
)
import torch
from PIL import Image
from model import JOHMRLite
import os
import glob
import json
from pathlib import Path
import argparse
import re
impo... | d3d-hoi-main | visualization/visualize_data.py |
# Copyright (c) Facebook, Inc. and its affiliates.
import torch.nn as nn
import torch
import numpy as np
from pytorch3d.renderer import (
look_at_view_transform, TexturesVertex
)
from pytorch3d.structures import Meshes
from utils import rotation_matrix
from pytorch3d.io import save_obj
from pytorch3d.transforms imp... | d3d-hoi-main | visualization/model.py |
# Copyright (c) Facebook, Inc. and its affiliates.
import numpy as np
import torch
import natsort
import glob
import open3d as o3d
# rendering components
from pytorch3d.renderer import (
FoVPerspectiveCameras,RasterizationSettings,
MeshRenderer, MeshRasterizer, BlendParams,
SoftSilhouetteShader, HardPhongSh... | d3d-hoi-main | visualization/utils.py |
# Copyright (c) Facebook, Inc. and its affiliates.
import cv2
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
import numpy as np
from utils import (
initialize_render, merge_meshes,
load_motion
)
import torch
from PIL import Image
from natsort import natsorted
from model import JOHMRLite
import os
import... | d3d-hoi-main | visualization/annotation/qt.py |
# Copyright (c) Facebook, Inc. and its affiliates.
import torch.nn as nn
import torch
import pdb
import numpy as np
from pytorch3d.renderer import (
look_at_view_transform, TexturesVertex
)
import math
from pytorch3d.structures import Meshes
import cv2
import matplotlib.pyplot as plt
from utils import rotation_mat... | d3d-hoi-main | visualization/annotation/model.py |
# Copyright (c) Facebook, Inc. and its affiliates.
import numpy as np
import torch
import natsort
import glob
import open3d as o3d
# rendering components
from pytorch3d.renderer import (
FoVPerspectiveCameras,RasterizationSettings,
MeshRenderer, MeshRasterizer, BlendParams,
SoftSilhouetteShader, HardPhongS... | d3d-hoi-main | visualization/annotation/utils.py |
# Copyright (c) Facebook, Inc. and its affiliates.
import torch
import os
from model import JOHMRModel
from utils import (
initialize_render, merge_meshes,
load_motion,
save_meshes, save_parameters
)
import json
import tqdm
from matplotlib.image import imsave
import matplotlib.pyplot as plt
import cv2
impor... | d3d-hoi-main | optimization/optimize.py |
# Copyright (c) Facebook, Inc. and its affiliates.
import torch.nn as nn
import torch
import numpy as np
from pytorch3d.renderer import (
look_at_view_transform, TexturesVertex
)
import math
from pytorch3d.structures import Meshes
import cv2
import matplotlib.pyplot as plt
from utils import rotation_matrix_batch
fr... | d3d-hoi-main | optimization/model.py |
# Copyright (c) Facebook, Inc. and its affiliates.
import numpy as np
import torch
import natsort
import glob
import open3d as o3d
# rendering components
from pytorch3d.renderer import (
FoVPerspectiveCameras,RasterizationSettings,
MeshRenderer, MeshRasterizer, BlendParams,
SoftSilhouetteShader, HardPhongSh... | d3d-hoi-main | optimization/utils.py |
# Copyright (c) Facebook, Inc. and its affiliates.
import os
import numpy as np
import cv2
import matplotlib.pyplot as plt
import torch
from pytorch3d.transforms import (
so3_relative_angle,
euler_angles_to_matrix
)
from scipy.spatial.distance import cdist
import json
from utils import (
load_motion,
)
impo... | d3d-hoi-main | optimization/evaluate.py |
# Copyright (c) Facebook, Inc. and its affiliates.
from skimage import io
from torch.utils.data import Dataset
import json
import os
import numpy as np
import torch
import matplotlib.pyplot as plt
import torchvision.transforms as transforms
from PIL import Image
import cv2
from natsort import natsorted
from utils impor... | d3d-hoi-main | optimization/dataloader.py |
import os
import argparse
import ntpath
import common
import pdb
import open3d as o3d
import numpy as np
class Simplification:
"""
Perform simplification of watertight meshes.
"""
def __init__(self):
"""
Constructor.
"""
parser = self.get_parser()
self.options ... | d3d-hoi-main | preprocess/3_simplify.py |
# Copyright (c) Facebook, Inc. and its affiliates.import math
import os
import torch
import numpy as np
from tqdm import tqdm_notebook
import imageio
import torch.nn as nn
import torch.nn.functional as F
import matplotlib.pyplot as plt
from skimage import img_as_ubyte
import pdb
import glob
import natsort
from torch.au... | d3d-hoi-main | preprocess/visualize_data.py |
import math
import numpy as np
import os
from scipy import ndimage
import common
import argparse
import ntpath
# Import shipped libraries.
import librender
import libmcubes
use_gpu = True
if use_gpu:
import libfusiongpu as libfusion
from libfusiongpu import tsdf_gpu as compute_tsdf
else:
import libfusionc... | d3d-hoi-main | preprocess/2_fusion.py |
import os
import subprocess
from tqdm import tqdm
from multiprocessing import Pool
def convert(obj_path):
try:
load_folder = os.path.join(obj_path, 'parts_ply')
save_folder = os.path.join(obj_path, 'parts_off')
part_paths = [f.path for f in os.scandir(load_folder)]
if not os.path.... | d3d-hoi-main | preprocess/convert_off.py |
import pdb
import subprocess
import scandir
from multiprocessing import Pool
import json
import common
def remesh(obj_path):
in_dir = os.path.join(obj_path, 'parts_off/')
scaled_dir = os.path.join(obj_path, 'parts_scaled_off/')
depth_dir = os.path.join(obj_path, 'parts_depth_off/')
fused_dir = os.path... | d3d-hoi-main | preprocess/re-meshing.py |
"""
Some I/O utilities.
"""
import os
import time
import h5py
import math
import numpy as np
def write_hdf5(file, tensor, key = 'tensor'):
"""
Write a simple tensor, i.e. numpy array ,to HDF5.
:param file: path to file to write
:type file: str
:param tensor: tensor to write
:type tensor: nump... | d3d-hoi-main | preprocess/common.py |
# Copyright (c) Facebook, Inc. and its affiliates.
import math
import os
import torch
import numpy as np
from tqdm import tqdm_notebook
import imageio
import torch.nn as nn
import torch.nn.functional as F
import matplotlib.pyplot as plt
from skimage import img_as_ubyte
from tqdm import tqdm
import re
import open3d as o... | d3d-hoi-main | preprocess/process_data.py |
import os
import common
import argparse
import numpy as np
import json
class Scale:
"""
Scales a bunch of meshes.
"""
def __init__(self):
"""
Constructor.
"""
parser = self.get_parser()
self.options = parser.parse_args()
def get_parser(self):
"""
... | d3d-hoi-main | preprocess/1_scale.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.
import sys, os
import time
import re
mode="analyze"
m=3
pre_k=1
main_k=5
def run_infer(infer_out, k, model, quiet):
to... | data_driven_infer-main | bin/DDInfer.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.
import sys, os
import time
import re
def run(path, p, k, model):
total_time, total_alarms = 0, 0
try:
infe... | data_driven_infer-main | Table2/bin/eval_ml_infer.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.
import numpy as np
import sklearn
from sklearn.ensemble import GradientBoostingClassifier
import pickle
import itertools
im... | data_driven_infer-main | Table2/bin/collect.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.
import numpy as np
from multiprocessing import Process
import sklearn
from sklearn.ensemble import GradientBoostingClassifi... | data_driven_infer-main | Table2/bin/learn_classifier.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.
import sys, os
import infer
if len(sys.argv) < 6:
print("usage:")
print("python run_ml_infer.py bin/programs_test.... | data_driven_infer-main | Table2/bin/run_ml_infer.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.
import sys, os
import time
import re
import random
from multiprocessing import Process, Queue, Manager
def split_list(a, n... | data_driven_infer-main | Table2/bin/infer.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.
# Modified from github.com/openai/CLIP
from collections import OrderedDict
import numpy as np
import timm
import torch
fr... | clip-rocket-main | models.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.
"""
A script to run multinode training with submitit.
"""
import argparse
import os
import uuid
from pathlib import Path
i... | clip-rocket-main | run_with_submitit.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.
from collections import defaultdict
import json
import os
import pickle
import zipfile
import numpy as np
from PIL import... | clip-rocket-main | datasets.py |
# Taken from https://github.com/rwightman/timm
""" Vision Transformer (ViT) in PyTorch
A PyTorch implement of Vision Transformers as described in:
'An Image Is Worth 16 x 16 Words: Transformers for Image Recognition at Scale'
- https://arxiv.org/abs/2010.11929
`How to train your ViT? Data, Augmentation, and Regular... | clip-rocket-main | vit.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.
# Modified from github.com/openai/CLIP
import gzip
import html
import os
from functools import lru_cache
import ftfy
impo... | clip-rocket-main | tokenizer.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.
import numpy as np
import os
import random
import shutil
import torch
import torch.distributed as dist
import torch.autogr... | clip-rocket-main | utils.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.
import argparse
from collections import OrderedDict, defaultdict
import json
import os
from sklearn import metrics
import ... | clip-rocket-main | eval_zeroshot.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.
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.distributed as dist
import utils
class C... | clip-rocket-main | losses.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.
import argparse
from collections import OrderedDict, defaultdict
import json
import math
import os
import sys
import time
... | clip-rocket-main | main.py |
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
from absl import app
from absl import flags
import cv2
import os.path as osp
import sys
sys.path.insert(0,'third_party')
import pdb
import time
import numpy as np
import torch
import torch.backends.cudnn as cudnn
cudnn.benchmark = True
from nnuti... | banmo-main | main.py |
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
from absl import flags, app
import sys
sys.path.insert(0,'third_party')
import numpy as np
import torch
import os
import glob
import pdb
import cv2
import trimesh
from scipy.spatial.transform import Rotation as R
import imageio
from utils.io impo... | banmo-main | extract.py |
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
import cv2
import glob
import numpy as np
import pdb
import os
import shutil
import detectron2
from detectron2.config import get_cfg
from detectron2.engine import DefaultPredictor
from detectron2.utils.visualizer import Visualizer, ColorMode
fro... | banmo-main | preprocess/mask.py |
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
"""
python img2lines.py --seqname xx
"""
from absl import flags, app
import sys
sys.path.insert(0,'third_party')
sys.path.insert(0,'./')
import numpy as np
import torch
import os
import glob
import pdb
import cv2
import trimesh
from scipy.spatial... | banmo-main | preprocess/img2lines.py |
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
import configparser
import cv2
import glob
import pdb
import sys
seqname_pre=sys.argv[1]
ishuman=sys.argv[2] # 'y/n'
silroot='database/DAVIS/Annotations/Full-Resolution/'
config = configparser.ConfigParser()
config['data'] = {
'dframe': '1',
'in... | banmo-main | preprocess/write_config.py |
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
import cv2
import glob
import numpy as np
import pdb
import os
import shutil
import detectron2
from detectron2.config import get_cfg
from detectron2.engine import DefaultPredictor
from detectron2.utils.visualizer import Visualizer, ColorMode
from... | banmo-main | preprocess/compute_dp.py |
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
import os
import errno
from typing import Any, Dict, List, Tuple, Union
import cv2
import pdb
import configparser
import torch
import numpy as np
import imageio
import trimesh
import glob
import matplotlib.cm
import torch.nn.functional as F
from sc... | banmo-main | utils/io.py |
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
import pickle
import cv2
import numpy as np
import os
import torch
import torch.nn.functional as F
import pdb
import trimesh
from detectron2.config import get_cfg
from detectron2.modeling import build_model
from detectron2.checkpoint import Detect... | banmo-main | utils/cselib.py |
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
import numpy as np
def label_colormap():
"""
colormap for visualizing bones
"""
return np.asarray(
[[155, 122, 157],
[ 45, 245, 50],
[ 71, 25, 64],
[231, 176, 35],
[125, 249, 245],
[ 32, 75, 253],
[241, 31, 111],
[218, 71,... | banmo-main | utils/colors.py |
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import torch
import torch.nn as nn
import os
import os.path as osp
import sys
sys.path.insert(0,'third_party')
import time
import pdb
impo... | banmo-main | nnutils/train_utils.py |
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
# adopted from nerf-pl
import numpy as np
import pdb
import torch
import torch.nn.functional as F
from pytorch3d import transforms
from nnutils.geom_utils import lbs, Kmatinv, mat2K, pinhole_cam, obj_to_cam,\
vec_to... | banmo-main | nnutils/rendering.py |
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
import numpy as np
import pdb
import torch
from torch import nn
import torch.nn.functional as F
import torchvision
from pytorch3d import transforms
import trimesh
from nnutils.geom_utils import fid_reindex
class Embedding(nn.Module):
def __in... | banmo-main | nnutils/nerf.py |
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from absl import app
from absl import flags
from collections import defaultdict
import os
import os.path as osp
import pickle
import sys
s... | banmo-main | nnutils/banmo.py |
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
import cv2, pdb, os, sys, numpy as np, torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision
curr_dir = os.path.abspath(os.getcwd())
sys.path.insert(0, curr_dir)
detbase = './third_party/detectron2/'
sys.path.insert(0, '%s... | banmo-main | nnutils/cse.py |
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
import torch
def image_grid(img, row, col):
"""
img: N,h,w,x
collage: 1,.., x
"""
bs,h,w,c=img.shape
device = img.device
collage = torch.zeros(h*row, w*col, c).to(device)
for i in range(row):
for j in r... | banmo-main | nnutils/vis_utils.py |
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
import pdb
import time
import cv2
import numpy as np
import trimesh
from pytorch3d import transforms
import torch
import torch.nn as nn
import torch.nn.functional as F
from scipy.spatial.transform import Rotation as R
import sys
sys.path.insert(0... | banmo-main | nnutils/geom_utils.py |
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
import pdb
import trimesh
import cv2
import numpy as np
import torch
from nnutils.geom_utils import rot_angle, mat2K, Kmatinv, obj_to_cam, \
pinhole_cam, lbs, gauss_mlp_skinning, evaluate_mlp
import torch.nn.functio... | banmo-main | nnutils/loss_utils.py |
"""
MIT License
Copyright (c) 2019 ThibaultGROUEIX
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publis... | banmo-main | third_party/fscore.py |
# MIT license
# Copyright (c) 2019 LI RUOTENG
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, p... | banmo-main | third_party/ext_utils/flowlib.py |
# MIT License
#
# Copyright (c) 2019 Carnegie Mellon University
# Copyright (c) 2021 Google LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limi... | banmo-main | third_party/ext_utils/util_flow.py |
from setuptools import setup, find_packages
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
CUDA_FLAGS = []
gencodes = [
'-gencode', 'arch=compute_52,code=sm_52',
'-gencode', 'arch=compute_60,code=sm_60',
'-gencode', 'arch=compute_61,code=sm_61',
... | banmo-main | third_party/softras/setup.py |
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy
import soft_renderer as sr
class Renderer(nn.Module):
def __init__(self, image_size=256, background_color=[0,0,0], near=1, far=100,
anti_aliasing=True, fill_back=True, eps=1e-6,
camera... | banmo-main | third_party/softras/soft_renderer/renderer.py |
from . import functional
from .mesh import Mesh
from .renderer import Renderer, SoftRenderer
from .transform import Projection, LookAt, Look, Transform
from .lighting import AmbientLighting, DirectionalLighting, Lighting
from .rasterizer import SoftRasterizer
from .losses import LaplacianLoss, FlattenLoss
__version__... | banmo-main | third_party/softras/soft_renderer/__init__.py |
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import soft_renderer.functional as srf
class Mesh(object):
'''
A simple class for creating and manipulating trimesh objects
'''
def __init__(self, vertices, faces, textures=None, texture_res=1, texture_type='surface... | banmo-main | third_party/softras/soft_renderer/mesh.py |
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import soft_renderer.functional as srf
class AmbientLighting(nn.Module):
def __init__(self, light_intensity=0.5, light_color=(1,1,1)):
super(AmbientLighting, self).__init__()
self.light_intensity = light_intens... | banmo-main | third_party/softras/soft_renderer/lighting.py |
import math
import numpy as np
import torch
import torch.nn as nn
import soft_renderer.functional as srf
class Projection(nn.Module):
def __init__(self, P, dist_coeffs=None, orig_size=512):
super(Projection, self).__init__()
self.P = P
self.dist_coeffs = dist_coeffs
self.orig_siz... | banmo-main | third_party/softras/soft_renderer/transform.py |
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
import soft_renderer.functional as srf
class SoftRasterizer(nn.Module):
def __init__(self, image_size=256, background_color=[0, 0, 0], near=1, far=100,
anti_aliasing=False, fill_back=False, eps=1e-3,
... | banmo-main | third_party/softras/soft_renderer/rasterizer.py |
import torch
import torch.nn as nn
import numpy as np
class LaplacianLoss(nn.Module):
def __init__(self, vertex, faces, average=False):
super(LaplacianLoss, self).__init__()
self.nv = vertex.size(0)
self.nf = faces.size(0)
self.average = average
laplacian = np.zeros([self.n... | banmo-main | third_party/softras/soft_renderer/losses.py |
banmo-main | third_party/softras/soft_renderer/cuda/__init__.py | |
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Function
import soft_renderer.cuda.voxelization as voxelization_cuda
def voxelize_sub1(faces, size, dim):
bs = faces.size(0)
nf = faces.size(1)
if dim == 0:
faces = faces[:, :, :, [2, 1, 0]].contiguous()... | banmo-main | third_party/softras/soft_renderer/functional/voxelization.py |
import numpy as np
import torch
import torch.nn.functional as F
def look_at(vertices, eye, at=[0, 0, 0], up=[0, 1, 0]):
"""
"Look at" transformation of vertices.
"""
if (vertices.ndimension() != 3):
raise ValueError('vertices Tensor should have 3 dimensions')
device = vertices.device
... | banmo-main | third_party/softras/soft_renderer/functional/look_at.py |
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
def directional_lighting(light, normals, light_intensity=0.5, light_color=(1,1,1),
light_direction=(0,1,0)):
# normals: [nb, :, 3]
device = light.device
if isinstance(light_color, tuple) or is... | banmo-main | third_party/softras/soft_renderer/functional/directional_lighting.py |
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
def ambient_lighting(light, light_intensity=0.5, light_color=(1,1,1)):
device = light.device
if isinstance(light_color, tuple) or isinstance(light_color, list):
light_color = torch.tensor(light_color, dtype=torch.fl... | banmo-main | third_party/softras/soft_renderer/functional/ambient_lighting.py |
import math
import torch
def perspective(vertices, angle=30.):
'''
Compute perspective distortion from a given angle
'''
if (vertices.ndimension() != 3):
raise ValueError('vertices Tensor should have 3 dimensions')
device = vertices.device
angle = torch.tensor(angle / 180 * math.pi, dt... | banmo-main | third_party/softras/soft_renderer/functional/perspective.py |
import os
import torch
import numpy as np
from skimage.io import imread
import soft_renderer.cuda.load_textures as load_textures_cuda
def load_mtl(filename_mtl):
'''
load color (Kd) and filename of textures from *.mtl
'''
texture_filenames = {}
colors = {}
material_name = ''
with open(fil... | banmo-main | third_party/softras/soft_renderer/functional/load_obj.py |
import torch
def face_vertices(vertices, faces):
"""
:param vertices: [batch size, number of vertices, 3]
:param faces: [batch size, number of faces, 3]
:return: [batch size, number of faces, 3, 3]
"""
assert (vertices.ndimension() == 3)
assert (faces.ndimension() == 3)
assert (vertice... | banmo-main | third_party/softras/soft_renderer/functional/face_vertices.py |
import numpy as np
import torch
import torch.nn.functional as F
def look(vertices, eye, direction=[0, 1, 0], up=None):
"""
"Look" transformation of vertices.
"""
if (vertices.ndimension() != 3):
raise ValueError('vertices Tensor should have 3 dimensions')
device = vertices.device
if ... | banmo-main | third_party/softras/soft_renderer/functional/look.py |
from .get_points_from_angles import get_points_from_angles
from .ambient_lighting import ambient_lighting
from .directional_lighting import directional_lighting
from .load_obj import load_obj
from .look import look
from .look_at import look_at
from .perspective import perspective
from .orthogonal import orthogonal
from... | banmo-main | third_party/softras/soft_renderer/functional/__init__.py |
import os
import torch
from skimage.io import imsave
import soft_renderer.cuda.create_texture_image as create_texture_image_cuda
def create_texture_image(textures, texture_res=16):
num_faces = textures.shape[0]
tile_width = int((num_faces - 1.) ** 0.5) + 1
tile_height = int((num_faces - 1.) / tile_width... | banmo-main | third_party/softras/soft_renderer/functional/save_obj.py |
import math
import torch
def get_points_from_angles(distance, elevation, azimuth, degrees=True):
if isinstance(distance, float) or isinstance(distance, int):
if degrees:
elevation = math.radians(elevation)
azimuth = math.radians(azimuth)
return (
distance * math... | banmo-main | third_party/softras/soft_renderer/functional/get_points_from_angles.py |
import torch
def orthogonal(vertices, scale):
'''
Compute orthogonal projection from a given angle
To find equivalent scale to perspective projection
set scale = focal_pixel / object_depth -- to 0~H/W pixel range
= 1 / ( object_depth * tan(half_fov_angle) ) -- to -1~1 pixel range
''... | banmo-main | third_party/softras/soft_renderer/functional/orthogonal.py |
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Function
import numpy as np
import soft_renderer.cuda.soft_rasterize as soft_rasterize_cuda
class SoftRasterizeFunction(Function):
@staticmethod
def forward(ctx, face_vertices, textures, image_size=256,
... | banmo-main | third_party/softras/soft_renderer/functional/soft_rasterize.py |
import torch
def projection(vertices, P, dist_coeffs, orig_size):
'''
Calculate projective transformation of vertices given a projection matrix
P: 3x4 projection matrix
dist_coeffs: vector of distortion coefficients
orig_size: original size of image captured by the camera
'''
vertices = to... | banmo-main | third_party/softras/soft_renderer/functional/projection.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.