(model, sess_init, inputs)
| 115 | |
| 116 | |
| 117 | def 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 | |
| 144 | if __name__ == '__main__': |
no test coverage detected
searching dependent graphs…