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

Function run_test

examples/CaffeModels/load-vgg19.py:60–86  ·  view source on GitHub ↗
(path, input)

Source from the content-addressed store, hash-verified

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

Callers 1

load-vgg19.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