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

Function run_image

examples/DoReFa-Net/alexnet-dorefa.py:167–191  ·  view source on GitHub ↗
(model, sess_init, inputs)

Source from the content-addressed store, hash-verified

165
166
167def run_image(model, sess_init, inputs):
168 pred_config = PredictConfig(
169 model=model,
170 session_init=sess_init,
171 input_names=['input'],
172 output_names=['output']
173 )
174 predictor = OfflinePredictor(pred_config)
175 meta = dataset.ILSVRCMeta()
176 words = meta.get_synset_words_1000()
177
178 transformers = imgaug.AugmentorList(fbresnet_augmentor(isTrain=False))
179 for f in inputs:
180 assert os.path.isfile(f), f
181 img = cv2.imread(f).astype('float32')
182 assert img is not None
183
184 img = transformers.augment(img)[np.newaxis, :, :, :]
185 outputs = predictor(img)[0]
186 prob = outputs[0]
187 ret = prob.argsort()[-10:][::-1]
188
189 names = [words[i] for i in ret]
190 print(f + ":")
191 print(list(zip(names, prob[ret])))
192
193
194if __name__ == '__main__':

Callers 1

alexnet-dorefa.pyFile · 0.70

Calls 5

get_synset_words_1000Method · 0.95
fbresnet_augmentorFunction · 0.90
PredictConfigClass · 0.85
OfflinePredictorClass · 0.85
augmentMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…