Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/dnn/test/imagenet_cls_test_googlenet.py
16347 views
1
import numpy as np
2
import sys
3
import os
4
import argparse
5
from imagenet_cls_test_alexnet import MeanChannelsFetch, CaffeModel, DnnCaffeModel, ClsAccEvaluation
6
try:
7
import caffe
8
except ImportError:
9
raise ImportError('Can\'t find Caffe Python module. If you\'ve built it from sources without installation, '
10
'configure environment variable PYTHONPATH to "git/caffe/python" directory')
11
try:
12
import cv2 as cv
13
except ImportError:
14
raise ImportError('Can\'t find OpenCV Python module. If you\'ve built it from sources without installation, '
15
'configure environment variable PYTHONPATH to "opencv_build_dir/lib" directory (with "python3" subdirectory if required)')
16
17
if __name__ == "__main__":
18
parser = argparse.ArgumentParser()
19
parser.add_argument("--imgs_dir", help="path to ImageNet validation subset images dir, ILSVRC2012_img_val dir")
20
parser.add_argument("--img_cls_file", help="path to file with classes ids for images, val.txt file from this "
21
"archive: http://dl.caffe.berkeleyvision.org/caffe_ilsvrc12.tar.gz")
22
parser.add_argument("--prototxt", help="path to caffe prototxt, download it here: "
23
"https://github.com/BVLC/caffe/blob/master/models/bvlc_alexnet/deploy.prototxt")
24
parser.add_argument("--caffemodel", help="path to caffemodel file, download it here: "
25
"http://dl.caffe.berkeleyvision.org/bvlc_alexnet.caffemodel")
26
parser.add_argument("--log", help="path to logging file")
27
parser.add_argument("--batch_size", help="size of images in batch", default=500, type=int)
28
parser.add_argument("--frame_size", help="size of input image", default=224, type=int)
29
parser.add_argument("--in_blob", help="name for input blob", default='data')
30
parser.add_argument("--out_blob", help="name for output blob", default='prob')
31
args = parser.parse_args()
32
33
data_fetcher = MeanChannelsFetch(args.frame_size, args.imgs_dir)
34
35
frameworks = [CaffeModel(args.prototxt, args.caffemodel, args.in_blob, args.out_blob),
36
DnnCaffeModel(args.prototxt, args.caffemodel, '', args.out_blob)]
37
38
acc_eval = ClsAccEvaluation(args.log, args.img_cls_file, args.batch_size)
39
acc_eval.process(frameworks, data_fetcher)
40
41