diff --git a/examples/classification/convert_from_caffe.py b/examples/classification/convert_from_caffe.py deleted file mode 100644 index 9f6ddb3926..0000000000 --- a/examples/classification/convert_from_caffe.py +++ /dev/null @@ -1,33 +0,0 @@ -from chainer.links import VGG16Layers as VGG16Layers_chainer -import chainer - -from chainercv.links import VGG16Layers as VGG16Layers_cv - - -if __name__ == '__main__': - chainer_model = VGG16Layers_chainer() - cv_model = VGG16Layers_cv() - - cv_model.conv1_1.copyparams(chainer_model.conv1_1) - - # The pretrained weights are trained to accept BGR images. - # Convert weights so that they accept RGB images. - cv_model.conv1_1.W.data[:] = cv_model.conv1_1.W.data[:, ::-1] - - cv_model.conv1_2.copyparams(chainer_model.conv1_2) - cv_model.conv2_1.copyparams(chainer_model.conv2_1) - cv_model.conv2_2.copyparams(chainer_model.conv2_2) - cv_model.conv3_1.copyparams(chainer_model.conv3_1) - cv_model.conv3_2.copyparams(chainer_model.conv3_2) - cv_model.conv3_3.copyparams(chainer_model.conv3_3) - cv_model.conv4_1.copyparams(chainer_model.conv4_1) - cv_model.conv4_2.copyparams(chainer_model.conv4_2) - cv_model.conv4_3.copyparams(chainer_model.conv4_3) - cv_model.conv5_1.copyparams(chainer_model.conv5_1) - cv_model.conv5_2.copyparams(chainer_model.conv5_2) - cv_model.conv5_3.copyparams(chainer_model.conv5_3) - cv_model.fc6.copyparams(chainer_model.fc6) - cv_model.fc7.copyparams(chainer_model.fc7) - cv_model.fc8.copyparams(chainer_model.fc8) - - chainer.serializers.save_npz('vgg_from_caffe.npz', cv_model) diff --git a/examples/classification/eval_imagenet.py b/examples/classification/eval_imagenet.py index 8548ac1d38..7ecb81cd1c 100644 --- a/examples/classification/eval_imagenet.py +++ b/examples/classification/eval_imagenet.py @@ -5,6 +5,7 @@ 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 @@ -12,6 +13,8 @@ from chainercv.datasets import ImageFolderDataset from chainercv.links import VGG16Layers +from chainercv.utils import apply_prediction_to_iterator + def main(): parser = argparse.ArgumentParser( @@ -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__':