repo
stringlengths
2
99
file
stringlengths
13
225
code
stringlengths
0
18.3M
file_length
int64
0
18.3M
avg_line_length
float64
0
1.36M
max_line_length
int64
0
4.26M
extension_type
stringclasses
1 value
chainer
chainer-master/examples/chainermn/seq2seq/seq2seq_mp1.py
# encoding: utf-8 import argparse import math import os.path import pickle import re import sys import time from nltk.translate import bleu_score import numpy import six import chainer from chainer import cuda import chainer.functions as F import chainer.links as L from chainer import reporter from chainer import tr...
19,042
34.005515
78
py
chainer
chainer-master/examples/chainermn/seq2seq/seq2seq.py
# encoding: utf-8 import argparse import math import os.path import pickle import re import sys import time from nltk.translate import bleu_score import numpy import six import chainer from chainer import cuda import chainer.functions as F import chainer.links as L from chainer import reporter from chainer import tr...
18,549
34.536398
101
py
chainer
chainer-master/examples/chainermn/parallel_convolution/VGG.py
from __future__ import print_function import chainer import chainer.functions as F import chainer.links as L import chainermn.functions import numpy as np """ This example is ported from Chainer official VGG16 example. https://github.com/chainer/chainer/blob/master/examples/cifar/models/VGG.py """ class ParallelCo...
6,013
32.786517
79
py
chainer
chainer-master/examples/chainermn/parallel_convolution/train.py
from __future__ import print_function import argparse import chainer import chainer.links as L from chainer import training from chainer.training import extensions import chainermn import VGG import matplotlib matplotlib.use('Agg') def main(): parser = argparse.ArgumentParser(description='ChainerMN example: V...
4,238
34.621849
76
py
chainer
chainer-master/examples/optuna/chainer_simple.py
""" Optuna example that optimizes multi-layer perceptrons using Chainer. In this example, we optimize the validation accuracy of hand-written digit recognition using Chainer and MNIST. We optimize the neural network architecture as well as the optimizer configuration. As it is too time consuming to use the whole MNIST...
4,621
30.442177
84
py
chainer
chainer-master/examples/optuna/chainermn_simple.py
""" Optuna example that optimizes multi-layer perceptrons using ChainerMN. In this example, we optimize the validation accuracy of hand-written digit recognition using ChainerMN and MNIST, where architecture of neural network is optimized. ChainerMN and it's Optuna integration are supposed to be invoked via MPI. You ...
3,898
30.443548
84
py
chainer
chainer-master/examples/optuna/chainer_integration.py
""" Optuna example that demonstrates a pruner for Chainer. In this example, we optimize the hyperparameters of a neural network for hand-written digit recognition in terms of validation loss. The network is implemented by Chainer and evaluated by MNIST dataset. Throughout the training of neural networks, a pruner obse...
4,372
30.919708
84
py
chainer
chainer-master/examples/optuna/chainermn_integration.py
""" Optuna example that demonstrates a pruner for ChainerMN. In this example, we optimize the validation accuracy of hand-written digit recognition using ChainerMN and MNIST, where architecture of neural network is optimized. Throughout the training of neural networks, a pruner observes intermediate results and stops ...
5,146
31.99359
79
py
chainer
chainer-master/examples/text_classification/text_datasets.py
import csv import glob import io import os import shutil import sys import tarfile import tempfile import numpy import chainer from nlp_utils import make_vocab from nlp_utils import normalize_text from nlp_utils import split_text from nlp_utils import transform_to_array URL_DBPEDIA = 'https://github.com/le-scientif...
5,533
30.988439
102
py
chainer
chainer-master/examples/text_classification/run_text_classifier.py
#!/usr/bin/env python import argparse import json import sys import chainer import numpy import nets import nlp_utils def setup_model(device, model_setup): sys.stderr.write(json.dumps(args.__dict__, indent=2) + '\n') setup = json.load(open(model_setup)) sys.stderr.write(json.dumps(setup, indent=2) + '\n...
4,034
34.707965
79
py
chainer
chainer-master/examples/text_classification/nlp_utils.py
import collections import io import numpy import chainer def split_text(text, char_based=False): if char_based: return list(text) else: return text.split() def normalize_text(text): return text.strip().lower() def make_vocab(dataset, max_vocab_size=20000, min_freq=2): counts = co...
2,316
26.915663
76
py
chainer
chainer-master/examples/text_classification/train_text_classifier.py
#!/usr/bin/env python import argparse import datetime import json import os import chainer from chainer import training from chainer.training import extensions import nets from nlp_utils import convert_seq import text_datasets def main(): current_datetime = '{}'.format(datetime.datetime.today()) parser = ar...
6,397
38.9875
77
py
chainer
chainer-master/examples/text_classification/nets.py
import numpy import chainer import chainer.functions as F import chainer.links as L from chainer import reporter embed_init = chainer.initializers.Uniform(.25) def sequence_embed(embed, xs, dropout=0.): """Efficient embedding function for variable-length sequences This output is equally to "return [F.d...
9,165
32.330909
79
py
chainer
chainer-master/examples/imagenet/nin.py
import chainer import chainer.functions as F import chainer.initializers as I import chainer.links as L class NIN(chainer.Chain): """Network-in-Network example model.""" insize = 227 def __init__(self): super(NIN, self).__init__() conv_init = I.HeNormal() # MSRA scaling with s...
1,295
34.027027
74
py
chainer
chainer-master/examples/imagenet/resnext50.py
import chainer import chainer.functions as F from chainer import initializers import chainer.links as L class BottleNeckA(chainer.Chain): def __init__(self, in_size, ch, out_size, stride=2, groups=1): super(BottleNeckA, self).__init__() initialW = initializers.HeNormal() with self.init_s...
3,601
32.351852
74
py
chainer
chainer-master/examples/imagenet/train_imagenet.py
#!/usr/bin/env python """Example code of learning a large scale convnet from ILSVRC2012 dataset. Prerequisite: To run this example, crop the center of ILSVRC2012 training and validation images, scale them to 256x256 and convert them to RGB, and make two lists of space-separated CSV whose first column is full path to i...
7,826
40.632979
79
py
chainer
chainer-master/examples/imagenet/googlenet.py
import chainer import chainer.functions as F import chainer.links as L class GoogLeNet(chainer.Chain): insize = 224 def __init__(self): super(GoogLeNet, self).__init__() with self.init_scope(): self.conv1 = L.Convolution2D(None, 64, 7, stride=2, pad=3) self.conv2_red...
2,938
33.576471
71
py
chainer
chainer-master/examples/imagenet/compute_mean.py
#!/usr/bin/env python import argparse import sys import numpy as np import chainer def compute_mean(dataset): print('compute mean image') sum_image = 0 N = len(dataset) for i, (image, _) in enumerate(dataset): sum_image += image sys.stderr.write('{} / {}\r'.format(i, N)) sys....
1,037
25.615385
77
py
chainer
chainer-master/examples/imagenet/googlenetbn.py
import chainer import chainer.functions as F import chainer.links as L class GoogLeNetBN(chainer.Chain): """New GoogLeNet of BatchNormalization version.""" insize = 224 def __init__(self): super(GoogLeNetBN, self).__init__() with self.init_scope(): self.conv1 = L.Convolution...
3,429
34
74
py
chainer
chainer-master/examples/imagenet/resnet50.py
# Original author: yasunorikudo # (https://github.com/yasunorikudo/chainer-ResNet) import chainer import chainer.functions as F from chainer import initializers import chainer.links as L class BottleNeckA(chainer.Chain): def __init__(self, in_size, ch, out_size, stride=2, groups=1): super(BottleNeckA, s...
4,807
32.158621
74
py
chainer
chainer-master/examples/imagenet/dali_util.py
import numpy as np try: from nvidia import dali from nvidia.dali import ops from nvidia.dali import pipeline _dali_available = True except ImportError: class pipeline(object): Pipeline = object pass _dali_available = False import chainer from chainer.backends import cuda impor...
7,470
38.951872
78
py
chainer
chainer-master/examples/imagenet/dataset_util.py
import random import chainer from chainer import dataset from chainer import datasets class PreprocessedDataset(dataset.DatasetMixin): def __init__(self, path, root, mean, crop_size, random=True): self.base = datasets.LabeledImageDataset(path, root) self.mean = mean.astype(chainer.get_dtype()) ...
1,459
30.06383
77
py
chainer
chainer-master/examples/imagenet/alex.py
import chainer import chainer.functions as F import chainer.links as L class Alex(chainer.Chain): """Single-GPU AlexNet without partition toward the channel axis.""" insize = 227 def __init__(self): super(Alex, self).__init__() with self.init_scope(): self.conv1 = L.Convolut...
1,369
34.128205
74
py
chainer
chainer-master/examples/imagenet/train_imagenet_data_parallel.py
#!/usr/bin/env python """Example code of learning a large scale convnet from LSVRC2012 dataset with multiple GPUs using data parallelism. Prerequisite: To run this example, crop the center of ILSVRC2012 training and validation images, scale them to 256x256 and convert them to RGB, and make two lists of space-separated...
6,197
40.046358
79
py
chainer
chainer-master/examples/imagenet/.testdata/replacements/train_imagenet.py
#!/usr/bin/env python """Example code of learning a large scale convnet from ILSVRC2012 dataset. Prerequisite: To run this example, crop the center of ILSVRC2012 training and validation images, scale them to 256x256 and convert them to RGB, and make two lists of space-separated CSV whose first column is full path to i...
7,962
40.473958
79
py
chainer
chainer-master/examples/sentiment/download.py
#!/usr/bin/env python import os import os.path from six.moves.urllib import request import zipfile request.urlretrieve( 'https://nlp.stanford.edu/sentiment/trainDevTestTrees_PTB.zip', 'trainDevTestTrees_PTB.zip') zf = zipfile.ZipFile('trainDevTestTrees_PTB.zip') for name in zf.namelist(): (dirname, filena...
403
24.25
67
py
chainer
chainer-master/examples/sentiment/thin_stack.py
import chainer from chainer import backend from chainer.utils import type_check class ThinStackSet(chainer.Function): """Set values to a thin stack.""" def check_type_forward(self, in_types): type_check.expect(in_types.size() == 3) s_type, i_type, v_type = in_types type_check.expect(...
2,137
27.506667
61
py
chainer
chainer-master/examples/sentiment/test_thin_stack.py
import unittest import numpy import chainer from chainer import backend from chainer import cuda from chainer import testing from chainer.testing import attr import thin_stack class TestThinStackGet(unittest.TestCase): shape = (3, 4, 5) dtype = numpy.float32 def setUp(self): self.s = numpy.ra...
4,647
30.835616
77
py
chainer
chainer-master/examples/sentiment/train_recursive_minibatch.py
import argparse import warnings import numpy import chainer import chainer.functions as F import chainer.links as L from chainer import reporter from chainer import training from chainer.training import extensions import data import thin_stack def linearize_tree(vocab, root, xp=numpy): # Left node indexes for ...
8,430
32.724
78
py
chainer
chainer-master/examples/sentiment/data.py
import codecs import re class SexpParser(object): def __init__(self, line): self.tokens = re.findall(r'\(|\)|[^\(\) ]+', line) self.pos = 0 def parse(self): assert self.pos < len(self.tokens) token = self.tokens[self.pos] assert token != ')' self.pos += 1 ...
1,018
23.261905
58
py
chainer
chainer-master/examples/sentiment/train_sentiment.py
#!/usr/bin/env python """Sample script of recursive neural networks for sentiment analysis. This is Socher's simple recursive model, not RTNN: R. Socher, C. Lin, A. Y. Ng, and C.D. Manning. Parsing Natural Scenes and Natural Language with Recursive Neural Networks. in ICML2011. """ import argparse import colle...
8,186
34.288793
79
py
chainer
chainer-master/examples/pos/postagging.py
import argparse import collections import warnings import nltk import numpy import six import chainer from chainer import datasets import chainer.links as L from chainer import reporter from chainer import training from chainer.training import extensions class CRF(chainer.Chain): def __init__(self, n_vocab, n_...
5,391
34.946667
78
py
chainer
chainer-master/examples/tests/test_mnist.py
import os import test_utils EXAMPLES_ROOT = test_utils.EXAMPLES_ROOT def test_1(): root_dir = os.path.join(EXAMPLES_ROOT, 'mnist') output_evaluator = test_utils.TemplateOutputEvaluator( b'''\ Device: @numpy # unit: 10 # Minibatch-size: 100 # epoch: 1 epoch main/loss validation/main/loss ...
1,192
27.404762
99
py
chainer
chainer-master/examples/tests/__init__.py
0
0
0
py
chainer
chainer-master/examples/tests/test_imagenet.py
import os import test_utils EXAMPLES_ROOT = test_utils.EXAMPLES_ROOT def test_1(): root_dir = os.path.join(EXAMPLES_ROOT, 'imagenet') image_root_dir = os.path.join(root_dir, '.testdata/images') list_file = os.path.join(root_dir, '.testdata/data.txt') with test_utils.ExampleRunner(root_dir) as r: ...
692
21.354839
63
py
chainer
chainer-master/examples/vae/train_vae.py
#!/usr/bin/env python """Chainer example: train a VAE on MNIST """ import argparse import os import warnings import matplotlib.pyplot as plt import numpy as np import chainer from chainer import training from chainer.training import extensions import chainerx import net import matplotlib matplotlib.use('Agg') def...
7,083
37.291892
79
py
chainer
chainer-master/examples/vae/net.py
import numpy as np import chainer import chainer.distributions as D import chainer.functions as F import chainer.links as L from chainer import reporter class AvgELBOLoss(chainer.Chain): """Loss function of VAE. The loss value is equal to ELBO (Evidence Lower Bound) multiplied by -1. Args: ...
3,656
30.8
79
py
chainer
chainer-master/examples/wavenet/generate.py
import argparse import chainer import chainerx import librosa import numpy import tqdm from net import UpsampleNet from net import WaveNet from utils import MuLaw from utils import Preprocess parser = argparse.ArgumentParser() parser.add_argument('--input', '-i', required=True, help='input file') parser.add_argument...
3,910
35.896226
79
py
chainer
chainer-master/examples/wavenet/modules.py
import chainer import chainer.functions as F import chainer.links as L class ResidualBlock(chainer.Chain): def __init__(self, filter_size, dilation, residual_channels, dilated_channels, skip_channels): super(ResidualBlock, self).__init__() with self.init_scope(): self....
2,897
33.5
75
py
chainer
chainer-master/examples/wavenet/utils.py
import random import librosa import numpy import chainer class MuLaw(object): def __init__(self, mu=256, int_type=numpy.int32, float_type=numpy.float32): self.mu = mu self.int_type = int_type self.float_type = float_type def transform(self, x): x = x.astype(self.float_type) ...
3,031
32.688889
79
py
chainer
chainer-master/examples/wavenet/net.py
import chainer import chainer.functions as F import chainer.links as L from modules import ResidualNet class UpsampleNet(chainer.ChainList): def __init__(self, out_layers, r_channels, channels=[128, 128], upscale_factors=[16, 16]): super(UpsampleNet, self).__init__() for channel,...
3,367
34.083333
78
py
chainer
chainer-master/examples/wavenet/train.py
import argparse import os import pathlib import warnings import numpy import chainer from chainer.training import extensions import chainerx from net import EncoderDecoderModel from net import UpsampleNet from net import WaveNet from utils import Preprocess import matplotlib matplotlib.use('Agg') parser = argpars...
5,955
39.794521
79
py
chainer
chainer-master/examples/mnist/inference.py
#!/usr/bin/env python import argparse import chainer from train_mnist import MLP from train_mnist_model_parallel import ParallelMLP def main(): parser = argparse.ArgumentParser(description='Chainer example: MNIST') parser.add_argument('--device', '-d', type=str, default='-1', help='De...
2,171
32.9375
76
py
chainer
chainer-master/examples/mnist/train_mnist_custom_loop.py
#!/usr/bin/env python """Fully-connected neural network example using MNIST dataset This code is a custom loop version of train_mnist.py. That is, we train models without using the Trainer class in chainer and instead write a training loop that manually computes the loss of minibatches and applies an optimizer to upda...
5,047
36.954887
78
py
chainer
chainer-master/examples/mnist/train_mnist_model_parallel.py
#!/usr/bin/env python import argparse import chainer import chainer.functions as F import chainer.links as L from chainer import training from chainer.training import extensions import chainerx import train_mnist # Network definition class ParallelMLP(chainer.Chain): def __init__(self, n_units, n_out, device0,...
5,362
36.767606
77
py
chainer
chainer-master/examples/mnist/train_mnist_data_parallel_updater.py
#!/usr/bin/env python import argparse import chainer import chainer.links as L from chainer import training from chainer.training import extensions import chainerx import sys import train_mnist def main(): # This script is almost identical to train_mnist.py. The only difference is # that this script uses da...
3,603
40.425287
79
py
chainer
chainer-master/examples/mnist/train_mnist_data_parallel.py
#!/usr/bin/env python import argparse import chainer import chainer.links as L from chainer import training from chainer.training import extensions import chainerx import train_mnist def main(): # This script is almost identical to train_mnist.py. The only difference is # that this script uses data-parallel...
4,284
42.282828
79
py
chainer
chainer-master/examples/mnist/train_mnist.py
#!/usr/bin/env python import argparse import chainer import chainer.functions as F import chainer.links as L from chainer import training from chainer.training import extensions import chainerx import matplotlib matplotlib.use('Agg') # Network definition class MLP(chainer.Chain): def __init__(self, n_units, n_...
6,024
39.709459
79
py
chainer
chainer-master/examples/mnist/.testdata/replacements/train_mnist.py
#!/usr/bin/env python import argparse import chainer import chainer.functions as F import chainer.links as L from chainer import training from chainer.training import extensions import chainerx import matplotlib matplotlib.use('Agg') # Network definition class MLP(chainer.Chain): def __init__(self, n_units, n_...
6,131
39.609272
79
py
chainer
chainer-master/examples/pix2pix/updater.py
#!/usr/bin/env python from __future__ import print_function import chainer import chainer.functions as F class FacadeUpdater(chainer.training.StandardUpdater): def __init__(self, *args, **kwargs): self.enc, self.dec, self.dis = kwargs.pop('models') super(FacadeUpdater, self).__init__(*args, **k...
2,430
31.851351
71
py
chainer
chainer-master/examples/pix2pix/facade_visualizer.py
#!/usr/bin/env python import os from PIL import Image import chainer import chainer.cuda from chainer import Variable import numpy as np def out_image(updater, enc, dec, rows, cols, seed, dst): @chainer.training.make_extension() def make_image(trainer): np.random.seed(seed) n_images = rows *...
2,567
31.506329
78
py
chainer
chainer-master/examples/pix2pix/facade_dataset.py
from PIL import Image from chainer.dataset import dataset_mixin import numpy as np # download `BASE` dataset from http://cmp.felk.cvut.cz/~tylecr1/facade/ class FacadeDataset(dataset_mixin.DatasetMixin): def __init__(self, dataDir='./facade/base', data_range=(1, 300)): print('load dataset start') ...
1,733
36.695652
74
py
chainer
chainer-master/examples/pix2pix/net.py
#!/usr/bin/env python from __future__ import print_function import chainer import chainer.functions as F import chainer.links as L # U-net https://arxiv.org/pdf/1611.07004v1.pdf # convolution-batchnormalization-(dropout)-relu class ConvBNR(chainer.Chain): def __init__(self, ch0, ch1, use_bn=True, ...
5,072
39.584
76
py
chainer
chainer-master/examples/pix2pix/train_facade.py
#!/usr/bin/env python from __future__ import print_function import argparse import sys import warnings import numpy import chainer from chainer import training from chainer.training import extensions import chainerx from facade_dataset import FacadeDataset from facade_visualizer import out_image from net import D...
5,144
35.75
78
py
chainer
chainer-master/examples/memnn/download.py
#!/usr/bin/env python from six.moves.urllib import request def main(): request.urlretrieve( 'http://www.thespermwhale.com/jaseweston/babi/tasks_1-20_v1-2.tar.gz', 'tasks_1-20_v1-2.tar.gz') if __name__ == '__main__': main()
252
17.071429
78
py
chainer
chainer-master/examples/memnn/memnn.py
import collections import json import os import numpy import six import chainer from chainer import backend import chainer.functions as F from chainer import initializers import chainer.links as L import babi def bow_encode(embed, sentences): """BoW sentence encoder. It is defined as: .. math:: ...
7,653
28.102662
79
py
chainer
chainer-master/examples/memnn/babi.py
import collections Query = collections.namedtuple('Query', ['sentence', 'answer', 'fact']) Sentence = collections.namedtuple('Sentence', ['sentence']) def split(sentence): """Splits a sentence into words. Args: sentence (str): A sentence to split. Returns: list of str: A list of words....
2,092
22.516854
71
py
chainer
chainer-master/examples/memnn/train_memnn.py
#!/usr/bin/env python import argparse import collections import warnings import chainer from chainer.training import extensions import numpy import babi import memnn def train(train_data_path, test_data_path, args): device = chainer.get_device(args.device) device.use() vocab = collections.defaultdict...
4,288
37.990909
78
py
chainer
chainer-master/examples/memnn/test_memnn.py
#!/usr/bin/env python import argparse import numpy import chainer import babi import memnn def main(): parser = argparse.ArgumentParser( description='Chainer example: End-to-end memory networks') parser.add_argument('MODEL', help='Path to model directory specified with `-m`...
2,673
33.282051
76
py
chainer
chainer-master/examples/cifar/train_cifar_custom_loop.py
#!/usr/bin/env python """Convnet example using CIFAR10 or CIFAR100 dataset This code is a custom loop version of train_cifar.py. That is, we train models without using the Trainer class in chainer and instead write a training loop that manually computes the loss of minibatches and applies an optimizer to update the mo...
5,913
37.653595
78
py
chainer
chainer-master/examples/cifar/train_cifar.py
import argparse import chainer from chainer import backend import chainer.links as L from chainer import training from chainer.training import extensions from chainer.training import triggers from chainer.datasets import get_cifar10 from chainer.datasets import get_cifar100 import models.VGG def main(): parser...
5,155
38.968992
79
py
chainer
chainer-master/examples/cifar/models/VGG.py
import chainer import chainer.functions as F import chainer.links as L class Block(chainer.Chain): """A convolution, batch norm, ReLU block. A block in a feedforward network that performs a convolution followed by batch normalization followed by a ReLU activation. For the convolution operation,...
3,799
29.894309
76
py
chainer
chainer-master/examples/cifar/models/__init__.py
0
0
0
py
chainer
chainer-master/examples/seq2seq/seq2seq.py
#!/usr/bin/env python import argparse import datetime import io from nltk.translate import bleu_score import numpy import progressbar import six import chainer import chainer.functions as F import chainer.links as L from chainer import training from chainer.training import extensions import chainerx UNK = 0 EOS = ...
15,768
37.089372
79
py
chainer
chainer-master/examples/seq2seq/wmt_preprocess.py
#!/usr/bin/env python from __future__ import unicode_literals import argparse import collections import io import re import progressbar split_pattern = re.compile(r'([.,!?"\':;)(])') digit_pattern = re.compile(r'\d') def split_sentence(s, use_lower): if use_lower: s = s.lower() s = s.replace('\u2...
2,403
26.318182
74
py
chainer
chainer-master/examples/image_captioning/download.py
#!/usr/bin/env python import argparse import os import zipfile import progressbar from six.moves.urllib import request """Download the MSCOCO dataset (images and captions).""" urls = [ 'http://images.cocodataset.org/zips/train2014.zip', 'http://images.cocodataset.org/zips/val2014.zip', 'http://images.co...
2,087
27.60274
78
py
chainer
chainer-master/examples/image_captioning/model.py
import numpy as np import chainer from chainer import functions as F from chainer import initializers from chainer import links as L from chainer import reporter from chainer import Variable class ImageCaptionModel(chainer.Chain): """Image captioning model.""" def __init__(self, vocab_size, hidden_size=512...
10,308
34.304795
79
py
chainer
chainer-master/examples/image_captioning/datasets.py
from collections import defaultdict import os import numpy as np from PIL import Image from pycocotools.coco import COCO from chainer import dataset from chainer.dataset.convert import to_device # Vocabulary tokens of BOS (beginning of sentence), EOS (end of sentence), # UNK (unknown word) and token labels to be ig...
4,479
30.77305
78
py
chainer
chainer-master/examples/image_captioning/predict.py
#!/usr/bin/env python import argparse import glob import os import sys import numpy as np from PIL import Image import chainer from chainer import serializers import chainerx import datasets from model import ImageCaptionModel def main(): parser = argparse.ArgumentParser() parser.add_argument('--img', type...
3,640
35.049505
79
py
chainer
chainer-master/examples/image_captioning/train.py
#!/usr/bin/env python import argparse import chainer from chainer.datasets import TransformDataset from chainer import iterators from chainer import optimizers from chainer import training from chainer.training import extensions import datasets from model import ImageCaptionModel import matplotlib matplotlib.use('Ag...
6,564
38.311377
79
py
chainer
chainer-master/examples/modelzoo/download_model.py
#!/usr/bin/env python import argparse import zipfile import six parser = argparse.ArgumentParser( description='Download a Caffe reference model') parser.add_argument('model_type', choices=('alexnet', 'caffenet', 'googlenet', 'resnet'), help='Model type (alexnet, caffenet, ...
1,438
33.261905
76
py
chainer
chainer-master/examples/modelzoo/download_mean_file.py
#!/usr/bin/env python import six print('Downloading ILSVRC12 mean file for NumPy...') six.moves.urllib.request.urlretrieve( 'https://github.com/BVLC/caffe/raw/master/python/caffe/imagenet/' 'ilsvrc_2012_mean.npy', 'ilsvrc_2012_mean.npy') print('Done')
266
23.272727
69
py
chainer
chainer-master/examples/modelzoo/evaluate_caffe_net.py
#!/usr/bin/env python """Example code of evaluating a Caffe reference model for ILSVRC2012 task. Prerequisite: To run this example, crop the center of ILSVRC2012 validation images and scale them to 256x256, and make a list of space-separated CSV each column of which contains a full path to an image at the fist column ...
4,652
31.767606
79
py
chainer
chainer-master/examples/static_graph_optimizations/ptb/train_ptb_custom_loop.py
"""Recurrent neural network language model with static graph optimizations. This is a modified version of the standard Chainer Penn Tree Bank (ptb) example that includes static subgraph optimizations. It is mostly unchanged from the original model except that that the RNN is unrolled for `bproplen` slices inside of a ...
12,422
36.759878
79
py
chainer
chainer-master/examples/static_graph_optimizations/mnist/train_mnist_custom_loop.py
"""MNIST example with static subgraph optimizations. This is a version of the Chainer MNIST example that has been modified to support the static subgraph optimizations feature. Note that the code is mostly unchanged except for the addition of the `@static_graph` decorator to the model chain's `__call__()` method. Thi...
5,773
36.738562
77
py
chainer
chainer-master/examples/static_graph_optimizations/mnist/train_mnist.py
"""MNIST example with static subgraph optimizations. This is a version of the Chainer MNIST example that has been modified to support the static subgraph optimizations feature. Note that the code is mostly unchanged except for the addition of the `@static_graph` decorator to the model chain's `__call__()` method. Not...
7,909
36.13615
79
py
chainer
chainer-master/examples/static_graph_optimizations/cifar/train_cifar_custom_loop.py
"""CIFAR example with static subgraph optimizations. This is a version of the Chainer CIFAR example that has been modified to support the static subgraph optimizations feature. Note that the code is mostly unchanged except for the addition of the `@static_graph` decorator to the model chain's `__call__()` method. Thi...
6,633
37.126437
77
py
chainer
chainer-master/examples/static_graph_optimizations/cifar/train_cifar.py
"""CIFAR example with static subgraph optimizations. This is a version of the Chainer CIFAR example that has been modified to support the static subgraph optimizations feature. Note that the code is mostly unchanged except for the addition of the `@static_graph` decorator to the model chain's `__call__()` method. """ ...
5,864
38.1
79
py
chainer
chainer-master/examples/static_graph_optimizations/cifar/models/VGG.py
import chainer import chainer.functions as F import chainer.links as L from chainer import static_graph class Block(chainer.Chain): """A convolution, batch norm, ReLU block. A block in a feedforward network that performs a convolution followed by batch normalization followed by a ReLU activation. ...
3,852
29.824
76
py
chainer
chainer-master/examples/static_graph_optimizations/cifar/models/__init__.py
0
0
0
py
chainer
chainer-master/examples/glance/glance.py
# Note for contributors: # This example code is referred to from "Chainer at a Glance" tutorial. # If this file is to be modified, please also update the line numbers in # `docs/source/glance.rst` accordingly. import chainer as ch from chainer import datasets import chainer.functions as F import chainer.links as L fro...
2,876
30.271739
78
py
chainer
chainer-master/examples/serialization/model.py
import chainer import chainer.functions as F import chainer.links as L import numpy as np class MLP(chainer.Chain): def __init__(self, n_in=784, n_units=100, n_out=10): super(MLP, self).__init__() with self.init_scope(): # the size of the inputs to each layer will be inferred ...
701
29.521739
70
py
chainer
chainer-master/examples/serialization/save.py
import chainer import h5py import numpy as np import model # Create a model object first model = model.MLP() def save_parameters_as_npz(model, filename='model.npz'): # Save the model parameters into a NPZ file chainer.serializers.save_npz(filename, model) print('{} saved!\n'.format(filename)) # Loa...
1,422
30.622222
65
py
chainer
chainer-master/examples/serialization/load.py
import chainer import numpy as np import model def load_npz_file_to_model(npz_filename='model.npz'): # Create model object first model1 = model.MLP() # Load the saved parameters into the model object chainer.serializers.load_npz(npz_filename, model1) print('{} loaded!'.format(npz_filename)) ...
1,000
25.342105
69
py
chainer
chainer-master/chainermn/global_except_hook.py
import os import sys import warnings _orig_except_hook = None def _global_except_hook(exctype, value, traceback): """Catches an unhandled exception and call MPI_Abort().""" try: if _orig_except_hook: _orig_except_hook(exctype, value, traceback) else: sys.__excepthook_...
2,716
34.75
78
py
chainer
chainer-master/chainermn/nccl.py
try: from cupy.cuda.nccl import get_build_version # NOQA from cupy.cuda.nccl import get_unique_id # NOQA from cupy.cuda.nccl import get_version # NOQA from cupy.cuda.nccl import NCCL_FLOAT # NOQA from cupy.cuda.nccl import NCCL_FLOAT16 # NOQA from cupy.cuda.nccl import NCCL_FLOAT32 # NOQA ...
588
38.266667
56
py
chainer
chainer-master/chainermn/optimizers.py
import chainer import copy class _MultiNodeOptimizer(object): def __init__(self, actual_optimizer, communicator, zero_fill): super(_MultiNodeOptimizer, self).__setattr__( 'communicator', communicator) super(_MultiNodeOptimizer, self).__setattr__( 'actual_optimizer', actual...
7,436
39.639344
79
py
chainer
chainer-master/chainermn/__init__.py
import chainer from chainermn import communicators # NOQA from chainermn import datasets # NOQA from chainermn import extensions # NOQA from chainermn import functions # NOQA from chainermn import global_except_hook # NOQA from chainermn import iterators # NOQA from chainermn import links # NOQA from chainermn ...
976
38.08
71
py
chainer
chainer-master/chainermn/functions/pseudo_connect.py
import chainer from chainer import backend import chainer.utils class PseudoConnect(chainer.FunctionNode): """Connect a variable to a delegating variable.""" def forward(self, inputs): self.retain_inputs((0,)) # delegate_variable = inputs[0] actual_variables = inputs[1:] retur...
6,895
46.232877
79
py
chainer
chainer-master/chainermn/functions/collective_communication.py
import chainer from chainer import backend import numpy class AllGather(chainer.Function): """Collective all-gather communication.""" def __init__(self, comm): chainer.utils.experimental('chainermn.functions.AllGather') self.comm = comm def forward(self, inputs): x, = inputs ...
12,921
31.224439
84
py
chainer
chainer-master/chainermn/functions/point_to_point_communication.py
import chainer from chainer import backend import chainer.utils class Send(chainer.Function): """Send elements to target process.""" def __init__(self, comm, peer_rank, peer_tag): chainer.utils.experimental('chainermn.functions.Send') self.comm = comm self.peer_rank = peer_rank ...
6,903
33.178218
84
py
chainer
chainer-master/chainermn/functions/__init__.py
from chainermn.functions.collective_communication import allgather # NOQA from chainermn.functions.collective_communication import alltoall # NOQA from chainermn.functions.collective_communication import bcast # NOQA from chainermn.functions.collective_communication import gather # NOQA from chainermn.functions.col...
585
52.272727
74
py
chainer
chainer-master/chainermn/functions/batch_normalization.py
import chainer from chainer.backends import cuda from chainer.functions.normalization import batch_normalization import chainer.utils class _MpiImpl(batch_normalization.GeneralBatchNormalizationImpl): def __init__(self, comm): self.comm = comm def get_mean_and_var(self, axis, gamma, x, xp, interm_dty...
5,424
41.382813
79
py
chainer
chainer-master/chainermn/testing/__init__.py
from chainermn.testing.device import get_device # NOQA
56
27.5
55
py
chainer
chainer-master/chainermn/testing/device.py
import chainer def get_device(device_id=None, use_chainerx=False): """Get device object Currently in Chainer, there are 3 officially-supported backends (numpy, cupy, and chainerx) and 2 devices (CPU and NVIDIA GPUs). Also, ChainerX has its own backend system, so there are 4 combinations (numpy, c...
771
29.88
74
py
chainer
chainer-master/chainermn/links/create_mnbn_model.py
import copy import chainer import chainermn def create_mnbn_model(link, comm, communication_backend='auto'): """Create a link object with MultiNodeBatchNormalization. Returns a copy of `link`, where BatchNormalization is replaced by MultiNodeBatchNormalization. Args: link: Link object ...
2,340
33.940299
78
py
chainer
chainer-master/chainermn/links/multi_node_chain_list.py
from six.moves import queue import chainer import chainermn import chainermn.communicators import chainermn.functions class MultiNodeChainList(chainer.ChainList): """Combining multiple non-connected components of computational graph. This class combines each ``chainer.Chain``, which represents one of the ...
10,526
37.56044
79
py
chainer
chainer-master/chainermn/links/__init__.py
from chainermn.links.batch_normalization import MultiNodeBatchNormalization # NOQA from chainermn.links.create_mnbn_model import create_mnbn_model # NOQA from chainermn.links.multi_node_chain_list import MultiNodeChainList # NOQA from chainermn.links.n_step_rnn import create_multi_node_n_step_rnn # NOQA
309
61
83
py
chainer
chainer-master/chainermn/links/n_step_rnn.py
import chainer import chainer.links.rnn as rnn import chainermn.functions class _MultiNodeNStepRNN(chainer.Chain): def __init__(self, link, communicator, rank_in, rank_out): super(_MultiNodeNStepRNN, self).__init__(actual_rnn=link) self.communicator = communicator self.rank_in = rank_in ...
3,181
36
78
py
chainer
chainer-master/chainermn/links/batch_normalization.py
import chainer from chainer.backends import cuda from chainer.functions.normalization import batch_normalization from chainer import initializers from chainer import link import chainer.utils from chainer import variable from chainermn.functions import batch_normalization as \ chainermn_batch_normalization import ...
5,709
37.581081
78
py