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 |
|---|---|---|---|---|---|---|
ARSaliency | ARSaliency-main/models/VQSal/sal_model/modules/transformer/mingpt.py | """
taken from: https://github.com/karpathy/minGPT/
GPT model:
- the initial stem consists of a combination of token encoding and a positional encoding
- the meat of it is a uniform sequence of Transformer blocks
- each Transformer is a sequential combination of a 1-hidden-layer MLP block and a self-attention block... | 13,577 | 38.586006 | 136 | py |
ARSaliency | ARSaliency-main/models/VQSal/sal_model/modules/transformer/permuter.py | import torch
import torch.nn as nn
import numpy as np
class AbstractPermuter(nn.Module):
def __init__(self, *args, **kwargs):
super().__init__()
def forward(self, x, reverse=False):
raise NotImplementedError
class Identity(AbstractPermuter):
def __init__(self):
super().__init__()... | 7,093 | 27.48996 | 83 | py |
ARSaliency | ARSaliency-main/models/VQSal/sal_model/modules/transformer/minbert.py | """
taken from: https://github.com/karpathy/minGPT/
GPT model:
- the initial stem consists of a combination of token encoding and a positional encoding
- the meat of it is a uniform sequence of Transformer blocks
- each Transformer is a sequential combination of a 1-hidden-layer MLP block and a self-attention block... | 13,838 | 38.99711 | 136 | py |
ARSaliency | ARSaliency-main/models/VQSal/sal_model/models/vqgan.py | ## --------------------------------------------------------------------------
## Saliency in Augmented Reality
## Huiyu Duan, Wei Shen, Xiongkuo Min, Danyang Tu, Jing Li, and Guangtao Zhai
## ACM International Conference on Multimedia (ACM MM 2022)
## --------------------------------------------------------------------... | 16,590 | 42.775726 | 126 | py |
ARSaliency | ARSaliency-main/models/VQSal/sal_model/models/vqsal_ar.py | ## --------------------------------------------------------------------------
## Saliency in Augmented Reality
## Huiyu Duan, Wei Shen, Xiongkuo Min, Danyang Tu, Jing Li, and Guangtao Zhai
## ACM International Conference on Multimedia (ACM MM 2022)
## --------------------------------------------------------------------... | 18,868 | 43.92619 | 126 | py |
ARSaliency | ARSaliency-main/models/VQSal/sal_model/data/saliency.py | ## --------------------------------------------------------------------------
## Saliency in Augmented Reality
## Huiyu Duan, Wei Shen, Xiongkuo Min, Danyang Tu, Jing Li, and Guangtao Zhai
## ACM International Conference on Multimedia (ACM MM 2022)
## --------------------------------------------------------------------... | 13,239 | 41.572347 | 179 | py |
ARSaliency | ARSaliency-main/models/VQSal/sal_model/data/base.py | import bisect
import numpy as np
import albumentations
from PIL import Image
from torch.utils.data import Dataset, ConcatDataset
class ConcatDatasetWithIndex(ConcatDataset):
"""Modified from original pytorch code to return dataset idx"""
def __getitem__(self, idx):
if idx < 0:
if -idx > le... | 2,609 | 35.760563 | 92 | py |
ARSaliency | ARSaliency-main/models/VQSal/sal_model/data/saliency_AR.py | ## --------------------------------------------------------------------------
## Saliency in Augmented Reality
## Huiyu Duan, Wei Shen, Xiongkuo Min, Danyang Tu, Jing Li, and Guangtao Zhai
## ACM International Conference on Multimedia (ACM MM 2022)
## --------------------------------------------------------------------... | 18,513 | 44.266504 | 179 | py |
ARSaliency | ARSaliency-main/models/VQSal/sal_model/data/panorama.py | import os
import random
import numpy as np
import cv2
import albumentations
from PIL import Image
from torch.utils.data import Dataset
import random
import glob
from .base import ConcatDatasetWithIndex
# from taming.data.base import ImagePaths, NumpyPaths, ConcatDatasetWithIndex
class FacesBase(Dataset):
def __i... | 26,990 | 44.670051 | 180 | py |
ARSaliency | ARSaliency-main/models/VQSal/taming/modules/util.py | import torch
import torch.nn as nn
def count_params(model):
total_params = sum(p.numel() for p in model.parameters())
return total_params
class ActNorm(nn.Module):
def __init__(self, num_features, logdet=False, affine=True,
allow_reverse_init=False):
assert affine
super(... | 2,900 | 28.30303 | 85 | py |
ARSaliency | ARSaliency-main/models/VQSal/taming/modules/vqvae/quantize.py | import torch
import torch.nn as nn
class VectorQuantizer(nn.Module):
"""
see https://github.com/MishaLaskin/vqvae/blob/d761a999e2267766400dc646d82d3ac3657771d4/models/quantizer.py
____________________________________________
Discretization bottleneck part of the VQ-VAE.
Inputs:
- n_e : number ... | 3,624 | 35.25 | 110 | py |
ARSaliency | ARSaliency-main/models/VQSal/taming/modules/discriminator/model.py | import functools
import torch.nn as nn
from taming.modules.util import ActNorm
def weights_init(m):
classname = m.__class__.__name__
if classname.find('Conv') != -1:
nn.init.normal_(m.weight.data, 0.0, 0.02)
elif classname.find('BatchNorm') != -1:
nn.init.normal_(m.weight.data, 1.0, 0.02... | 2,550 | 36.514706 | 116 | py |
ARSaliency | ARSaliency-main/models/VQSal/taming/modules/misc/coord.py | import torch
class CoordStage(object):
def __init__(self, n_embed, down_factor):
self.n_embed = n_embed
self.down_factor = down_factor
def eval(self):
return self
def encode(self, c):
"""fake vqmodel interface"""
assert 0.0 <= c.min() and c.max() <= 1.0
b,c... | 1,012 | 30.65625 | 81 | py |
ARSaliency | ARSaliency-main/models/VQSal/taming/modules/diffusionmodules/model.py | # pytorch_diffusion + derived encoder decoder
import math
import torch
import torch.nn as nn
import numpy as np
def get_timestep_embedding(timesteps, embedding_dim):
"""
This matches the implementation in Denoising Diffusion Probabilistic Models:
From Fairseq.
Build sinusoidal embeddings.
This mat... | 30,221 | 37.895753 | 121 | py |
ARSaliency | ARSaliency-main/models/VQSal/taming/modules/transformer/mingpt.py | """
taken from: https://github.com/karpathy/minGPT/
GPT model:
- the initial stem consists of a combination of token encoding and a positional encoding
- the meat of it is a uniform sequence of Transformer blocks
- each Transformer is a sequential combination of a 1-hidden-layer MLP block and a self-attention block... | 13,577 | 38.586006 | 136 | py |
ARSaliency | ARSaliency-main/models/VQSal/taming/modules/transformer/permuter.py | import torch
import torch.nn as nn
import numpy as np
class AbstractPermuter(nn.Module):
def __init__(self, *args, **kwargs):
super().__init__()
def forward(self, x, reverse=False):
raise NotImplementedError
class Identity(AbstractPermuter):
def __init__(self):
super().__init__()... | 7,093 | 27.48996 | 83 | py |
ARSaliency | ARSaliency-main/models/VQSal/taming/modules/losses/lpips.py | """Stripped version of https://github.com/richzhang/PerceptualSimilarity/tree/master/models"""
import torch
import torch.nn as nn
from torchvision import models
from collections import namedtuple
from taming.util import get_ckpt_path
class LPIPS(nn.Module):
# Learned perceptual metric
def __init__(self, use... | 4,836 | 38.008065 | 104 | py |
ARSaliency | ARSaliency-main/models/VQSal/taming/modules/losses/vqperceptual.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from taming.modules.losses.lpips import LPIPS
from taming.modules.discriminator.model import NLayerDiscriminator, weights_init
class DummyLoss(nn.Module):
def __init__(self):
super().__init__()
def adopt_weight(weight, global_step, thre... | 6,179 | 44.109489 | 113 | py |
ARSaliency | ARSaliency-main/models/VQSal/taming/models/vqgan.py | import torch
import torch.nn.functional as F
import pytorch_lightning as pl
from main import instantiate_from_config
from taming.modules.diffusionmodules.model import Encoder, Decoder, VUNet
from taming.modules.vqvae.quantize import VectorQuantizer
class VQModel(pl.LightningModule):
def __init__(self,
... | 10,504 | 40.196078 | 105 | py |
ARSaliency | ARSaliency-main/models/VQSal/taming/models/cond_transformer.py | import os, math
import torch
import torch.nn.functional as F
import pytorch_lightning as pl
from main import instantiate_from_config
def disabled_train(self, mode=True):
"""Overwrite model.train with this function to make sure train/eval mode
does not change anymore."""
return self
class Net2NetTransfo... | 14,069 | 42.560372 | 127 | py |
ARSaliency | ARSaliency-main/models/VQSal/taming/data/base.py | import bisect
import numpy as np
import albumentations
from PIL import Image
from torch.utils.data import Dataset, ConcatDataset
class ConcatDatasetWithIndex(ConcatDataset):
"""Modified from original pytorch code to return dataset idx"""
def __getitem__(self, idx):
if idx < 0:
if -idx > le... | 2,609 | 35.760563 | 92 | py |
ARSaliency | ARSaliency-main/models/VQSal/taming/data/ade20k.py | import os
import numpy as np
import cv2
import albumentations
from PIL import Image
from torch.utils.data import Dataset
from taming.data.sflckr import SegmentationBase # for examples included in repo
class Examples(SegmentationBase):
def __init__(self, size=256, random_crop=False, interpolation="bicubic"):
... | 5,378 | 42.032 | 107 | py |
ARSaliency | ARSaliency-main/models/VQSal/taming/data/faceshq.py | import os
import numpy as np
import albumentations
from torch.utils.data import Dataset
from taming.data.base import ImagePaths, NumpyPaths, ConcatDatasetWithIndex
class FacesBase(Dataset):
def __init__(self, *args, **kwargs):
super().__init__()
self.data = None
self.keys = None
def ... | 4,640 | 33.377778 | 92 | py |
ARSaliency | ARSaliency-main/models/VQSal/taming/data/sflckr.py | import os
import numpy as np
import cv2
import albumentations
from PIL import Image
from torch.utils.data import Dataset
class SegmentationBase(Dataset):
def __init__(self,
data_csv, data_root, segmentation_root,
size=None, random_crop=False, interpolation="bicubic",
... | 4,097 | 43.543478 | 104 | py |
ARSaliency | ARSaliency-main/models/VQSal/taming/data/imagenet.py | import os, tarfile, glob, shutil
import yaml
import numpy as np
from tqdm import tqdm
from PIL import Image
import albumentations
from omegaconf import OmegaConf
from torch.utils.data import Dataset
from taming.data.base import ImagePaths
from taming.util import download, retrieve
import taming.data.utils as bdu
def... | 20,815 | 36.237925 | 112 | py |
ARSaliency | ARSaliency-main/models/VQSal/taming/data/coco.py | import os
import json
import albumentations
import numpy as np
from PIL import Image
from tqdm import tqdm
from torch.utils.data import Dataset
from taming.data.sflckr import SegmentationBase # for examples included in repo
class Examples(SegmentationBase):
def __init__(self, size=256, random_crop=False, interpo... | 8,121 | 44.887006 | 115 | py |
yolact | yolact-master/yolact.py | import torch, torchvision
import torch.nn as nn
import torch.nn.functional as F
from torchvision.models.resnet import Bottleneck
import numpy as np
from itertools import product
from math import sqrt
from typing import List
from collections import defaultdict
from data.config import cfg, mask_type
from layers import D... | 31,092 | 41.886897 | 137 | py |
yolact | yolact-master/backbone.py | import torch
import torch.nn as nn
import pickle
from collections import OrderedDict
try:
from dcn_v2 import DCN
except ImportError:
def DCN(*args, **kwdargs):
raise Exception('DCN could not be imported. If you want to use YOLACT++ models, compile DCN. Check the README for instructions.')
class Bottl... | 17,286 | 36.580435 | 137 | py |
yolact | yolact-master/eval.py | from data import COCODetection, get_label_map, MEANS, COLORS
from yolact import Yolact
from utils.augmentations import BaseTransform, FastBaseTransform, Resize
from utils.functions import MovingAverage, ProgressBar
from layers.box_utils import jaccard, center_size, mask_iou
from utils import timer
from utils.functions ... | 46,915 | 41.34296 | 159 | py |
yolact | yolact-master/train.py | from data import *
from utils.augmentations import SSDAugmentation, BaseTransform
from utils.functions import MovingAverage, SavePath
from utils.logger import Log
from utils import timer
from layers.modules import MultiBoxLoss
from yolact import Yolact
import os
import sys
import time
import math, random
from pathlib i... | 21,482 | 41.540594 | 196 | py |
yolact | yolact-master/external/DCNv2/test.py | #!/usr/bin/env python
from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
import time
import torch
import torch.nn as nn
from torch.autograd import gradcheck
from dcn_v2 import dcn_v2_conv, DCNv2, DCN
from dcn_v2 import dcn_v2_pooling, DCNv2Pooling, DCNPooling
... | 8,506 | 30.391144 | 81 | py |
yolact | yolact-master/external/DCNv2/setup.py | #!/usr/bin/env python
import os
import glob
import torch
from torch.utils.cpp_extension import CUDA_HOME
from torch.utils.cpp_extension import CppExtension
from torch.utils.cpp_extension import CUDAExtension
from setuptools import find_packages
from setuptools import setup
requirements = ["torch", "torchvision"]
... | 1,978 | 28.537313 | 73 | py |
yolact | yolact-master/external/DCNv2/dcn_v2.py | #!/usr/bin/env python
from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
import math
import torch
from torch import nn
from torch.autograd import Function
from torch.nn.modules.utils import _pair
from torch.autograd.function import once_differentiable
import _... | 12,081 | 38.743421 | 92 | py |
yolact | yolact-master/scripts/convert_darknet.py | from backbone import DarkNetBackbone
import h5py
import torch
f = h5py.File('darknet53.h5', 'r')
m = f['model_weights']
yolo_keys = list(m.keys())
yolo_keys = [x for x in yolo_keys if len(m[x].keys()) > 0]
yolo_keys.sort()
sd = DarkNetBackbone().state_dict()
sd_keys = list(sd.keys())
sd_keys.sort()
# Note this won... | 1,466 | 28.938776 | 93 | py |
yolact | yolact-master/scripts/unpack_statedict.py | import torch
import sys, os
# Usage python scripts/unpack_statedict.py path_to_pth out_folder/
# Make sure to include that slash after your out folder, since I can't
# be arsed to do path concatenation so I'd rather type out this comment
print('Loading state dict...')
state = torch.load(sys.argv[1])
if not os.path.e... | 456 | 25.882353 | 71 | py |
yolact | yolact-master/scripts/optimize_bboxes.py | """
Instead of clustering bbox widths and heights, this script
directly optimizes average IoU across the training set given
the specified number of anchor boxes.
Run this script from the Yolact root directory.
"""
import pickle
import random
from itertools import product
from math import sqrt
import numpy as np
impo... | 6,743 | 31.897561 | 215 | py |
yolact | yolact-master/scripts/compute_masks.py | import numpy as np
import matplotlib.pyplot as plt
import cv2
import torch
import torch.nn.functional as F
COLORS = ((255, 0, 0, 128), (0, 255, 0, 128), (0, 0, 255, 128),
(0, 255, 255, 128), (255, 0, 255, 128), (255, 255, 0, 128))
def mask_iou(mask1, mask2):
"""
Inputs inputs are matricies of size _... | 2,618 | 26.861702 | 97 | py |
yolact | yolact-master/scripts/augment_bbox.py |
import os.path as osp
import json, pickle
import sys
from math import sqrt
from itertools import product
import torch
from numpy import random
import numpy as np
max_image_size = 550
augment_idx = 0
dump_file = 'weights/bboxes_aug.pkl'
box_file = 'weights/bboxes.pkl'
def augment_boxes(bboxes):
bboxes_rel = []
fo... | 3,978 | 22.133721 | 77 | py |
yolact | yolact-master/scripts/bbox_recall.py | """
This script compiles all the bounding boxes in the training data and
clusters them for each convout resolution on which they're used.
Run this script from the Yolact root directory.
"""
import os.path as osp
import json, pickle
import sys
from math import sqrt
from itertools import product
import torch
import ran... | 5,960 | 31.752747 | 117 | py |
yolact | yolact-master/layers/output_utils.py | """ Contains functions used to sanitize and prepare the output of Yolact. """
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import cv2
from data import cfg, mask_type, MEANS, STD, activation_func
from utils.augmentations import Resize
from utils import timer
from .box_utils im... | 6,932 | 35.68254 | 171 | py |
yolact | yolact-master/layers/box_utils.py | # -*- coding: utf-8 -*-
import torch
from utils import timer
from data import cfg
@torch.jit.script
def point_form(boxes):
""" Convert prior_boxes to (xmin, ymin, xmax, ymax)
representation for comparison to point form ground truth data.
Args:
boxes: (tensor) center-size default boxes from priorbo... | 14,952 | 37.341026 | 125 | py |
yolact | yolact-master/layers/interpolate.py | import torch.nn as nn
import torch.nn.functional as F
class InterpolateModule(nn.Module):
"""
This is a module version of F.interpolate (rip nn.Upsampling).
Any arguments you give it just get passed along for the ride.
"""
def __init__(self, *args, **kwdargs):
super().__init__()
self.args = args
self.kwda... | 412 | 21.944444 | 63 | py |
yolact | yolact-master/layers/functions/detection.py | import torch
import torch.nn.functional as F
from ..box_utils import decode, jaccard, index2d
from utils import timer
from data import cfg, mask_type
import numpy as np
class Detect(object):
"""At test time, Detect is the final layer of SSD. Decode location preds,
apply non-maximum suppression to location ... | 8,882 | 37.790393 | 121 | py |
yolact | yolact-master/layers/modules/multibox_loss.py | # -*- coding: utf-8 -*-
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
from ..box_utils import match, log_sum_exp, decode, center_size, crop, elemwise_mask_iou, elemwise_box_iou
from data import cfg, mask_type, activation_func
class MultiBoxLoss(nn.Module):
... | 31,335 | 44.08777 | 164 | py |
yolact | yolact-master/utils/augmentations.py | import torch
from torchvision import transforms
import cv2
import numpy as np
import types
from numpy import random
from math import sqrt
from data import cfg, MEANS, STD
def intersect(box_a, box_b):
max_xy = np.minimum(box_a[:, 2:], box_b[2:])
min_xy = np.maximum(box_a[:, :2], box_b[:2])
inter = np.clip... | 23,931 | 33.734398 | 113 | py |
yolact | yolact-master/utils/functions.py | import torch
import torch.nn as nn
import os
import math
from collections import deque
from pathlib import Path
from layers.interpolate import InterpolateModule
class MovingAverage():
""" Keeps an average window of the specified number of items. """
def __init__(self, max_window_size=1000):
self.max_w... | 6,499 | 29.516432 | 126 | py |
yolact | yolact-master/utils/nvinfo.py | # My version of nvgpu because nvgpu didn't have all the information I was looking for.
import re
import subprocess
import shutil
import os
def gpu_info() -> list:
"""
Returns a dictionary of stats mined from nvidia-smi for each gpu in a list.
Adapted from nvgpu: https://pypi.org/project/nvgpu/, but mine ha... | 2,402 | 37.142857 | 106 | py |
yolact | yolact-master/data/config.py | from backbone import ResNetBackbone, VGGBackbone, ResNetBackboneGN, DarkNetBackbone
from math import sqrt
import torch
# for making bounding boxes pretty
COLORS = ((244, 67, 54),
(233, 30, 99),
(156, 39, 176),
(103, 58, 183),
( 63, 81, 181),
( 33, 150, 243),
... | 31,172 | 36.694075 | 140 | py |
yolact | yolact-master/data/__init__.py | from .config import *
from .coco import *
import torch
import cv2
import numpy as np
| 86 | 11.428571 | 21 | py |
yolact | yolact-master/data/coco.py | import os
import os.path as osp
import sys
import torch
import torch.utils.data as data
import torch.nn.functional as F
import cv2
import numpy as np
from .config import cfg
from pycocotools import mask as maskUtils
import random
def get_label_map():
if cfg.dataset.label_map is None:
return {x+1: x+1 for x... | 10,858 | 37.101754 | 122 | py |
calibrated-backprojection-network | calibrated-backprojection-network-master/src/kbnet_model.py | '''
Author: Alex Wong <alexw@cs.ucla.edu>
If you use this code, please cite the following paper:
A. Wong, and S. Soatto. Unsupervised Depth Completion with Calibrated Backprojection Layers.
https://arxiv.org/pdf/2108.10531.pdf
@inproceedings{wong2021unsupervised,
title={Unsupervised Depth Completion with Calibrate... | 24,527 | 36.677419 | 108 | py |
calibrated-backprojection-network | calibrated-backprojection-network-master/src/losses.py | '''
Author: Alex Wong <alexw@cs.ucla.edu>
If you use this code, please cite the following paper:
A. Wong, and S. Soatto. Unsupervised Depth Completion with Calibrated Backprojection Layers.
https://arxiv.org/pdf/2108.10531.pdf
@inproceedings{wong2021unsupervised,
title={Unsupervised Depth Completion with Calibrate... | 4,557 | 27.666667 | 92 | py |
calibrated-backprojection-network | calibrated-backprojection-network-master/src/kbnet.py | '''
Author: Alex Wong <alexw@cs.ucla.edu>
If you use this code, please cite the following paper:
A. Wong, and S. Soatto. Unsupervised Depth Completion with Calibrated Backprojection Layers.
https://arxiv.org/pdf/2108.10531.pdf
@inproceedings{wong2021unsupervised,
title={Unsupervised Depth Completion with Calibrate... | 49,481 | 37.151118 | 119 | py |
calibrated-backprojection-network | calibrated-backprojection-network-master/src/train_kbnet.py | '''
Author: Alex Wong <alexw@cs.ucla.edu>
If you use this code, please cite the following paper:
A. Wong, and S. Soatto. Unsupervised Depth Completion with Calibrated Backprojection Layers.
https://arxiv.org/pdf/2108.10531.pdf
@inproceedings{wong2021unsupervised,
title={Unsupervised Depth Completion with Calibrate... | 14,149 | 55.827309 | 221 | py |
calibrated-backprojection-network | calibrated-backprojection-network-master/src/networks.py | '''
Author: Alex Wong <alexw@cs.ucla.edu>
If you use this code, please cite the following paper:
A. Wong, and S. Soatto. Unsupervised Depth Completion with Calibrated Backprojection Layers.
https://arxiv.org/pdf/2108.10531.pdf
@inproceedings{wong2021unsupervised,
title={Unsupervised Depth Completion with Calibrate... | 79,040 | 34.976787 | 108 | py |
calibrated-backprojection-network | calibrated-backprojection-network-master/src/datasets.py | '''
Author: Alex Wong <alexw@cs.ucla.edu>
If you use this code, please cite the following paper:
A. Wong, and S. Soatto. Unsupervised Depth Completion with Calibrated Backprojection Layers.
https://arxiv.org/pdf/2108.10531.pdf
@inproceedings{wong2021unsupervised,
title={Unsupervised Depth Completion with Calibrate... | 8,420 | 28.341463 | 92 | py |
calibrated-backprojection-network | calibrated-backprojection-network-master/src/log_utils.py | '''
Author: Alex Wong <alexw@cs.ucla.edu>
If you use this code, please cite the following paper:
A. Wong, and S. Soatto. Unsupervised Depth Completion with Calibrated Backprojection Layers.
https://arxiv.org/pdf/2108.10531.pdf
@inproceedings{wong2021unsupervised,
title={Unsupervised Depth Completion with Calibrate... | 2,037 | 25.815789 | 92 | py |
calibrated-backprojection-network | calibrated-backprojection-network-master/src/posenet_model.py | '''
Author: Alex Wong <alexw@cs.ucla.edu>
If you use this code, please cite the following paper:
A. Wong, and S. Soatto. Unsupervised Depth Completion with Calibrated Backprojection Layers.
https://arxiv.org/pdf/2108.10531.pdf
@inproceedings{wong2021unsupervised,
title={Unsupervised Depth Completion with Calibrate... | 6,479 | 30.304348 | 92 | py |
calibrated-backprojection-network | calibrated-backprojection-network-master/src/net_utils.py | '''
Author: Alex Wong <alexw@cs.ucla.edu>
If you use this code, please cite the following paper:
A. Wong, and S. Soatto. Unsupervised Depth Completion with Calibrated Backprojection Layers.
https://arxiv.org/pdf/2108.10531.pdf
@inproceedings{wong2021unsupervised,
title={Unsupervised Depth Completion with Calibrate... | 57,688 | 30.925291 | 103 | py |
calibrated-backprojection-network | calibrated-backprojection-network-master/src/transforms.py | '''
Author: Alex Wong <alexw@cs.ucla.edu>
If you use this code, please cite the following paper:
A. Wong, and S. Soatto. Unsupervised Depth Completion with Calibrated Backprojection Layers.
https://arxiv.org/pdf/2108.10531.pdf
@inproceedings{wong2021unsupervised,
title={Unsupervised Depth Completion with Calibrate... | 11,870 | 31.975 | 96 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/codec/torch_codec.py | import torch
import numpy as np
from .neighbors import OneNN_Torch
def codec2(Z, Y):
# Y ind Z
if len(Z.shape)==1:
Z = Z.reshape(-1,1)
if len(Y.shape)==2:
if Y.shape[1] ==1:
Y = Y.squeeze()
else:
print(Y.shape)
error("Cannot handle multidimensional Y.")
n, q = Z.shape... | 2,359 | 20.851852 | 67 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/codec/codec_compare.py | import numpy as np
import time
import torch
import random
from codec import codec2 as scikit_codec2
from codec import codec3 as scikit_codec3
from torch_codec import codec2 as torch_codec2
from torch_codec import codec3 as torch_codec3
seed = 12345
print("Setting seeds to: ", seed)
np.random.seed(seed)
random.seed(s... | 1,793 | 25.776119 | 70 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/codec/torch_foci.py | import numpy as np
import torch
from .torch_codec import codec2, codec3
# for testing
from .foci import foci as sci_foci
# feature ordering
def foci(X, Y, earlyStop=True, verbose=False):
p = X.shape[1]
indeps = np.empty((p,1))
maxval = -100
maxind = None
for i in range(p):
tmp = codec2(X... | 3,486 | 20.658385 | 79 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/codec/neighbors.py | import torch
import numpy as np
from sklearn.neighbors import NearestNeighbors
def OneNN_Torch(X, p=2):
'''
Compute pairwise p-norm distance and gets
elements with closest distance.
'''
# number of samples is first dimension
# feature space size is second dimension
n, d = X.shape
... | 2,202 | 22.945652 | 81 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/codec/__init__.py | from codec.codec import *
from codec.foci import *
from codec.torch_codec import codec2 as torch_codec2
from codec.torch_codec import codec3 as torch_codec3
from codec.torch_foci import foci as torch_foci
from codec.torch_foci import cheap_foci as cheap_torch_foci
| 265 | 37 | 59 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/kfac_scrub.py | # KFAC tutorial: https://towardsdatascience.com/introducing-k-fac-and-its-application-for-large-scale-deep-learning-4e3f9b443414
# KFAC tutorial: https://yaroslavvb.medium.com/optimizing-deeper-networks-with-kfac-in-pytorch-4004adcba1b0
# KFAC main code: https://github.com/cybertronai/autograd-lib
import argparse
imp... | 16,909 | 43.036458 | 215 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/multi_scrub.py | import argparse
import copy
import numpy as np
import pandas as pd
import os
import torch
from torch.utils.data import DataLoader, Subset
from tqdm import tqdm
import time
from data_utils import getDatasets
from nn_utils import do_epoch, manual_seed
from scrub_tools import scrubSample, inp_perturb
device = torch.d... | 10,360 | 44.442982 | 215 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/data_utils.py | # Copyright 2017-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" fil... | 6,132 | 33.846591 | 122 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/dataset.py | from __future__ import print_function
import os
import os.path
import numpy as np
import pandas as pd
import sys
from scipy import ndimage as nd
import torch
import torch.utils.data as data
from PIL import Image
import glob
class OurCelebA(data.Dataset):
"""
Args:
root (string): Root directory of datas... | 5,850 | 30.627027 | 150 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/reid_viz.py | import numpy as np
import os.path as osp
import argparse
import cv2
import torch
from torch.nn import functional as F
import pdb
import torchreid
from torchreid.utils import (
check_isfile, mkdir_if_missing, load_pretrained_weights
)
IMAGENET_MEAN = [0.485, 0.456, 0.406]
IMAGENET_STD = [0.229, 0.224, 0.225]
GRID_... | 4,939 | 34.539568 | 92 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/grad_utils.py | import torch
def getGradObjs(model):
grad_objs = {}
param_objs = {}
for module in model.modules():
#for module in model.modules():
for (name, param) in module.named_parameters():
grad_objs[(str(module), name)] = param.grad
param_objs[(str(module), name)] = param.data
... | 2,977 | 30.347368 | 103 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/scrub_tools.py | import argparse
import random
import copy
import numpy as np
import pandas as pd
import os
import torch
from torch.nn.utils import parameters_to_vector as p2v
from torch.nn.utils import vector_to_parameters as v2p
from torch.utils.data import DataLoader
from torch.utils.data import Subset
from torch.utils.data.sampler ... | 24,925 | 34.710602 | 164 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/example_hessian.py | import torch
from torch import nn
import pdb
from autograd_lib import autograd_lib
from collections import defaultdict
from attrdict import AttrDefault
from autograd_lib import util as u
from autograd_lib import autograd_lib
from data_utils import getDatasets
def simple_model(d, num_layers):
"""Creates simple l... | 3,430 | 25.596899 | 80 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/retrain_scrub.py | import pdb
import argparse
import copy
import numpy as np
import pandas as pd
import os
import torch
from torch.utils.data import DataLoader, Subset
from tqdm import tqdm
import time
from data_utils import getDatasets
from nn_utils import do_epoch, manual_seed, retrain_model
from scrub_tools import scrubSample, inp... | 12,321 | 47.511811 | 277 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/reid_scrub.py | import torchreid
import pdb
import random
import argparse
import torch
import torch.nn as nn
from torch.utils.data import (
DataLoader,
RandomSampler,
SequentialSampler,
)
from tqdm import tqdm, trange
import numpy as np
import copy
import pandas as pd
import os
import sys
from torch.utils.data import... | 13,058 | 36.418338 | 203 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/hypercolumn.py | import torch
import torch.nn as nn
import torch.nn.functional as F
class NLP_ActivationsHook(nn.Module):
def __init__(self, model):
super(NLP_ActivationsHook, self).__init__()
self.model = model
self.model.eval()
self.layers = []
self.activations = []
self.hooks = ... | 3,702 | 28.15748 | 148 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/reid.py | import torchreid
import pdb
datamanager = torchreid.data.ImageDataManager(
root='reid-data',
sources='msmt17',
targets='msmt17',
height=256,
width=128,
batch_size_train=128,
batch_size_test=100,
transforms=['random_flip', 'random_crop'],
combineall=True
)
model = torchreid.models.... | 991 | 17.036364 | 47 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/autograd_lib_test.py | from collections import defaultdict
import torch
import sys
from attrdict import AttrDefault
from autograd_lib import autograd_lib
from autograd_lib import util as u
def create_toy_model():
"""
Create model from https://www.wolframcloud.com/obj/yaroslavvb/newton/linear-jacobians-and-hessians.nb
PyTorch ... | 9,703 | 32.006803 | 105 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/example_norms.py | import torch
from torch import nn
from autograd_lib import autograd_lib
from collections import defaultdict
from attrdict import AttrDefault
def simple_model(d, num_layers):
"""Creates simple linear neural network initialized to identity"""
layers = []
for i in range(num_layers):
layer = nn.Linea... | 1,394 | 24.833333 | 70 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/vgg_scrub.py | import argparse
import copy
import numpy as np
import pandas as pd
import os
import torch
from torch.utils.data import DataLoader, Subset
from tqdm import tqdm
import time
from data_utils import getDatasets
from nn_utils import do_epoch, manual_seed
from sklearn.metrics import classification_report
from vgg_scrub_... | 9,196 | 44.985 | 201 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/scrub.py | import argparse
import copy
import numpy as np
import pandas as pd
import os
import torch
from torch.utils.data import DataLoader
from tqdm import tqdm
from data_utils import getDatasets
from nn_utils import do_epoch
from scrub_tools import scrubSample, inp_perturb
device = torch.device('cuda' if torch.cuda.is_avai... | 5,973 | 46.792 | 168 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/ledgar_scrub.py | # Code modified from https://github.com/dtuggener/LEDGAR_provision_classification/
import random
import argparse
import torch
import torch.nn as nn
from torch.utils.data import (
DataLoader,
RandomSampler,
SequentialSampler,
)
from pytorch_transformers import (
DistilBertConfig,
DistilBertTokeniz... | 26,326 | 35.718271 | 203 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/train.py | import argparse
import numpy as np
from tqdm import tqdm
import torch
import torchvision
from torch.utils.data import DataLoader
from torch.utils.data.sampler import SubsetRandomSampler
from torch.utils.data import Subset
from data_utils import getDatasets
from nn_utils import do_epoch
from grad_utils import getGrad... | 5,031 | 46.471698 | 283 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/ledgar_utils.py | # Code modified from https://github.com/dtuggener/LEDGAR_provision_classification/
import itertools
import json
import numpy as np
import re
import torch
from torch.utils.data import TensorDataset
from typing import List, Union, Dict, DefaultDict, Tuple
from collections import defaultdict
from sklearn.model_selectio... | 10,516 | 36.162544 | 116 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/VGGFaceDataset.py | from __future__ import print_function
import os
import os.path
import numpy as np
import pandas as pd
import sys
from scipy import ndimage as nd
import torch
import torch.utils.data as data
from PIL import Image
def getVGGClassLabelFromName(person='Aamir_Khan', dataroot='./data/vggface/', namefile='names.txt'):
al... | 4,446 | 31.224638 | 126 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/vgg_scrub_tools.py | import argparse
import random
import copy
import numpy as np
import pandas as pd
import os
import torch
from torch.nn.utils import parameters_to_vector as p2v
from torch.nn.utils import vector_to_parameters as v2p
from torch.utils.data import DataLoader
from torch.utils.data import Subset
from torch.utils.data.sampler ... | 13,673 | 37.846591 | 172 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/nn_utils.py | import torch
import numpy as np
import random
from tqdm import tqdm
from grad_utils import getGradObjs, gradNorm
def do_epoch(model, dataloader, criterion, epoch, nepochs, optim=None, device='cpu', outString='', compute_grads=False, retrain=False):
# saves last two epochs gradients for computing finite differenc... | 4,444 | 36.991453 | 176 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/models/vggface/vgg_face.py | # -*- coding: utf-8 -*-
__author__ = "Pau Rodríguez López, ISELAB, CVC-UAB"
__email__ = "pau.rodri1@gmail.com"
import numpy as np
from PIL import Image
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchfile
class VGG_16(nn.Module):
"""
Main Class
"""
def __init__(self, l... | 4,255 | 34.173554 | 108 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/models/imagenet/resnext.py | from __future__ import division
"""
Creates a ResNeXt Model as defined in:
Xie, S., Girshick, R., Dollar, P., Tu, Z., & He, K. (2016).
Aggregated residual transformations for deep neural networks.
arXiv preprint arXiv:1611.05431.
import from https://github.com/facebookresearch/ResNeXt/blob/master/models/resnext.lua
... | 5,698 | 31.752874 | 105 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/models/mnist/fcs.py | import torch.nn as nn
class LogisticRegressor(nn.Module):
def __init__(self, input_size=784, num_classes=10):
super(LogisticRegressor, self).__init__()
self.input_size = input_size
self.linear = nn.Linear(input_size, num_classes, bias=True)
def forward(self, x):
x = x.view(-1,... | 898 | 28 | 67 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/models/mrleye/simple.py | from torch import nn
import torch.nn.functional as F
import torch
class MRLEYE_CNN(nn.Module):
"""CNN."""
def __init__(self, n_classes=23):
"""CNN Builder."""
super(MRLEYE_CNN, self).__init__()
self.conv_layer = nn.Sequential(
# Conv Layer block 1
nn.Conv2d(in... | 2,018 | 28.691176 | 83 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/models/cifar/preresnet.py | from __future__ import absolute_import
'''Resnet for cifar dataset.
Ported form
https://github.com/facebook/fb.resnet.torch
and
https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py
(c) YANG, Wei
'''
import torch.nn as nn
import math
__all__ = ['preresnet']
def conv3x3(in_planes, out_planes, st... | 5,110 | 29.789157 | 116 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/models/cifar/resnet.py | import torch
def resnet18(**kwargs):
model = torch.hub.load('pytorch/vision:v0.10.0', 'resnet18', pretrained=False, num_classes=10)
return model
def resnet50(**kwargs):
model = torch.hub.load('pytorch/vision:v0.10.0', 'resnet50', pretrained=False, num_classes=10)
return model
| 295 | 28.6 | 98 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/models/cifar/vgg.py | import torch
def vgg11(**kwargs):
"""VGG 11-layer model (configuration "A")
Args:
pretrained (bool): If True, returns a model pre-trained on ImageNet
"""
#model = VGG(make_layers(cfg['A']), num_classes=10, **kwargs)
model = torch.hub.load('pytorch/vision:v0.10.0', 'vgg11', pretrained=False... | 1,928 | 26.956522 | 98 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/models/cifar/simple.py | from torch import nn
import torch.nn.functional as F
import torch
class CIFAR10Logistic2NN(nn.Module):
def __init__(self, input_size=32*32*3, num_classes=10):
super(CIFAR10Logistic2NN, self).__init__()
self.input_size = input_size
self.linear1 = nn.Linear(input_size, 100, bias=True)
... | 4,318 | 29.415493 | 83 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/models/cifar/densenet.py | import torch
def densenet(**kwargs):
model = torch.hub.load('pytorch/vision:v0.10.0', 'densenet121', pretrained=False, num_classes=10)
return model
| 157 | 25.333333 | 101 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/models/cifar/mobilenetCIFAR.py | '''MobileNetV2 in PyTorch.
See the paper "Inverted Residuals and Linear Bottlenecks:
Mobile Networks for Classification, Detection and Segmentation" for more details.
'''
import torch
import torch.nn as nn
import torch.nn.functional as F
def mobilenet(**kwargs):
model = torch.hub.load('pytorch/vision:v0.10.0', 'm... | 3,237 | 34.977778 | 114 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/models/cifar/resnext.py | import torch
def resnext(**kwargs):
"""Constructs a ResNeXt.
"""
#model = CifarResNeXt(**kwargs)
model = torch.hub.load('pytorch/vision:v0.10.0', 'densenet121', pretrained=False)#, num_classes=10)
#model = torch.hub.load('pytorch/vision:v0.10.0', 'resnext50_32x4d', pretrained=False)#, num_classes=1... | 341 | 30.090909 | 108 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/models/cifar/__init__.py | from __future__ import absolute_import
"""The models subpackage contains definitions for the following model for CIFAR10/CIFAR100
architectures:
- `AlexNet`_
- `VGG`_
- `ResNet`_
- `SqueezeNet`_
- `DenseNet`_
You can construct a model with random weights by calling its constructor:
.. code:: python
import... | 2,302 | 30.547945 | 90 | py |
LCODEC-deep-unlearning | LCODEC-deep-unlearning-main/scrub/models/cifar/alexnet.py | import torch
def alexnet(**kwargs):
model = torch.hub.load('pytorch/vision:v0.10.0', 'alexnet', pretrained=False, num_classes=10)
return model
| 152 | 24.5 | 97 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.