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 |
|---|---|---|---|---|---|---|
Attention-Gated-Networks | Attention-Gated-Networks-master/visualise_att_maps_epoch.py | from torch.utils.data import DataLoader
from dataio.loader import get_dataset, get_dataset_path
from dataio.transformation import get_dataset_transformation
from utils.util import json_file_to_pyobj
from models import get_model
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import math, numpy, os
from dat... | 3,482 | 36.451613 | 148 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/setup.py | #!/usr/bin/env python
from setuptools import setup, find_packages
with open('README.md') as f:
readme = f.read()
setup(name='AttentionGatedNetworks',
version='1.0',
description='Pytorch library for Soft Attention',
long_description=readme,
author='Ozan Oktay & Jo Schlemper',
install... | 782 | 22.029412 | 90 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/train_segmentation.py | import numpy
from torch.utils.data import DataLoader
from tqdm import tqdm
from dataio.loader import get_dataset, get_dataset_path
from dataio.transformation import get_dataset_transformation
from utils.util import json_file_to_pyobj
from utils.visualiser import Visualiser
from utils.error_logger import ErrorLogger
... | 4,354 | 39.324074 | 127 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/visualise_attention.py | from torch.utils.data import DataLoader
from dataio.loader import get_dataset, get_dataset_path
from dataio.transformation import get_dataset_transformation
from utils.util import json_file_to_pyobj
from utils.visualiser import Visualiser
from models import get_model
import os, time
# import matplotlib
# matplotlib.u... | 7,900 | 39.937824 | 178 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/test_classification.py | import os, sys, numpy as np
from torch.utils.data import DataLoader, sampler
from tqdm import tqdm
from dataio.loader import get_dataset, get_dataset_path
from dataio.transformation import get_dataset_transformation
from utils.util import json_file_to_pyobj
from utils.visualiser import Visualiser
from utils.error_log... | 6,345 | 34.651685 | 125 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/validation.py | from torch.utils.data import DataLoader
from dataio.loader import get_dataset, get_dataset_path
from dataio.transformation import get_dataset_transformation
from utils.util import json_file_to_pyobj
from models import get_model
import numpy as np
import os
from utils.metrics import dice_score, distance_metric, precis... | 3,992 | 43.366667 | 125 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/visualise_fmaps.py | from torch.utils.data import DataLoader
from dataio.loader import get_dataset, get_dataset_path
from dataio.transformation import get_dataset_transformation
from utils.util import json_file_to_pyobj
from models import get_model
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import math, numpy, os
from sci... | 3,357 | 39.95122 | 142 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/train_classifaction.py | import numpy as np
from torch.utils.data import DataLoader, sampler
from tqdm import tqdm
from dataio.loader import get_dataset, get_dataset_path
from dataio.transformation import get_dataset_transformation
from utils.util import json_file_to_pyobj
from utils.visualiser import Visualiser
from utils.error_logger impor... | 9,033 | 36.641667 | 124 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/base_model.py | import os
import numpy
import torch
from utils.util import mkdir
from .networks_other import get_n_parameters
class BaseModel():
def __init__(self):
self.input = None
self.net = None
self.isTrain = False
self.use_cuda = True
self.schedulers = []
self.optimizers = []
... | 3,357 | 32.247525 | 96 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/utils.py | '''
Misc Utility functions
'''
import os
import numpy as np
import torch.optim as optim
from torch.nn import CrossEntropyLoss
from utils.metrics import segmentation_scores, dice_score_list
from sklearn import metrics
from .layers.loss import *
def get_optimizer(option, params):
opt_alg = 'sgd' if not hasattr(opti... | 4,417 | 36.440678 | 156 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/aggregated_classifier.py | import os, collections
import numpy as np
import torch
from torch.autograd import Variable
from .feedforward_classifier import FeedForwardClassifier
class AggregatedClassifier(FeedForwardClassifier):
def name(self):
return 'AggregatedClassifier'
def initialize(self, opts, **kwargs):
FeedForwa... | 3,629 | 38.89011 | 120 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/feedforward_classifier.py | import os
import numpy as np
import utils.util as util
from collections import OrderedDict
import torch
from torch.autograd import Variable
from .base_model import BaseModel
from .networks import get_network
from .layers.loss import *
from .networks_other import get_scheduler, print_network, benchmark_fp_bp_time
from ... | 7,536 | 37.258883 | 102 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/networks_other.py | import torch
import torch.nn as nn
from torch.nn import init
import functools
from torch.autograd import Variable
from torch.optim import lr_scheduler
import time
import numpy as np
###############################################################################
# Functions
##############################################... | 20,196 | 37.251894 | 151 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/feedforward_seg_model.py | import torch
from torch.autograd import Variable
import torch.optim as optim
from collections import OrderedDict
import utils.util as util
from .base_model import BaseModel
from .networks import get_network
from .layers.loss import *
from .networks_other import get_scheduler, print_network, benchmark_fp_bp_time
from .... | 6,177 | 38.350318 | 112 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/networks/unet_nonlocal_2D.py | import math
import torch.nn as nn
from .utils import unetConv2, unetUp
from models.layers.nonlocal_layer import NONLocalBlock2D
import torch.nn.functional as F
class unet_nonlocal_2D(nn.Module):
def __init__(self, feature_scale=4, n_classes=21, is_deconv=True, in_channels=3,
is_batchnorm=True, n... | 3,267 | 36.136364 | 96 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/networks/sononet.py | import numpy as np
import math
import torch.nn as nn
from .utils import unetConv2, unetUp, conv2DBatchNormRelu, conv2DBatchNorm
import torch.nn.functional as F
from models.networks_other import init_weights
class sononet(nn.Module):
def __init__(self, feature_scale=4, n_classes=21, in_channels=3, is_batchnorm=Tru... | 2,761 | 31.494118 | 102 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/networks/unet_2D.py | import math
import torch.nn as nn
from .utils import unetConv2, unetUp
import torch.nn.functional as F
from models.networks_other import init_weights
class unet_2D(nn.Module):
def __init__(self, feature_scale=4, n_classes=21, is_deconv=True, in_channels=3, is_batchnorm=True):
super(unet_2D, self).__init__... | 2,613 | 27.413043 | 104 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/networks/utils.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from models.networks_other import init_weights
class conv2DBatchNorm(nn.Module):
def __init__(self, in_channels, n_filters, k_size, stride, padding, bias=True):
super(conv2DBatchNorm, self).__init__()
self.cb_unit = nn.Sequential... | 18,106 | 38.192641 | 120 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/networks/unet_nonlocal_3D.py | import math
import torch.nn as nn
from .utils import UnetConv3, UnetUp3
import torch.nn.functional as F
from models.layers.nonlocal_layer import NONLocalBlock3D
from models.networks_other import init_weights
class unet_nonlocal_3D(nn.Module):
def __init__(self, feature_scale=4, n_classes=21, is_deconv=True, in_ch... | 3,237 | 31.707071 | 103 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/networks/sononet_grid_attention.py | import numpy as np
import math
import torch.nn as nn
from .utils import unetConv2, unetUp, conv2DBatchNormRelu, conv2DBatchNorm
import torch
import torch.nn.functional as F
from models.layers.grid_attention_layer import GridAttentionBlock2D_TORR as AttentionBlock2D
from models.networks_other import init_weights
class ... | 5,710 | 38.659722 | 104 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/networks/unet_CT_dsv_3D.py | import torch.nn as nn
from .utils import UnetConv3, UnetUp3_CT, UnetDsv3
import torch.nn.functional as F
from models.networks_other import init_weights
import torch
class unet_CT_dsv_3D(nn.Module):
def __init__(self, feature_scale=4, n_classes=21, is_deconv=True, in_channels=3, is_batchnorm=True):
super(u... | 3,457 | 32.572816 | 122 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/networks/unet_grid_attention_3D.py | import torch.nn as nn
from .utils import UnetConv3, UnetUp3, UnetGridGatingSignal3
import torch.nn.functional as F
from models.layers.grid_attention_layer import GridAttentionBlock3D
from models.networks_other import init_weights
class unet_grid_attention_3D(nn.Module):
def __init__(self, feature_scale=4, n_class... | 4,134 | 36.252252 | 135 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/networks/unet_CT_multi_att_dsv_3D.py | import torch.nn as nn
import torch
from .utils import UnetConv3, UnetUp3_CT, UnetGridGatingSignal3, UnetDsv3
import torch.nn.functional as F
from models.networks_other import init_weights
from models.layers.grid_attention_layer import GridAttentionBlock3D
class unet_CT_multi_att_dsv_3D(nn.Module):
def __init__(s... | 6,354 | 44.719424 | 122 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/networks/unet_3D.py | import math
import torch.nn as nn
from .utils import UnetConv3, UnetUp3
import torch.nn.functional as F
from models.networks_other import init_weights
class unet_3D(nn.Module):
def __init__(self, feature_scale=4, n_classes=21, is_deconv=True, in_channels=3, is_batchnorm=True):
super(unet_3D, self).__init_... | 2,705 | 28.736264 | 104 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/networks/unet_CT_single_att_dsv_3D.py | import torch.nn as nn
import torch
from .utils import UnetConv3, UnetUp3_CT, UnetGridGatingSignal3, UnetDsv3
import torch.nn.functional as F
from models.networks_other import init_weights
from models.layers.grid_attention_layer import GridAttentionBlock3D
class unet_CT_single_att_dsv_3D(nn.Module):
def __init__(... | 5,952 | 43.096296 | 122 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/layers/grid_attention_layer.py | import torch
from torch import nn
from torch.nn import functional as F
from models.networks_other import init_weights
class _GridAttentionBlockND(nn.Module):
def __init__(self, in_channels, gating_channels, inter_channels=None, dimension=3, mode='concatenation',
sub_sample_factor=(2,2,2)):
... | 16,617 | 40.441397 | 137 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/layers/nonlocal_layer.py | import torch
from torch import nn
from torch.nn import functional as F
from models.networks_other import init_weights
class _NonLocalBlockND(nn.Module):
def __init__(self, in_channels, inter_channels=None, dimension=3, mode='embedded_gaussian',
sub_sample_factor=4, bn_layer=True):
super(_... | 13,546 | 39.318452 | 127 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/models/layers/loss.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.loss import _Loss
from torch.autograd import Function, Variable
def cross_entropy_2D(input, target, weight=None, size_average=True):
n, c, h, w = input.size()
log_p = F.log_softmax(input, dim=1)
log_p = log_p.transpose... | 3,621 | 34.509804 | 106 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/dataio/loader/test_dataset.py | import torch.utils.data as data
import numpy as np
import os
from os import listdir
from os.path import join
from .utils import load_nifti_img, check_exceptions, is_image_file
class TestDataset(data.Dataset):
def __init__(self, root_dir, transform):
super(TestDataset, self).__init__()
image_dir =... | 1,639 | 33.166667 | 111 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/dataio/loader/us_dataset.py | import torch
import torch.utils.data as data
import h5py
import numpy as np
import datetime
from os import listdir
from os.path import join
#from .utils import check_exceptions
class UltraSoundDataset(data.Dataset):
def __init__(self, root_path, split, transform=None, preload_data=False):
super(UltraSoun... | 2,405 | 30.657895 | 115 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/dataio/loader/cmr_3D_dataset.py | import torch.utils.data as data
import numpy as np
import datetime
from os import listdir
from os.path import join
from .utils import load_nifti_img, check_exceptions, is_image_file
class CMR3DDataset(data.Dataset):
def __init__(self, root_dir, split, transform=None, preload_data=False):
super(CMR3DDatas... | 2,167 | 39.148148 | 110 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/dataio/loader/ukbb_dataset.py | import torch.utils.data as data
import numpy as np
import datetime
from os import listdir
from os.path import join
from .utils import load_nifti_img, check_exceptions, is_image_file
class UKBBDataset(data.Dataset):
def __init__(self, root_dir, split, transform=None, preload_data=False):
super(UKBBDataset... | 2,346 | 39.465517 | 110 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/dataio/transformation/myImageTransformations.py | import numpy as np
import scipy
import scipy.ndimage
from scipy.ndimage.filters import gaussian_filter
from scipy.ndimage.interpolation import map_coordinates
import collections
from PIL import Image
import numbers
def center_crop(x, center_crop_size):
assert x.ndim == 3
centerw, centerh = x.shape[1] // 2, x.... | 14,785 | 31.640177 | 107 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/dataio/transformation/transforms.py | import torchsample.transforms as ts
from pprint import pprint
class Transformations:
def __init__(self, name):
self.name = name
# Input patch and scale size
self.scale_size = (192, 192, 1)
self.patch_size = (128, 128, 1)
# self.patch_size = (208, 272, 1)
# Affine... | 7,764 | 46.638037 | 119 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/utils/util.py | from __future__ import print_function
import torch
from PIL import Image
import inspect, re
import numpy as np
import os
import collections
import json
import csv
from skimage.exposure import rescale_intensity
# Converts a Tensor into a Numpy array
# |imtype|: the desired type of the converted numpy array
def tensor2i... | 3,464 | 32 | 97 | py |
Attention-Gated-Networks | Attention-Gated-Networks-master/utils/metrics.py | # Originally written by wkentaro
# https://github.com/wkentaro/pytorch-fcn/blob/master/torchfcn/utils.py
import numpy as np
import cv2
def _fast_hist(label_true, label_pred, n_class):
mask = (label_true >= 0) & (label_true < n_class)
hist = np.bincount(
n_class * label_true[mask].astype(int) +
... | 5,458 | 36.390411 | 91 | py |
muLAn | muLAn-master/muLAn/plottypes/fitflux.py | # -*-coding:Utf-8 -*
# ----------------------------------------------------------------------
# Routine to plot the result of the MCMC, in flux.
# ----------------------------------------------------------------------
# External libraries
# ----------------------------------------------------------------------
import... | 129,579 | 47.010374 | 1,076 | py |
muLAn | muLAn-master/muLAn/plottypes/fitmag.py | # -*-coding:Utf-8 -*
# ----------------------------------------------------------------------
# Routine to plot the result of the MCMC, in magnitude.
# ----------------------------------------------------------------------
# External libraries
# ----------------------------------------------------------------------
i... | 135,360 | 47.068537 | 1,076 | py |
CDGS | CDGS-main/losses.py | """All functions related to loss computation and optimization."""
import torch
import torch.optim as optim
import numpy as np
from models import utils as mutils
from sde_lib import VPSDE
def get_optimizer(config, params):
"""Return a flax optimizer object based on `config`."""
if config.optim.optimizer == 'A... | 7,611 | 42.00565 | 124 | py |
CDGS | CDGS-main/dpm_solvers.py | # DPM solvers: stiff semi-linear ODE
# Note: hyperparams of Atom_SDE and Bond_SDE should keep the same for DPM-Solver-1, DPM-Solver-2 and DPM-Solver-3 !!!
import torch
import numpy as np
import functools
from models.utils import get_multi_theta_fn, get_multi_score_fn, get_theta_fn
def sample_nodes(n_nodes_pmf, atom... | 23,918 | 43.376623 | 119 | py |
CDGS | CDGS-main/run_lib.py | import os
import torch
import numpy as np
import random
import logging
import time
from absl import flags
from torch.utils import tensorboard
from torch_geometric.loader import DataLoader, DenseDataLoader
import pickle
from rdkit import RDLogger, Chem
from models import cdgs
import losses
import sampling
from models i... | 15,886 | 43.00831 | 120 | py |
CDGS | CDGS-main/utils.py | import torch
import os
import logging
import re
import copy
import numpy as np
import torch.nn.functional as F
import networkx as nx
from rdkit import Chem, DataStructs
from rdkit.Chem import AllChem, rdMolDescriptors
from rdkit.Chem.Descriptors import MolLogP, qed
from sascorer import calculateScore
ATOM_VALENCY = {6... | 14,882 | 30.801282 | 117 | py |
CDGS | CDGS-main/sampling.py | """Various sampling methods."""
import functools
import torch
import numpy as np
import abc
from models.utils import get_multi_score_fn
from scipy import integrate
# from torchdiffeq import odeint
import sde_lib
from models import utils as mutils
from dpm_solvers import get_mol_sampler_dpm1, get_mol_sampler_dpm2, ge... | 22,407 | 41.845124 | 120 | py |
CDGS | CDGS-main/datasets.py | import ast
import torch
import json
import os
import numpy as np
import os.path as osp
import pandas as pd
import pickle as pk
from itertools import repeat
from rdkit import Chem
import torch_geometric.transforms as T
from torch_geometric.data import Data, InMemoryDataset, download_url
from torch_geometric.utils import... | 20,430 | 36.147273 | 129 | py |
CDGS | CDGS-main/sde_lib.py | """Abstract SDE classes, Reverse SDE, and VE/VP SDEs."""
import abc
import torch
import numpy as np
class SDE(abc.ABC):
"""SDE abstract class. Functions are designed for a mini-batch of inputs."""
def __init__(self, N):
"""Construct an SDE.
Args:
N: number of discretization time... | 8,565 | 35.14346 | 120 | py |
CDGS | CDGS-main/evaluation/mol_metrics.py | from fcd_torch import FCD
def compute_intermediate_FCD(smiles, n_jobs=1, device='cpu', batch_size=512):
"""
Precomputes statistics such as mean and variance for FCD.
"""
kwargs_fcd = {'n_jobs': n_jobs, 'device': device, 'batch_size': batch_size}
stats = FCD(**kwargs_fcd).precalc(smiles)
return... | 674 | 31.142857 | 83 | py |
CDGS | CDGS-main/models/cdgs.py | import torch.nn as nn
import torch
import functools
from torch_geometric.utils import dense_to_sparse
from . import utils, layers
from .hmpb import HybridMPBlock
get_act = layers.get_act
conv1x1 = layers.conv1x1
@utils.register_model(name='CDGS')
class CDGS(nn.Module):
"""
Graph Noise Prediction Model.
... | 7,728 | 35.116822 | 114 | py |
CDGS | CDGS-main/models/utils.py | """All functions and modules related to model definition.
"""
import torch
import sde_lib
import numpy as np
from torch_scatter import scatter_min, scatter_max, scatter_mean, scatter_std
_MODELS = {}
def register_model(cls=None, *, name=None):
"""A decorator for registering model classes."""
def _register... | 10,204 | 38.099617 | 146 | py |
CDGS | CDGS-main/models/transformer_layers.py | import math
from typing import Union, Tuple, Optional
from torch_geometric.typing import PairTensor, Adj, OptTensor
import torch
import torch.nn as nn
from torch import Tensor
import torch.nn.functional as F
from torch.nn import Linear
from torch_scatter import scatter
from torch_geometric.nn.conv import MessagePassin... | 3,328 | 35.184783 | 109 | py |
CDGS | CDGS-main/models/layers.py | """Common layers for defining score networks."""
import torch.nn as nn
import torch
import torch.nn.functional as F
import numpy as np
import math
import torch_geometric.nn as graph_nn
def get_act(config):
"""Get actiuvation functions from the config file."""
if config.model.nonlinearity.lower() == 'elu':
... | 1,641 | 33.93617 | 103 | py |
CDGS | CDGS-main/models/ema.py | import torch
class ExponentialMovingAverage:
"""
Maintains (exponential) moving average of a set of parameters.
"""
def __init__(self, parameters, decay, use_num_updates=True):
"""
Args:
parameters: Iterable of `torch.nn.Parameter`; usually the result of `model.parameters(... | 3,373 | 38.232558 | 114 | py |
CDGS | CDGS-main/models/hmpb.py | import numpy as np
import torch
import math
import torch.nn as nn
import torch.nn.functional as F
import torch_geometric.nn as pygnn
from torch_geometric.nn import Linear as Linear_pyg
from torch_geometric.utils import dense_to_sparse
from .transformer_layers import EdgeGateTransLayer
class HybridMPBlock(nn.Module):... | 6,040 | 38.743421 | 103 | py |
CDGS | CDGS-main/configs/vp_zinc_cdgs.py | """Training GNN on ZINC250k with continuous VPSDE."""
import ml_collections
import torch
def get_config():
config = ml_collections.ConfigDict()
config.model_type = 'mol_sde'
# training
config.training = training = ml_collections.ConfigDict()
training.sde = 'vpsde'
training.continuous = True... | 3,149 | 26.876106 | 96 | py |
CDGS | CDGS-main/configs/vp_qm9_cdgs.py | """Training GNN on QM9 with continuous VPSDE."""
import ml_collections
import torch
def get_config():
config = ml_collections.ConfigDict()
config.model_type = 'mol_sde'
# training
config.training = training = ml_collections.ConfigDict()
training.sde = 'vpsde'
training.continuous = True
... | 3,118 | 26.60177 | 96 | py |
pubmed_parser | pubmed_parser-master/docs/conf.py | # Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If ex... | 2,161 | 32.261538 | 79 | py |
crpn | crpn-master/tools/compress_net.py | #!/usr/bin/env python
# --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------
"""Compress a Fast R-CNN network using truncated... | 3,918 | 30.103175 | 81 | py |
crpn | crpn-master/tools/train_faster_rcnn_alt_opt.py | #!/usr/bin/env python
# --------------------------------------------------------
# Faster R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------
"""Train a Faster R-CNN network using alternat... | 12,871 | 37.423881 | 80 | py |
crpn | crpn-master/tools/test_net.py | #!/usr/bin/env python
# --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------
"""Test a Fast R-CNN network on an image databas... | 3,165 | 33.791209 | 77 | py |
crpn | crpn-master/tools/_init_paths.py | # --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------
"""Set up paths for Fast R-CNN."""
import os.path as osp
import sys
d... | 637 | 23.538462 | 66 | py |
crpn | crpn-master/tools/model_libs.py | import os
import _init_paths
import caffe
from caffe import layers as L
from caffe import params as P
from caffe.proto import caffe_pb2
def check_if_exist(path):
return os.path.exists(path)
def make_if_not_exist(path):
if not os.path.exists(path):
os.makedirs(path)
def UnpackVariable(var, num):
as... | 40,548 | 42.367914 | 132 | py |
crpn | crpn-master/tools/demo.py | #!/usr/bin/env python
# --------------------------------------------------------
# Faster R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------
"""
Demo script showing detections in sample i... | 6,624 | 32.974359 | 111 | py |
crpn | crpn-master/tools/train_svms.py | #!/usr/bin/env python
# --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------
"""
Train post-hoc SVMs using the algorithm and ... | 13,480 | 37.081921 | 80 | py |
crpn | crpn-master/tools/gen_crpn.py | #!/usr/bin/env python
from __future__ import division
import _init_paths
import caffe
from caffe import layers as L, params as P
from fast_rcnn.config import cfg
def conv_relu(bottom, nout, ks=3, stride=1, pad=1):
conv = L.Convolution(bottom, kernel_size=ks, stride=stride, num_output=nout, pad=pad,
... | 11,040 | 52.081731 | 119 | py |
crpn | crpn-master/tools/rpn_generate.py | #!/usr/bin/env python
# --------------------------------------------------------
# Fast/er/ R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------
"""Generate RPN proposals."""
import _init_... | 2,994 | 31.554348 | 78 | py |
crpn | crpn-master/tools/generate_net.py | #!/usr/bin/env python
from __future__ import division
import _init_paths
import caffe
from caffe import layers as L, params as P
from caffe.coord_map import crop
def conv_relu(bottom, nout, ks=3, stride=1, pad=1):
conv = L.Convolution(bottom, kernel_size=ks, stride=stride, num_output=nout, pad=pad,
... | 6,908 | 44.453947 | 118 | py |
crpn | crpn-master/tools/train_net.py | #!/usr/bin/env python
# --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------
"""Train a Fast R-CNN network on a region of int... | 3,747 | 32.168142 | 78 | py |
crpn | crpn-master/caffe-fast-rcnn/tools/extra/summarize.py | #!/usr/bin/env python
"""Net summarization tool.
This tool summarizes the structure of a net in a concise but comprehensive
tabular listing, taking a prototxt file as input.
Use this tool to check at a glance that the computation you've specified is the
computation you expect.
"""
from caffe.proto import caffe_pb2
... | 4,880 | 33.617021 | 95 | py |
crpn | crpn-master/caffe-fast-rcnn/tools/extra/parse_log.py | #!/usr/bin/env python
"""
Parse training log
Evolved from parse_log.sh
"""
import os
import re
import extract_seconds
import argparse
import csv
from collections import OrderedDict
def parse_log(path_to_log):
"""Parse log file
Returns (train_dict_list, test_dict_list)
train_dict_list and test_dict_lis... | 7,136 | 32.824645 | 86 | py |
crpn | crpn-master/caffe-fast-rcnn/src/caffe/test/test_data/generate_sample_data.py | """
Generate data used in the HDF5DataLayer and GradientBasedSolver tests.
"""
import os
import numpy as np
import h5py
script_dir = os.path.dirname(os.path.abspath(__file__))
# Generate HDF5DataLayer sample_data.h5
num_cols = 8
num_rows = 10
height = 6
width = 5
total_size = num_cols * num_rows * height * width
da... | 2,104 | 24.670732 | 70 | py |
crpn | crpn-master/caffe-fast-rcnn/python/draw_net.py | #!/usr/bin/env python
"""
Draw a graph of the net architecture.
"""
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from google.protobuf import text_format
import caffe
import caffe.draw
from caffe.proto import caffe_pb2
def parse_args():
"""Parse input arguments
"""
parser = Argument... | 1,934 | 31.79661 | 81 | py |
crpn | crpn-master/caffe-fast-rcnn/python/detect.py | #!/usr/bin/env python
"""
detector.py is an out-of-the-box windowed detector
callable from the command line.
By default it configures and runs the Caffe reference ImageNet model.
Note that this model was trained for image classification and not detection,
and finetuning for detection can be expected to improve results... | 5,734 | 31.95977 | 88 | py |
crpn | crpn-master/caffe-fast-rcnn/python/classify.py | #!/usr/bin/env python
"""
classify.py is an out-of-the-box image classifer callable from the command line.
By default it configures and runs the Caffe reference ImageNet model.
"""
import numpy as np
import os
import sys
import argparse
import glob
import time
import caffe
def main(argv):
pycaffe_dir = os.path.... | 4,262 | 29.669065 | 88 | py |
crpn | crpn-master/caffe-fast-rcnn/python/train.py | #!/usr/bin/env python
"""
Trains a model using one or more GPUs.
"""
from multiprocessing import Process
import caffe
def train(
solver, # solver proto definition
snapshot, # solver snapshot to restore
gpus, # list of device ids
timing=False, # show timing info for compute and com... | 3,145 | 30.148515 | 85 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/net_spec.py | """Python net specification.
This module provides a way to write nets directly in Python, using a natural,
functional style. See examples/pycaffe/caffenet.py for an example.
Currently this works as a thin wrapper around the Python protobuf interface,
with layers and parameters automatically generated for the "layers"... | 8,277 | 34.835498 | 88 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/classifier.py | #!/usr/bin/env python
"""
Classifier is an image classifier specialization of Net.
"""
import numpy as np
import caffe
class Classifier(caffe.Net):
"""
Classifier extends Net for image class prediction
by scaling, center cropping, or oversampling.
Parameters
----------
image_dims : dimensio... | 3,537 | 34.737374 | 78 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/coord_map.py | """
Determine spatial relationships between layers to relate their coordinates.
Coordinates are mapped from input-to-output (forward), but can
be mapped output-to-input (backward) by the inverse mapping too.
This helps crop and align feature maps among other uses.
"""
from __future__ import division
import numpy as np... | 6,721 | 35.139785 | 79 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/detector.py | #!/usr/bin/env python
"""
Do windowed detection by classifying a number of images/crops at once,
optionally using the selective search window proposal method.
This implementation follows ideas in
Ross Girshick, Jeff Donahue, Trevor Darrell, Jitendra Malik.
Rich feature hierarchies for accurate object detection... | 8,541 | 38.364055 | 80 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/__init__.py | from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
from ._caffe import init_log, log, set_mode_cpu, set_mode_gpu, set_device, Layer, get_solver, layer_type_list, set_random_seed, solver_count, set_solver_count, solver_rank, set_solver_rank, set_mul... | 552 | 60.444444 | 216 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/pycaffe.py | """
Wrap the internal caffe C++ module (_caffe.so) with a clean, Pythonic
interface.
"""
from collections import OrderedDict
try:
from itertools import izip_longest
except:
from itertools import zip_longest as izip_longest
import numpy as np
from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \... | 11,615 | 32.572254 | 89 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/draw.py | """
Caffe network visualization: draw the NetParameter protobuffer.
.. note::
This requires pydot>=1.0.2, which is not included in requirements.txt since
it requires graphviz and other prerequisites outside the scope of the
Caffe.
"""
from caffe.proto import caffe_pb2
"""
pydot is not supported under p... | 8,789 | 34.877551 | 112 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/io.py | import numpy as np
import skimage.io
from scipy.ndimage import zoom
from skimage.transform import resize
try:
# Python3 will most likely not be able to load protobuf
from caffe.proto import caffe_pb2
except:
import sys
if sys.version_info >= (3, 0):
print("Failed to include caffe_pb2, things mi... | 12,743 | 32.1875 | 110 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/test/test_coord_map.py | import unittest
import numpy as np
import random
import caffe
from caffe import layers as L
from caffe import params as P
from caffe.coord_map import coord_map_from_to, crop
def coord_net_spec(ks=3, stride=1, pad=0, pool=2, dstride=2, dpad=0):
"""
Define net spec for simple conv-pool-deconv pattern common t... | 6,894 | 34.725389 | 79 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/test/test_python_layer_with_param_str.py | import unittest
import tempfile
import os
import six
import caffe
class SimpleParamLayer(caffe.Layer):
"""A layer that just multiplies by the numeric value of its param string"""
def setup(self, bottom, top):
try:
self.value = float(self.param_str)
except ValueError:
... | 2,031 | 31.774194 | 79 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/test/test_io.py | import numpy as np
import unittest
import caffe
class TestBlobProtoToArray(unittest.TestCase):
def test_old_format(self):
data = np.zeros((10,10))
blob = caffe.proto.caffe_pb2.BlobProto()
blob.data.extend(list(data.flatten()))
shape = (1,1,10,10)
blob.num, blob.channels, b... | 1,694 | 28.736842 | 65 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/test/test_solver.py | import unittest
import tempfile
import os
import numpy as np
import six
import caffe
from test_net import simple_net_file
class TestSolver(unittest.TestCase):
def setUp(self):
self.num_output = 13
net_f = simple_net_file(self.num_output)
f = tempfile.NamedTemporaryFile(mode='w+', delete=F... | 2,165 | 33.380952 | 76 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/test/test_layer_type_list.py | import unittest
import caffe
class TestLayerTypeList(unittest.TestCase):
def test_standard_types(self):
#removing 'Data' from list
for type_name in ['Data', 'Convolution', 'InnerProduct']:
self.assertIn(type_name, caffe.layer_type_list(),
'%s not in layer_type_lis... | 338 | 27.25 | 65 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/test/test_net.py | import unittest
import tempfile
import os
import numpy as np
import six
from collections import OrderedDict
import caffe
def simple_net_file(num_output):
"""Make a simple net prototxt, based on test_net.cpp, returning the name
of the (temporary) file."""
f = tempfile.NamedTemporaryFile(mode='w+', delete... | 11,640 | 28.848718 | 82 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/test/test_draw.py | import os
import unittest
from google.protobuf import text_format
import caffe.draw
from caffe.proto import caffe_pb2
def getFilenames():
"""Yields files in the source tree which are Net prototxts."""
result = []
root_dir = os.path.abspath(os.path.join(
os.path.dirname(__file__), '..', '..', '..... | 1,114 | 28.342105 | 79 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/test/test_nccl.py | import sys
import unittest
import caffe
class TestNCCL(unittest.TestCase):
def test_newuid(self):
"""
Test that NCCL uids are of the proper type
according to python version
"""
if caffe.has_nccl():
uid = caffe.NCCL.new_uid()
if sys.version_info.maj... | 457 | 21.9 | 55 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/test/test_net_spec.py | import unittest
import tempfile
import caffe
from caffe import layers as L
from caffe import params as P
def lenet(batch_size):
n = caffe.NetSpec()
n.data, n.label = L.DummyData(shape=[dict(dim=[batch_size, 1, 28, 28]),
dict(dim=[batch_size, 1, 1, 1])],
... | 3,756 | 40.744444 | 80 | py |
crpn | crpn-master/caffe-fast-rcnn/python/caffe/test/test_python_layer.py | import unittest
import tempfile
import os
import six
import caffe
class SimpleLayer(caffe.Layer):
"""A layer that just multiplies by ten"""
def setup(self, bottom, top):
pass
def reshape(self, bottom, top):
top[0].reshape(*bottom[0].data.shape)
def forward(self, bottom, top):
... | 5,510 | 31.609467 | 81 | py |
crpn | crpn-master/caffe-fast-rcnn/scripts/cpp_lint.py | #!/usr/bin/env python
#
# Copyright (c) 2009 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list... | 187,569 | 37.483792 | 93 | py |
crpn | crpn-master/caffe-fast-rcnn/scripts/split_caffe_proto.py | #!/usr/bin/env python
import mmap
import re
import os
import errno
script_path = os.path.dirname(os.path.realpath(__file__))
# a regex to match the parameter definitions in caffe.proto
r = re.compile(r'(?://.*\n)*message ([^ ]*) \{\n(?: .*\n|\n)*\}')
# create directory to put caffe.proto fragments
try:
os.mkdir(... | 941 | 25.166667 | 65 | py |
crpn | crpn-master/caffe-fast-rcnn/scripts/download_model_binary.py | #!/usr/bin/env python
import os
import sys
import time
import yaml
import hashlib
import argparse
from six.moves import urllib
required_keys = ['caffemodel', 'caffemodel_url', 'sha1']
def reporthook(count, block_size, total_size):
"""
From http://blog.moleculea.com/2012/10/04/urlretrieve-progres-indicator/
... | 2,531 | 31.461538 | 78 | py |
crpn | crpn-master/lib/roi_data_layer/layer.py | # --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------
"""The data layer used during training to train a Fast R-CNN network.
... | 7,450 | 36.631313 | 81 | py |
crpn | crpn-master/lib/roi_data_layer/minibatch.py | # --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------
"""Compute minibatch blobs for training a Fast R-CNN network."""
impor... | 8,409 | 39.432692 | 97 | py |
crpn | crpn-master/lib/fast_rcnn/test.py | # --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------
"""Test a Fast R-CNN network on an imdb (image database)."""
import os... | 12,911 | 38.127273 | 110 | py |
crpn | crpn-master/lib/fast_rcnn/config.py | # --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------
"""Fast R-CNN config system.
This file specifies default config option... | 9,936 | 29.764706 | 91 | py |
crpn | crpn-master/lib/fast_rcnn/train.py | # --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------
"""Train a Fast R-CNN network."""
import caffe
from fast_rcnn.config i... | 6,076 | 36.282209 | 79 | py |
crpn | crpn-master/lib/rpn/proposal_layer.py | # --------------------------------------------------------
# CRPN
# Written by Linjie Deng
# --------------------------------------------------------
import yaml
import caffe
import numpy as np
from fast_rcnn.config import cfg
from fast_rcnn.nms_wrapper import nms
from quad.quad_convert import whctrs, mkanchors, quad_2... | 13,357 | 38.173021 | 108 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.