MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / run_test

Function run_test

examples/CaffeModels/load-vgg16.py:57–84  ·  view source on GitHub ↗
(path, input)

Source from the content-addressed store, hash-verified

55
56
57def run_test(path, input):
58 param_dict = dict(np.load(path))
59 param_dict = {k.replace('/W', '/kernel').replace('/b', '/bias'): v for k, v in six.iteritems(param_dict)}
60
61 predict_func = OfflinePredictor(PredictConfig(
62 input_signature=[tf.TensorSpec((None, 224, 224, 3), tf.float32, 'input')],
63 tower_func=tower_func,
64 session_init=SmartInit(param_dict),
65 input_names=['input'],
66 output_names=['prob'] # prob:0 is the probability distribution
67 ))
68
69 im = cv2.imread(input)
70 assert im is not None, input
71 im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
72 im = cv2.resize(im, (224, 224)).reshape((1, 224, 224, 3)).astype('float32')
73
74 # VGG16 requires channelwise mean substraction
75 VGG_MEAN = [103.939, 116.779, 123.68]
76 im -= VGG_MEAN[::-1]
77
78 outputs = predict_func(im)[0]
79 prob = outputs[0]
80 ret = prob.argsort()[-10:][::-1]
81 print("Top10 predictions:", ret)
82
83 meta = ILSVRCMeta().get_synset_words_1000()
84 print("Top10 class names:", [meta[k] for k in ret])
85
86
87if __name__ == '__main__':

Callers 1

load-vgg16.pyFile · 0.70

Calls 6

ILSVRCMetaClass · 0.90
OfflinePredictorClass · 0.85
PredictConfigClass · 0.85
SmartInitFunction · 0.85
get_synset_words_1000Method · 0.80
loadMethod · 0.45

Tested by

no test coverage detected