Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify content 01/003/02 #28

Merged
merged 2 commits into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions 003cnn/002/002.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from chainer import training
from chainer.training import extensions
import numpy as np
import argparse

train, test = chainer.datasets.get_cifar100()
train, test = chainer.datasets.get_cifar10()

class MLP(chainer.Chain):

Expand All @@ -25,11 +24,6 @@ def __call__(self, x):
h2 = F.relu(self.l2(h1))
return self.l3(h2)

parser = argparse.ArgumentParser(description='Chainer example: MNIST')
parser.add_argument('--gpu', '-g', type=int, default=-1,
help='GPU ID (negative value indicates CPU)')
args = parser.parse_args()


batchsize = 100
train_iter = chainer.iterators.SerialIterator(train, batchsize)
Expand All @@ -38,8 +32,9 @@ def __call__(self, x):

model = L.Classifier(MLP(784, 10))

if args.gpu >= 0:
chainer.cuda.get_device(args.gpu).use() # Make a specified GPU current
gpu = -1
if gpu >= 0:
chainer.cuda.get_device(gpu).use() # Make a specified GPU current
model.to_gpu() # Copy the model to the GPU

opt = chainer.optimizers.Adam()
Expand All @@ -49,11 +44,11 @@ def __call__(self, x):
epoch = 10

# Set up a trainer
updater = training.StandardUpdater(train_iter, opt, device=args.gpu)
trainer = training.Trainer(updater, (epoch, 'epoch'), out='result')
updater = training.StandardUpdater(train_iter, opt, device=gpu)
trainer = training.Trainer(updater, (epoch, 'epoch'), out='/tmp/result')

# Evaluate the model with the test dataset for each epoch
trainer.extend(extensions.Evaluator(test_iter, model, device=args.gpu))
trainer.extend(extensions.Evaluator(test_iter, model, device=gpu))

# Dump a computational graph from 'loss' variable at the first iteration
# The "main" refers to the target link of the "main" optimizer.
Expand Down
1 change: 1 addition & 0 deletions 003cnn/002/metadata.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
uuid: 453D8CBB-9ABC-4F3D-9798-EAFBA1DD5EF3
timeout: 15m