Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
improve eval_imagenet
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyu2172 committed Jun 14, 2017
1 parent 2d4c45e commit 33f46db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 37 deletions.
33 changes: 0 additions & 33 deletions examples/classification/convert_from_caffe.py

This file was deleted.

17 changes: 13 additions & 4 deletions examples/classification/eval_imagenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@

import chainer
import chainer.links as L
import chainer.functions as F
from chainer import iterators
from chainer import training
from chainer.training import extensions

from chainercv.datasets import ImageFolderDataset
from chainercv.links import VGG16Layers

from chainercv.utils import apply_prediction_to_iterator


def main():
parser = argparse.ArgumentParser(
Expand All @@ -26,15 +29,21 @@ def main():
dataset, args.batchsize, repeat=False, shuffle=False,
n_processes=4)

model = L.Classifier(VGG16Layers())
model = VGG16Layers()

if args.gpu >= 0:
chainer.cuda.get_device(args.gpu).use()
model.to_gpu()


result = extensions.Evaluator(iterator, model)
print result
imgs, pred_values, gt_values = apply_prediction_to_iterator(model.predict, iterator)
del imgs

pred_labels, = pred_values
gt_labels, = gt_values

accuracy = F.accuracy(
np.array(list(pred_labels)), np.array(list(gt_labels))).data
print accuracy


if __name__ == '__main__':
Expand Down

0 comments on commit 33f46db

Please sign in to comment.