|
|
|
|
|
|
|
|
|
|
|
|
|
import argparse |
|
|
|
import numpy as np |
|
import cv2 as cv |
|
|
|
from ppresnet import PPResNet |
|
|
|
def str2bool(v): |
|
if v.lower() in ['on', 'yes', 'true', 'y', 't']: |
|
return True |
|
elif v.lower() in ['off', 'no', 'false', 'n', 'f']: |
|
return False |
|
else: |
|
raise NotImplementedError |
|
|
|
parser = argparse.ArgumentParser(description='Deep Residual Learning for Image Recognition (https://arxiv.org/abs/1512.03385, https://github.com/PaddlePaddle/PaddleHub)') |
|
parser.add_argument('--input', '-i', type=str, help='Path to the input image.') |
|
parser.add_argument('--model', '-m', type=str, default='image_classification_ppresnet50_2021oct.onnx', help='Path to the model.') |
|
args = parser.parse_args() |
|
|
|
if __name__ == '__main__': |
|
|
|
model = PPResNet(modelPath=args.model) |
|
|
|
|
|
image = cv.imread(args.input) |
|
image = cv.cvtColor(image, cv.COLOR_BGR2RGB) |
|
image = cv.resize(image, dsize=(256, 256)) |
|
image = image[16:240, 16:240, :] |
|
|
|
|
|
result = model.infer(image) |
|
|
|
|
|
print('label: {}'.format(result)) |