(path, input)
| 37 | |
| 38 | |
| 39 | def run_test(path, input): |
| 40 | predictor = OfflinePredictor(PredictConfig( |
| 41 | input_signature=[tf.TensorSpec((None, 227, 227, 3), tf.float32, 'input')], |
| 42 | tower_func=tower_func, |
| 43 | session_init=SmartInit(path), |
| 44 | input_names=['input'], |
| 45 | output_names=['prob'] |
| 46 | )) |
| 47 | |
| 48 | im = cv2.imread(input) |
| 49 | assert im is not None, input |
| 50 | im = cv2.resize(im, (227, 227))[None, :, :, ::-1].astype('float32') - 110 |
| 51 | outputs = predictor(im)[0] |
| 52 | prob = outputs[0] |
| 53 | ret = prob.argsort()[-10:][::-1] |
| 54 | print("Top10 predictions:", ret) |
| 55 | |
| 56 | meta = ILSVRCMeta().get_synset_words_1000() |
| 57 | print("Top10 class names:", [meta[k] for k in ret]) |
| 58 | |
| 59 | |
| 60 | if __name__ == '__main__': |
no test coverage detected