MCPcopy Create free account
hub / github.com/tensorpack/tensorpack / run_image

Function run_image

examples/DoReFa-Net/resnet-dorefa.py:117–141  ·  view source on GitHub ↗
(model, sess_init, inputs)

Source from the content-addressed store, hash-verified

115
116
117def run_image(model, sess_init, inputs):
118 pred_config = PredictConfig(
119 model=model,
120 session_init=sess_init,
121 input_names=['input'],
122 output_names=['output']
123 )
124 predict_func = OfflinePredictor(pred_config)
125 meta = dataset.ILSVRCMeta()
126 words = meta.get_synset_words_1000()
127
128 transformers = get_inference_augmentor()
129 for f in inputs:
130 assert os.path.isfile(f)
131 img = cv2.imread(f).astype('float32')
132 assert img is not None
133
134 img = transformers.augment(img)[np.newaxis, :, :, :]
135 o = predict_func(img)
136 prob = o[0][0]
137 ret = prob.argsort()[-10:][::-1]
138
139 names = [words[i] for i in ret]
140 print(f + ":")
141 print(list(zip(names, prob[ret])))
142
143
144if __name__ == '__main__':

Callers 1

resnet-dorefa.pyFile · 0.70

Calls 5

get_synset_words_1000Method · 0.95
PredictConfigClass · 0.85
OfflinePredictorClass · 0.85
augmentMethod · 0.80
get_inference_augmentorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…