Esempio n. 1
0
def main(args):
    # Inference single image by native apis.
    model = init_model(args.config, args.checkpoint, device=args.device)
    model_result = inference_model(model, args.img)
    show_result_pyplot(model, args.img, model_result, title='pytorch_result')

    # Inference single image by torchserve engine.
    url = 'http://' + args.inference_addr + '/predictions/' + args.model_name
    with open(args.img, 'rb') as image:
        response = requests.post(url, image)
    server_result = response.json()
    show_result_pyplot(model, args.img, server_result, title='server_result')

    assert np.allclose(model_result['pred_score'], server_result['pred_score'])
    print('Test complete, the results of PyTorch and TorchServe are the same.')
Esempio n. 2
0
def main():
    parser = ArgumentParser()
    parser.add_argument('img', help='Image file')
    parser.add_argument('config', help='Config file')
    parser.add_argument('checkpoint', help='Checkpoint file')
    parser.add_argument('--device',
                        default='cuda:0',
                        help='Device used for inference')
    args = parser.parse_args()

    # build the model from a config file and a checkpoint file
    model = init_model(args.config, args.checkpoint, device=args.device)
    # test a single image
    result = inference_model(model, args.img)
    # print result on terminal
    print(result)
 def inference(self, data, *args, **kwargs):
     results = []
     for image in data:
         results.append(inference_model(self.model, image))
     return results