From 73f578490dcf44c726b5382376b7e8a3d3c200df Mon Sep 17 00:00:00 2001 From: pyhqos7bg Date: Thu, 30 May 2024 15:11:30 +0800 Subject: [PATCH] ADD file via upload --- model_predict.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 model_predict.py diff --git a/model_predict.py b/model_predict.py new file mode 100644 index 0000000..e58fc4f --- /dev/null +++ b/model_predict.py @@ -0,0 +1,26 @@ +from PIL import Image +import paddle.fluid as fluid +import numpy as np +from 手势识别.build_model import FullNet_Model +def load_image(path): + img =Image.open(path) + img = img.resize((100,100),Image.ANTIALIAS) + img = np.array(img).astype('float32') + img = img.transpose(2,0,1) + img = img/255.0 + print(img.shape) + return img +with fluid.dygraph.guard(): + infer_path ='test.jpg' + model = FullNet_Model() + model_dict,_ =fluid.load_dygraph('./FullNet_Model') + model.load_dict(model_dict) + + model.eval() #开启评估模式 + + infer_image = load_image(infer_path) + infer_image = infer_image[np.newaxis,:,:,:] + infer_image =fluid.dygraph.to_variable(infer_image) + + result = model(infer_image) + print(np.argmax(result.numpy())) \ No newline at end of file