(model, sess_init, inputs)
| 165 | |
| 166 | |
| 167 | def 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 | |
| 194 | if __name__ == '__main__': |
no test coverage detected
searching dependent graphs…