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 |
|---|---|---|---|---|---|---|
UAL-CVPR2020 | UAL-CVPR2020-master/LoadDataset_Batch.py | import torch
import numpy as np
import torch.utils.data as data
import scipy.io as sio
from scipy.misc import imresize
import copy
from Spa_downs import *
names_CAVE = [
'balloons_ms','thread_spools_ms', 'fake_and_real_food_ms', 'face_ms','feathers_ms', 'cd_ms', 'real_and_fake_peppers_ms',
'stuffed_toys_ms', ... | 5,140 | 37.654135 | 135 | py |
UAL-CVPR2020 | UAL-CVPR2020-master/Train_FusionModel.py | import torch
import numpy as np
import scipy.io as sio
from Spa_downs import *
from LoadDataset_Batch import *
from torch.utils.data import DataLoader
from torch.autograd import Variable
import time
import os
import matplotlib.pyplot as plt
from torch.nn.functional import upsample
from ThreeBranch_3 import *
lr = 1e... | 3,351 | 26.702479 | 173 | py |
UAL-CVPR2020 | UAL-CVPR2020-master/PY_Evalue/SSIM.py | import torch
import torch.nn.functional as F
from torch.autograd import Variable
import numpy as np
from math import exp
def gaussian(window_size, sigma):
gauss = torch.Tensor([exp(-(x - window_size//2)**2/float(2*sigma**2)) for x in range(window_size)])
return gauss/gauss.sum()
def create_window(window_size,... | 2,639 | 34.675676 | 104 | py |
UAL-CVPR2020 | UAL-CVPR2020-master/PY_Evalue/Result_Evaluate.py | from function import *
from SSIM import *
import numpy as np
import scipy.io as sio
import torch
import os
import h5py
import matplotlib.pyplot as plt
CAVE_TestSet = [
'real_and_fake_apples', 'superballs', 'chart_and_stuffed_toy', 'hairs', 'fake_and_real_lemons',
'fake_and_real_lemon_slices', 'fake_and_real_s... | 1,618 | 26.440678 | 168 | py |
UAL-CVPR2020 | UAL-CVPR2020-master/PY_Evalue/function.py | import torch
import torch.nn as nn
import numpy as np
class ReshapeTo2D(nn.Module):
def __init__(self):
super(ReshapeTo2D, self).__init__()
def forward(self,x):
return torch.reshape(x, (x.shape[0], x.shape[1], x.shape[2]*x.shape[3]))
class ReshapeTo3D(nn.Module):
def __init__(self):
... | 3,331 | 27.478632 | 110 | py |
RAD | RAD-main/base.py | # Get Python six functionality:
from __future__ import\
absolute_import, print_function, division, unicode_literals
from builtins import zip
import six
###############################################################################
###############################################################################
###... | 32,693 | 38.437877 | 84 | py |
RAD | RAD-main/test.py | import os
import cv2
import json
import time
import shutil
import argparse
import numpy as np
import PIL.Image
from copy import deepcopy
import mmcv
from mmdet.apis import init_detector, inference_detector, show_result
# install mmdet v1 in https://github.com/open-mmlab/mmdetection
# download correspongding pretrained... | 8,596 | 48.982558 | 195 | py |
RAD | RAD-main/retinanet_base.py | """rewrite from https://github.com/fizyr/keras-retinanet"""
import argparse
import os
os.environ['HDF5_DISABLE_VERSION_CHECK'] = '1'
import sys
import warnings
import numpy as np
import PIL.Image
import keras
import keras.preprocessing.image
import tensorflow as tf
# Allow relative imports when being executed as sc... | 11,186 | 48.5 | 1,193 | py |
RAD | RAD-main/interpreters.py | """rewrite from https://github.com/uchidalab/softmaxgradient-lrp"""
"""enable attention gradient in tensorflow and Multi-Node SGLRP if specify multi=True"""
""" !!! need to modify source code in innvestigate to run"""
import numpy as np
from keras import backend as K
from innvestigate.analyzer import BoundedDeepTaylor... | 12,378 | 34.067989 | 204 | py |
RAD | RAD-main/deeptaylor.py | # Get Python six functionality:
from __future__ import\
absolute_import, print_function, division, unicode_literals
###############################################################################
###############################################################################
######################################... | 7,491 | 34.339623 | 130 | py |
RAD | RAD-main/utils.py | import os
import cv2
import time
import json
import shutil
import argparse
import PIL.Image
import numpy as np
import tensorflow as tf
from copy import deepcopy
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from keras.utils.np_utils import to_categorical
from keras import backend as K
from in... | 8,121 | 38.048077 | 155 | py |
RAD | RAD-main/yolov3_base.py | """rewrite from https://github.com/qqwweee/keras-yolo3"""
"""modified from yolo.py"""
import os
import numpy as np
import colorsys
from timeit import default_timer as timer
from PIL import Image, ImageFont, ImageDraw
from keras import backend as K
from keras.layers import Input
from keras.utils import multi_gpu_mode... | 33,627 | 39.564536 | 130 | py |
RAD | RAD-main/retinanet.py | from rad import *
from retinanet_base import load_net, read_image, detect_image
class RetinaNet(Model):
def __init__(self, model_attack, model_detect):
super().__init__(model_attack, model_detect, 'RetinaNet')
self.low = - np.array([103.939, 116.779, 123.68])
self.high = 255 + self.low
... | 2,033 | 42.276596 | 123 | py |
RAD | RAD-main/train.py | """
Retrain the YOLO model for your own dataset.
"""
import os
import numpy as np
import time
import keras.backend as K
from keras.layers import Input, Lambda
from keras.models import Model
from keras.optimizers import Adam
from keras.callbacks import TensorBoard, ModelCheckpoint, ReduceLROnPlateau, EarlyStopping
from ... | 10,860 | 46.845815 | 323 | py |
RAD | RAD-main/yolov3.py |
from rad import *
from yolov3_base import YOLO
class YOLOv3(Model):
def __init__(self, model_attack, model_detect):
super().__init__(model_attack, model_detect, 'YOLOv3')
def preprocess_image(self, image_path):
image, self.val_image, self.resized = self.model_detect.preprocess_image(PIL.... | 1,898 | 42.159091 | 141 | py |
RAD | RAD-main/configs/faster_rcnn_r50_fpn_1x.py | # model settings
model = dict(
type='FasterRCNN',
pretrained='torchvision://resnet50',
backbone=dict(
type='ResNet',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
type='FPN',
in_channels=[25... | 5,373 | 29.534091 | 78 | py |
RAD | RAD-main/configs/cascade_rcnn_r50_caffe_c4_1x.py | # model settings
norm_cfg = dict(type='BN', requires_grad=False)
model = dict(
type='CascadeRCNN',
num_stages=3,
pretrained='open-mmlab://resnet50_caffe',
backbone=dict(
type='ResNet',
depth=50,
num_stages=3,
strides=(1, 2, 2),
dilations=(1, 1, 1),
out_ind... | 7,590 | 30.110656 | 78 | py |
RAD | RAD-main/configs/retinanet_r101_fpn_1x.py | # model settings
model = dict(
type='RetinaNet',
pretrained='torchvision://resnet101',
backbone=dict(
type='ResNet',
depth=101,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
type='FPN',
in_channels=[2... | 3,847 | 28.374046 | 77 | py |
RAD | RAD-main/configs/fast_mask_rcnn_r50_fpn_1x.py | # model settings
model = dict(
type='FastRCNN',
pretrained='torchvision://resnet50',
backbone=dict(
type='ResNet',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
type='FPN',
in_channels=[256,... | 4,956 | 30.980645 | 77 | py |
RAD | RAD-main/configs/faster_rcnn_x101_32x4d_fpn_1x.py | # model settings
model = dict(
type='FasterRCNN',
pretrained='open-mmlab://resnext101_32x4d',
backbone=dict(
type='ResNeXt',
depth=101,
groups=32,
base_width=4,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck... | 5,430 | 29.511236 | 78 | py |
RAD | RAD-main/configs/cascade_rcnn_x101_32x4d_fpn_1x.py | # model settings
model = dict(
type='CascadeRCNN',
num_stages=3,
pretrained='open-mmlab://resnext101_32x4d',
backbone=dict(
type='ResNeXt',
depth=101,
groups=32,
base_width=4,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='... | 7,452 | 30.447257 | 78 | py |
RAD | RAD-main/configs/faster_rcnn_x101_64x4d_fpn_1x.py | # model settings
model = dict(
type='FasterRCNN',
pretrained='open-mmlab://resnext101_64x4d',
backbone=dict(
type='ResNeXt',
depth=101,
groups=64,
base_width=4,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck... | 5,430 | 29.511236 | 78 | py |
RAD | RAD-main/configs/mask_rcnn_r101_fpn_1x.py | # model settings
model = dict(
type='MaskRCNN',
pretrained='torchvision://resnet101',
backbone=dict(
type='ResNet',
depth=101,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
type='FPN',
in_channels=[25... | 5,802 | 29.542105 | 78 | py |
RAD | RAD-main/configs/mask_rcnn_r50_caffe_c4_1x.py | # model settings
norm_cfg = dict(type='BN', requires_grad=False)
model = dict(
type='MaskRCNN',
# pretrained='open-mmlab://resnet50_caffe',
backbone=dict(
type='ResNet',
depth=50,
num_stages=3,
strides=(1, 2, 2),
dilations=(1, 1, 1),
out_indices=(2, ),
... | 5,822 | 29.015464 | 78 | py |
RAD | RAD-main/configs/faster_rcnn_r50_caffe_c4_1x.py | # model settings
norm_cfg = dict(type='BN', requires_grad=False)
model = dict(
type='FasterRCNN',
pretrained='open-mmlab://resnet50_caffe',
backbone=dict(
type='ResNet',
depth=50,
num_stages=3,
strides=(1, 2, 2),
dilations=(1, 1, 1),
out_indices=(2, ),
... | 5,445 | 29.088398 | 78 | py |
RAD | RAD-main/configs/retinanet_x101_32x4d_fpn_1x.py | # model settings
model = dict(
type='RetinaNet',
pretrained='open-mmlab://resnext101_32x4d',
backbone=dict(
type='ResNeXt',
depth=101,
groups=32,
base_width=4,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=... | 3,901 | 28.338346 | 77 | py |
RAD | RAD-main/configs/fast_mask_rcnn_r101_fpn_1x.py | # model settings
model = dict(
type='FastRCNN',
pretrained='torchvision://resnet101',
backbone=dict(
type='ResNet',
depth=101,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
type='FPN',
in_channels=[25... | 4,959 | 31 | 77 | py |
RAD | RAD-main/configs/rpn_x101_32x4d_fpn_1x.py | # model settings
model = dict(
type='RPN',
pretrained='open-mmlab://resnext101_32x4d',
backbone=dict(
type='ResNeXt',
depth=101,
groups=32,
base_width=4,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
... | 3,978 | 28.917293 | 78 | py |
RAD | RAD-main/configs/faster_rcnn_ohem_r50_fpn_1x.py | # model settings
model = dict(
type='FasterRCNN',
pretrained='torchvision://resnet50',
backbone=dict(
type='ResNet',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
type='FPN',
in_channels=[25... | 5,371 | 29.522727 | 78 | py |
RAD | RAD-main/configs/mask_rcnn_r50_fpn_1x.py | # model settings
model = dict(
type='MaskRCNN',
pretrained='torchvision://resnet50',
backbone=dict(
type='ResNet',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
type='FPN',
in_channels=[256,... | 5,799 | 29.526316 | 78 | py |
RAD | RAD-main/configs/ssd512_coco.py | # model settings
input_size = 512
model = dict(
type='SingleStageDetector',
pretrained='open-mmlab://vgg16_caffe',
backbone=dict(
type='SSDVGG',
input_size=input_size,
depth=16,
with_last_pool=False,
ceil_mode=True,
out_indices=(3, 4),
out_feature_indi... | 4,004 | 28.448529 | 79 | py |
RAD | RAD-main/configs/faster_rcnn_r101_fpn_1x.py | # model settings
model = dict(
type='FasterRCNN',
pretrained='torchvision://resnet101',
backbone=dict(
type='ResNet',
depth=101,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
type='FPN',
in_channels=[... | 5,376 | 29.551136 | 78 | py |
RAD | RAD-main/configs/mask_rcnn_x101_64x4d_fpn_1x.py | # model settings
model = dict(
type='MaskRCNN',
pretrained='open-mmlab://resnext101_64x4d',
backbone=dict(
type='ResNeXt',
depth=101,
groups=64,
base_width=4,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=d... | 5,856 | 29.505208 | 78 | py |
RAD | RAD-main/configs/cascade_rcnn_r50_fpn_1x.py | # model settings
model = dict(
type='CascadeRCNN',
num_stages=3,
pretrained='torchvision://resnet50',
backbone=dict(
type='ResNet',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
type='FPN',
... | 7,395 | 30.47234 | 78 | py |
RAD | RAD-main/configs/cascade_mask_rcnn_x101_32x4d_fpn_1x.py | # model settings
model = dict(
type='CascadeRCNN',
num_stages=3,
pretrained='open-mmlab://resnext101_32x4d',
backbone=dict(
type='ResNeXt',
depth=101,
groups=32,
base_width=4,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='... | 8,061 | 30.492188 | 78 | py |
RAD | RAD-main/configs/rpn_x101_64x4d_fpn_1x.py | # model settings
model = dict(
type='RPN',
pretrained='open-mmlab://resnext101_64x4d',
backbone=dict(
type='ResNeXt',
depth=101,
groups=64,
base_width=4,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
... | 3,978 | 28.917293 | 78 | py |
RAD | RAD-main/configs/fast_rcnn_r101_fpn_1x.py | # model settings
model = dict(
type='FastRCNN',
pretrained='torchvision://resnet101',
backbone=dict(
type='ResNet',
depth=101,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
type='FPN',
in_channels=[25... | 4,389 | 31.279412 | 78 | py |
RAD | RAD-main/configs/rpn_r50_fpn_1x.py | # model settings
model = dict(
type='RPN',
pretrained='torchvision://resnet50',
backbone=dict(
type='ResNet',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
type='FPN',
in_channels=[256, 512,... | 3,921 | 28.938931 | 78 | py |
RAD | RAD-main/configs/retinanet_r50_fpn_1x.py | # model settings
model = dict(
type='RetinaNet',
pretrained='torchvision://resnet50',
backbone=dict(
type='ResNet',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
type='FPN',
in_channels=[256... | 3,844 | 28.351145 | 77 | py |
RAD | RAD-main/configs/retinanet_x101_64x4d_fpn_1x.py | # model settings
model = dict(
type='RetinaNet',
pretrained='open-mmlab://resnext101_64x4d',
backbone=dict(
type='ResNeXt',
depth=101,
groups=64,
base_width=4,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=... | 3,901 | 28.338346 | 77 | py |
RAD | RAD-main/configs/fast_rcnn_r50_fpn_1x.py | # model settings
model = dict(
type='FastRCNN',
pretrained='torchvision://resnet50',
backbone=dict(
type='ResNet',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
type='FPN',
in_channels=[256,... | 4,386 | 31.257353 | 78 | py |
RAD | RAD-main/configs/cascade_mask_rcnn_r50_fpn_1x.py | # model settings
model = dict(
type='CascadeRCNN',
num_stages=3,
pretrained='torchvision://resnet50',
backbone=dict(
type='ResNet',
depth=50,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
type='FPN',
... | 8,004 | 30.515748 | 78 | py |
RAD | RAD-main/configs/rpn_r50_caffe_c4_1x.py | # model settings
model = dict(
type='RPN',
pretrained='open-mmlab://resnet50_caffe',
backbone=dict(
type='ResNet',
depth=50,
num_stages=3,
strides=(1, 2, 2),
dilations=(1, 1, 1),
out_indices=(2, ),
frozen_stages=1,
norm_cfg=dict(type='BN', requ... | 3,947 | 29.137405 | 78 | py |
RAD | RAD-main/configs/cascade_rcnn_x101_64x4d_fpn_1x.py | # model settings
model = dict(
type='CascadeRCNN',
num_stages=3,
pretrained='open-mmlab://resnext101_64x4d',
backbone=dict(
type='ResNeXt',
depth=101,
groups=64,
base_width=4,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='... | 7,452 | 30.447257 | 78 | py |
RAD | RAD-main/configs/fast_mask_rcnn_r50_caffe_c4_1x.py | # model settings
norm_cfg = dict(type='BN', requires_grad=False)
model = dict(
type='FastRCNN',
pretrained='open-mmlab://resnet50_caffe',
backbone=dict(
type='ResNet',
depth=50,
num_stages=3,
strides=(1, 2, 2),
dilations=(1, 1, 1),
out_indices=(2, ),
f... | 4,708 | 29.577922 | 75 | py |
RAD | RAD-main/configs/cascade_mask_rcnn_x101_64x4d_fpn_1x.py | # model settings
model = dict(
type='CascadeRCNN',
num_stages=3,
pretrained='open-mmlab://resnext101_64x4d',
backbone=dict(
type='ResNeXt',
depth=101,
groups=64,
base_width=4,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='... | 8,061 | 30.492188 | 78 | py |
RAD | RAD-main/configs/ssd300_coco.py | # model settings
input_size = 300
model = dict(
type='SingleStageDetector',
pretrained='open-mmlab://vgg16_caffe',
backbone=dict(
type='SSDVGG',
input_size=input_size,
depth=16,
with_last_pool=False,
ceil_mode=True,
out_indices=(3, 4),
out_feature_indi... | 3,987 | 28.323529 | 79 | py |
RAD | RAD-main/configs/mask_rcnn_x101_32x4d_fpn_1x.py | # model settings
model = dict(
type='MaskRCNN',
pretrained='open-mmlab://resnext101_32x4d',
backbone=dict(
type='ResNeXt',
depth=101,
groups=32,
base_width=4,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=d... | 5,856 | 29.505208 | 78 | py |
RAD | RAD-main/configs/fast_rcnn_r50_caffe_c4_1x.py | # model settings
norm_cfg = dict(type='BN', requires_grad=False)
model = dict(
type='FastRCNN',
pretrained='open-mmlab://resnet50_caffe',
backbone=dict(
type='ResNet',
depth=50,
num_stages=3,
strides=(1, 2, 2),
dilations=(1, 1, 1),
out_indices=(2, ),
f... | 4,570 | 30.743056 | 78 | py |
RAD | RAD-main/configs/cascade_mask_rcnn_r50_caffe_c4_1x.py | # model settings
norm_cfg = dict(type='BN', requires_grad=False)
model = dict(
type='CascadeRCNN',
num_stages=3,
pretrained='open-mmlab://resnet50_caffe',
backbone=dict(
type='ResNet',
depth=50,
num_stages=3,
strides=(1, 2, 2),
dilations=(1, 1, 1),
out_ind... | 7,957 | 30.085938 | 78 | py |
RAD | RAD-main/configs/cascade_mask_rcnn_r101_fpn_1x.py | # model settings
model = dict(
type='CascadeRCNN',
num_stages=3,
pretrained='torchvision://resnet101',
backbone=dict(
type='ResNet',
depth=101,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
type='FPN',
... | 8,007 | 30.527559 | 78 | py |
RAD | RAD-main/configs/cascade_rcnn_r101_fpn_1x.py | # model settings
model = dict(
type='CascadeRCNN',
num_stages=3,
pretrained='torchvision://resnet101',
backbone=dict(
type='ResNet',
depth=101,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
type='FPN',
... | 7,398 | 30.485106 | 78 | py |
RAD | RAD-main/configs/rpn_r101_fpn_1x.py | # model settings
model = dict(
type='RPN',
pretrained='torchvision://resnet101',
backbone=dict(
type='ResNet',
depth=101,
num_stages=4,
out_indices=(0, 1, 2, 3),
frozen_stages=1,
style='pytorch'),
neck=dict(
type='FPN',
in_channels=[256, 51... | 3,924 | 28.961832 | 78 | py |
rl-starter-files | rl-starter-files-master/model.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.distributions.categorical import Categorical
import torch_ac
# Function from https://github.com/ikostrikov/pytorch-a2c-ppo-acktr/blob/master/model.py
def init_params(m):
classname = m.__class__.__name__
if classname.find("Linear") !... | 3,418 | 30.366972 | 104 | py |
rl-starter-files | rl-starter-files-master/scripts/evaluate.py | import argparse
import time
import torch
from torch_ac.utils.penv import ParallelEnv
import utils
from utils import device
# Parse arguments
parser = argparse.ArgumentParser()
parser.add_argument("--env", required=True,
help="name of the environment (REQUIRED)")
parser.add_argument("--model", re... | 4,113 | 34.162393 | 121 | py |
rl-starter-files | rl-starter-files-master/scripts/train.py | import argparse
import time
import datetime
import torch_ac
import tensorboardX
import sys
import utils
from utils import device
from model import ACModel
# Parse arguments
parser = argparse.ArgumentParser()
# General parameters
parser.add_argument("--algo", required=True,
help="algorithm to us... | 8,521 | 40.77451 | 178 | py |
rl-starter-files | rl-starter-files-master/utils/storage.py | import csv
import os
import torch
import logging
import sys
import utils
from .other import device
def create_folders_if_necessary(path):
dirname = os.path.dirname(path)
if not os.path.isdir(dirname):
os.makedirs(dirname)
def get_storage_dir():
if "RL_STORAGE" in os.environ:
return os.e... | 1,525 | 20.492958 | 54 | py |
rl-starter-files | rl-starter-files-master/utils/format.py | import os
import json
import numpy
import re
import torch
import torch_ac
import gymnasium as gym
import utils
def get_obss_preprocessor(obs_space):
# Check if obs_space is an image space
if isinstance(obs_space, gym.spaces.Box):
obs_space = {"image": obs_space.shape}
def preprocess_obss(obs... | 2,581 | 30.108434 | 96 | py |
rl-starter-files | rl-starter-files-master/utils/agent.py | import torch
import utils
from .other import device
from model import ACModel
class Agent:
"""An agent.
It is able:
- to choose an action given an observation,
- to analyze the feedback (i.e. reward and done state) of its action."""
def __init__(self, obs_space, action_space, model_dir,
... | 1,921 | 32.719298 | 97 | py |
rl-starter-files | rl-starter-files-master/utils/other.py | import random
import numpy
import torch
import collections
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
def seed(seed):
random.seed(seed)
numpy.random.seed(seed)
torch.manual_seed(seed)
if torch.cuda.is_available():
torch.cuda.manual_seed_all(seed)
def synthesize(a... | 506 | 19.28 | 69 | py |
MAT-CNN-SOPC | MAT-CNN-SOPC-master/source/python/evaluation/handcrafted_metrics.py | import os
from utils.predict import *
import itertools
class HRA_metrics():
"""Perfofmance metrics base class.
"""
def __init__(self,
main_test_dir ='/home/sandbox/Desktop/Human_Rights_Archive_DB/test'
):
self.main_test_dir = main_test_dir
self.total_nb... | 16,276 | 34.852423 | 104 | py |
MAT-CNN-SOPC | MAT-CNN-SOPC-master/source/python/engine/bottleneck_features.py | # -*- coding: utf-8 -*-
"""Leverage a pre-trained network (saved network previously trained on a large dataset)
in order to build an image recognition system and analyse traffic.
Transfer image representations from popular deep learning models.
[A] ConvNet as fixed feature extractor.`Feature extraction` will simply c... | 13,894 | 40.354167 | 159 | py |
MAT-CNN-SOPC | MAT-CNN-SOPC-master/source/python/applications/vgg16_places_365.py | # -*- coding: utf-8 -*-
'''VGG16-places365 model for Keras
# Reference:
- [Places: A 10 million Image Database for Scene Recognition](http://places2.csail.mit.edu/PAMI_places.pdf)
- [https://github.com/GKalliatakis/Keras-VGG16-places365]
'''
from __future__ import division, print_function
import os
import warnings
... | 10,357 | 41.105691 | 160 | py |
GMAA | GMAA-main/metric/test_asr.py | from builtins import enumerate
import os
from PIL import Image
from tqdm import tqdm
import argparse
import torch
from glob import glob
import logging
import torch.nn.functional as F
from torchvision import transforms as T
from glob import glob
import logging
import cv2
import sys
import re
sys.path.append('src/models/... | 7,110 | 40.343023 | 153 | py |
GMAA | GMAA-main/metric/test_faceplusplus.py | import os
import time
import requests
from json import JSONDecoder
from tqdm import tqdm
import torch.nn.functional as F
import argparse
import re
def attack_faceplusplus():
parser = argparse.ArgumentParser()
parser.add_argument("--res_root", default="", help="path to generated images during testing")
par... | 3,527 | 36.531915 | 120 | py |
GMAA | GMAA-main/src/eval.py | import pyrootutils
root = pyrootutils.setup_root(
search_from=__file__,
indicator=[".git", "pyproject.toml"],
pythonpath=True,
dotenv=True,
)
# ------------------------------------------------------------------------------------ #
# `pyrootutils.setup_root(...)` is recommended at the top of each start... | 3,334 | 31.378641 | 98 | py |
GMAA | GMAA-main/src/train.py | import pyrootutils
root = pyrootutils.setup_root(
search_from=__file__,
indicator=[".git", "pyproject.toml"],
pythonpath=True,
dotenv=True,
)
# ------------------------------------------------------------------------------------ #
# `pyrootutils.setup_root(...)` is recommended at the top of each start... | 4,517 | 32.969925 | 136 | py |
GMAA | GMAA-main/src/datamodules/celebahq/face_datamodulel.py | from typing import Any, Dict, Optional, Tuple
from numpy import float32
import numpy as np
import torch
from pytorch_lightning import LightningDataModule
from torch.utils.data import ConcatDataset, DataLoader, Dataset, random_split
from torchvision.transforms import transforms
import random
import os
from PIL import ... | 11,451 | 34.345679 | 164 | py |
GMAA | GMAA-main/src/models/gmaa/gmaa_eval_module.py | from typing import Any, List
import torch
from pytorch_lightning import LightningModule
from torchmetrics import MaxMetric, MeanMetric
from torchmetrics.classification.accuracy import Accuracy
import torch.nn.functional as F
from torchvision import transforms as T
from torchvision.utils import save_image
import torch.... | 30,314 | 43.190962 | 232 | py |
GMAA | GMAA-main/src/models/gmaa/gmaa_module.py | from typing import Any, List
import torch
from pytorch_lightning import LightningModule
import torch.nn.functional as F
from torchvision import transforms as T
from torchvision.utils import save_image
import torch.nn as nn
import sys
import cv2
import random
import os
import numpy as np
from .crtiterions import LPIPS... | 28,346 | 42.74537 | 232 | py |
GMAA | GMAA-main/src/models/gmaa/models/model.py | from configparser import NoSectionError
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import random
import functools
class BaseNetwork(nn.Module):
def __init__(self):
super(BaseNetwork, self).__init__()
def init_weights(self):
self.apply(self._weights_i... | 17,112 | 35.333333 | 114 | py |
GMAA | GMAA-main/src/models/gmaa/crtiterions/lpips/lpips.py | from __future__ import absolute_import
import torch
import torch.nn
import torch.nn as nn
from torch.autograd import Variable
from . import lpips
from . import pretrained_networks as pn
def spatial_average(in_tens, keepdim=True):
return in_tens.mean([2, 3], keepdim=keepdim)
def upsample(in_tens, out_HW=(64, 64)... | 10,351 | 39.755906 | 120 | py |
GMAA | GMAA-main/src/models/gmaa/crtiterions/lpips/pretrained_networks.py | from collections import namedtuple
import torch
from torchvision import models as tv
class squeezenet(torch.nn.Module):
def __init__(self, requires_grad=False, pretrained=True):
super(squeezenet, self).__init__()
pretrained_features = tv.squeezenet1_1(pretrained=pretrained).features
self.sl... | 6,507 | 34.955801 | 109 | py |
GMAA | GMAA-main/src/models/gmaa/crtiterions/lpips/__init__.py |
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import torch
# from torch.autograd import Variable
from .trainer import *
from .lpips import *
def normalize_tensor(in_feat,eps=1e-10):
norm_factor = torch.sqrt(torch.sum(in_feat**2,di... | 4,864 | 31.218543 | 88 | py |
GMAA | GMAA-main/src/models/gmaa/crtiterions/lpips/trainer.py | from __future__ import absolute_import
import os
from collections import OrderedDict
import numpy as np
import torch
from scipy.ndimage import zoom
from torch.autograd import Variable
from tqdm import tqdm
from . import lpips
class Trainer():
def name(self):
return self.model_name
def initialize(self... | 11,575 | 40.640288 | 120 | py |
GMAA | GMAA-main/src/models/gmaa/pytorch_ssim/__init__.py | import torch
import torch.nn.functional as F
from torch.autograd import Variable
import numpy as np
from math import exp
def gaussian(window_size, sigma):
gauss = torch.Tensor([exp(-(x - window_size//2)**2/float(2*sigma**2)) for x in range(window_size)])
return gauss/gauss.sum()
def create_window(window_size,... | 2,635 | 34.621622 | 104 | py |
GMAA | GMAA-main/src/models/gmaa/FRmodels/ir152.py | import torch
import torch.nn as nn
from torch.nn import Linear, Conv2d, BatchNorm1d, BatchNorm2d, PReLU, ReLU, Sigmoid, Dropout, MaxPool2d, \
AdaptiveAvgPool2d, Sequential, Module
from collections import namedtuple
# Support: ['IR_50', 'IR_101', 'IR_152', 'IR_SE_50', 'IR_SE_101', 'IR_SE_152']
class Flatten(Modu... | 7,691 | 30.52459 | 112 | py |
GMAA | GMAA-main/src/models/gmaa/FRmodels/irse.py | from torch.nn import Linear, Conv2d, BatchNorm1d, BatchNorm2d, PReLU, ReLU, Sigmoid, Dropout2d, Dropout, AvgPool2d, \
MaxPool2d, AdaptiveAvgPool2d, Sequential, Module, Parameter
import torch.nn.functional as F
import torch
from collections import namedtuple
import math
import pdb
#################################... | 13,020 | 38.21988 | 120 | py |
GMAA | GMAA-main/src/models/gmaa/FRmodels/facenet.py | import torch
from torch import nn
from torch.nn import functional as F
class BasicConv2d(nn.Module):
def __init__(self, in_planes, out_planes, kernel_size, stride, padding=0):
super().__init__()
self.conv = nn.Conv2d(
in_planes, out_planes,
kernel_size=kernel_size, stride=... | 10,525 | 31.588235 | 105 | py |
GMAA | GMAA-main/src/utils/rich_utils.py | from pathlib import Path
from typing import Sequence
import rich
import rich.syntax
import rich.tree
from hydra.core.hydra_config import HydraConfig
from omegaconf import DictConfig, OmegaConf, open_dict
from pytorch_lightning.utilities import rank_zero_only
from rich.prompt import Prompt
from src.utils import pylogg... | 3,328 | 30.40566 | 102 | py |
GMAA | GMAA-main/src/utils/utils.py | import time
import warnings
from importlib.util import find_spec
from pathlib import Path
from typing import Any, Callable, Dict, List
import hydra
from omegaconf import DictConfig
from pytorch_lightning import Callback
from pytorch_lightning.loggers import LightningLoggerBase
from pytorch_lightning.utilities import r... | 6,518 | 30.645631 | 94 | py |
GMAA | GMAA-main/src/utils/pylogger.py | import logging
from pytorch_lightning.utilities import rank_zero_only
def get_pylogger(name=__name__) -> logging.Logger:
"""Initializes multi-GPU-friendly python command line logger."""
logger = logging.getLogger(name)
# this ensures all logging levels get marked with the rank zero decorator
# othe... | 608 | 32.833333 | 92 | py |
Thought-SC2 | Thought-SC2-master/TG-SC1/mind-SC1/protoss.py | import argparse
import torchcraft as tc
import torchcraft.Constants as tcc
import random
import matplotlib.pyplot as plt
import numpy as np
import scipy.ndimage as ndimage
from mini_agent import ProtossAction
parser = argparse.ArgumentParser(
description='Plays simple micro battles with an attack closest heuris... | 13,973 | 39.155172 | 132 | py |
Thought-SC2 | Thought-SC2-master/TG-SC1/mind-SC1/eval_mini_srcgame.py | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
USED_DEVICES = "-1"
import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = USED_DEVICES
import sys
import threading
import time
import tensorflow as tf
from absl import ... | 11,697 | 32.907246 | 145 | py |
Thought-SC2 | Thought-SC2-master/TG-SC1/mind-SC1/mini_source_agent.py | from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import tensorflow as tf
from pysc2.agents import base_agent
from pysc2.lib import actions as sc2_actions
from lib import utils as U
from lib import config as C
from lib import macro_action a... | 17,706 | 34.202783 | 144 | py |
Thought-SC2 | Thought-SC2-master/TG-SC1/mind-SC1/lib/macro_action.py | import lib.config as C
import lib.utils as U
import lib.transform_pos as T
import numpy as np
import torchcraft.Constants as tcc
import random
"""For the sake of simplicity, we give the macro-action directly and not provide the way on how to get them.
Also for simplicity, the information required for macro operations ... | 7,173 | 28.281633 | 120 | py |
Thought-SC2 | Thought-SC2-master/test/mnist_first_test.py | USED_DEVICES = "0"
import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = USED_DEVICES
import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Seq... | 718 | 26.653846 | 56 | py |
Thought-SC2 | Thought-SC2-master/test/iris_test.py | USED_DEVICES = "0"
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = USED_DEVICES
import tensorflow as tf
import pandas as pd
def input_fn(features, labels, training=True, batch_size=256):
"""An input function for training or ev... | 2,553 | 28.022727 | 105 | py |
Thought-SC2 | Thought-SC2-master/algo/zhang_ppo.py | """
Implementation of PPO
ref: Schulman, John, et al. "Proximal policy optimization algorithms." arXiv preprint arXiv:1707.06347 (2017).
ref: https://github.com/Jiankai-Sun/Proximal-Policy-Optimization-in-Pytorch/blob/master/ppo.py
ref: https://github.com/openai/baselines/tree/master/baselines/ppo2
NOTICE:
`Tensor... | 13,043 | 33.416887 | 126 | py |
gfx-classifier | gfx-classifier-master/src/trainer/trainer.py | import torch
import torch.nn.functional as F
import torch.nn as nn
import numpy as np
import utils
def train_fx_net(model, optimizer, train_loader, train_sampler, epoch, loss_function=nn.CrossEntropyLoss(), device='cpu'):
model.train()
train_set_size = len(train_sampler)
total_loss = 0
total_correct = ... | 33,766 | 36.940449 | 138 | py |
gfx-classifier | gfx-classifier-master/src/datasplit/datasplit.py | import numpy as np
import torch
import logging
from torch.utils.data import DataLoader
from torch.utils.data.sampler import SubsetRandomSampler
# from https://palikar.github.io/posts/pytorch_datasplit/
class DataSplit:
def __init__(self, dataset, test_train_split=0.8, val_train_split=0.1, shuffle=False):
... | 2,898 | 44.296875 | 116 | py |
gfx-classifier | gfx-classifier-master/src/dataset/dataset.py | import torch
import numpy as np
import librosa
import os
import csv
from torch.utils.data import Dataset
class FxDataset(Dataset):
def __init__(self,
root,
excl_folders=None,
spectra_folder=None,
processed_settings_csv='proc_setting... | 10,915 | 45.059072 | 128 | py |
gfx-classifier | gfx-classifier-master/src/model/models.py | import torch
import torch.nn as nn
import torch.nn.functional as F
class FxNet(nn.Module):
def __init__(self, n_classes):
super().__init__()
self.n_classes = n_classes # number of fx labels
self.conv1 = nn.Conv2d(in_channels=1, out_channels=6, kernel_size=5)
self.batchNorm1 = ... | 7,337 | 30.225532 | 107 | py |
RVMDE | RVMDE-main/rvmde_mer.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import matplotlib.pyplot as plt
class network(nn.Module):
def __init__(self, rd_layers):
super().__init__()
input_size = (192,400)
assert len(input_size) == 2
self.kernel_size = 16
self.si... | 15,464 | 36.26506 | 118 | py |
RVMDE | RVMDE-main/data_loader_depth_hg.py | import torch
from torch.utils import data
import numpy as np
from os.path import join
import matplotlib.pyplot as plt
import h5py
"""
Parts of the code is borrowed from https://github.com/longyunf/rc-pda
For further details please visit https://github.com/longyunf/rc-pda
"""
def init_data_loader(args, mode):
... | 2,764 | 34.909091 | 122 | py |
RVMDE | RVMDE-main/loss.py | import numpy as np
import torch
import torch.nn.functional as F
"""
Parts of the code is borrowed from https://github.com/lochenchou/DORN_radar
For further details please visit https://github.com/lochenchou/DORN_radar
"""
class OrdinalRegressionLoss(torch.nn.Module):
def __init__(self, ord_num, beta, discreti... | 1,880 | 33.833333 | 91 | py |
RVMDE | RVMDE-main/utils.py | import torch
import glob
import os
import shutil
import numpy as np
import matplotlib.pyplot as plt
from torch.optim.lr_scheduler import _LRScheduler
from PIL import Image
"""
Parts of the code is borrowed from https://github.com/lochenchou/DORN_radar
For further details please visit https://github.com/lochenchou/D... | 8,893 | 34.718876 | 107 | py |
RVMDE | RVMDE-main/valid_loader.py | """
Parts of the code is borrowed from https://github.com/lochenchou/DORN_radar
For further details please visit https://github.com/lochenchou/DORN_radar
"""
import os
import time
import torch
import numpy as np
import utils
from tqdm import tqdm
from metrics import AverageMeter, Result, compute_errors
import torch.... | 7,000 | 36.843243 | 176 | py |
RVMDE | RVMDE-main/metrics.py | import torch
import math
import numpy as np
lg_e_10 = math.log(10)
"""
Parts of the code is borrowed from https://github.com/lochenchou/DORN_radar
For further details please visit https://github.com/lochenchou/DORN_radar
"""
def log10(x):
"""Convert a new tensor with the base-10 logarithm of the elements of x.... | 6,699 | 31.524272 | 110 | py |
RVMDE | RVMDE-main/model/radar_retinanet.py | import torch
import torch.nn as nn
affine_par = True
"""
Parts of the code is borrowed from https://github.com/lochenchou/DORN_radar
For further details please visit https://github.com/lochenchou/DORN_radar
"""
def weights_init(m):
# Initialize filters with Gaussian random weights
if isinstance(m, nn.Conv... | 12,767 | 36.552941 | 118 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.