Path: blob/master/modules/dnn/test/imagenet_cls_test_googlenet.py
16347 views
import numpy as np1import sys2import os3import argparse4from imagenet_cls_test_alexnet import MeanChannelsFetch, CaffeModel, DnnCaffeModel, ClsAccEvaluation5try:6import caffe7except ImportError:8raise ImportError('Can\'t find Caffe Python module. If you\'ve built it from sources without installation, '9'configure environment variable PYTHONPATH to "git/caffe/python" directory')10try:11import cv2 as cv12except ImportError:13raise ImportError('Can\'t find OpenCV Python module. If you\'ve built it from sources without installation, '14'configure environment variable PYTHONPATH to "opencv_build_dir/lib" directory (with "python3" subdirectory if required)')1516if __name__ == "__main__":17parser = argparse.ArgumentParser()18parser.add_argument("--imgs_dir", help="path to ImageNet validation subset images dir, ILSVRC2012_img_val dir")19parser.add_argument("--img_cls_file", help="path to file with classes ids for images, val.txt file from this "20"archive: http://dl.caffe.berkeleyvision.org/caffe_ilsvrc12.tar.gz")21parser.add_argument("--prototxt", help="path to caffe prototxt, download it here: "22"https://github.com/BVLC/caffe/blob/master/models/bvlc_alexnet/deploy.prototxt")23parser.add_argument("--caffemodel", help="path to caffemodel file, download it here: "24"http://dl.caffe.berkeleyvision.org/bvlc_alexnet.caffemodel")25parser.add_argument("--log", help="path to logging file")26parser.add_argument("--batch_size", help="size of images in batch", default=500, type=int)27parser.add_argument("--frame_size", help="size of input image", default=224, type=int)28parser.add_argument("--in_blob", help="name for input blob", default='data')29parser.add_argument("--out_blob", help="name for output blob", default='prob')30args = parser.parse_args()3132data_fetcher = MeanChannelsFetch(args.frame_size, args.imgs_dir)3334frameworks = [CaffeModel(args.prototxt, args.caffemodel, args.in_blob, args.out_blob),35DnnCaffeModel(args.prototxt, args.caffemodel, '', args.out_blob)]3637acc_eval = ClsAccEvaluation(args.log, args.img_cls_file, args.batch_size)38acc_eval.process(frameworks, data_fetcher)394041