jetson nano上用paddle_inference推理ppyolov2模型报错
paddlepaddle2.1-gpu环境已经配好 模型用paddlex导出, --fixed_input_shape=[1,3,224,224] 在使用inference推理的时候报如下错误 InvalidArgumentError: The Tensor in the conv2d_fusion Op's Input Variable Input(image) is not initialized. [Hint: Expected t->IsInitialized() == true, but received t->IsInitialized():0 != true:1.] (at /home/paddle/data/wangye19/Paddle/paddle/fluid/framework/operator.cc:1570) [operator < conv2d_fusion > error] 推理代码如下: import numpy as np import argparse import cv2 import time
from paddle.inference import Config from paddle.inference import create_predictor from paddle.inference import PrecisionType from img_preprocess import preprocess
def parse_args(): parser = argparse.ArgumentParser() parser.add_argument( "--model_dir", type=str, default="", help= "Model dir, If you load a non-combined model, specify the directory of the model." ) parser.add_argument( "--model_file", type=str, default="fire2/model.pdmodel", help="Model filename, Specify this when your model is a combined model." ) parser.add_argument( "--params_file", type=str, default="fire2/model.pdiparams", help= "Parameter filename, Specify this when your model is a combined model." ) parser.add_argument("--img_path", type=str, default="", help="Input image path.") parser.add_argument("--threads", type=int, default=1, help="Whether use gpu.") return parser.parse_args()
if name == 'main':
args = parse_args()
assert (args.model_dir != "") or
(args.model_file != "" and args.params_file != ""),
"Set model path error."
assert args.img_path != "", "Set img_path error."
# Init config
if args.model_dir == "":
config = Config(args.model_file, args.params_file)
else:
config = Config(args.model_dir)
#config.enable_use_gpu(100, 0)
#print("**************",config.fraction_of_gpu_memory_for_pool()*100)
config.switch_ir_optim()
config.enable_memory_optim()
#config.enable_tensorrt_engine(workspace_size=1 << 30, precision_mode=PrecisionType.Float32,max_batch_size=1, min_subgraph_size=5, use_static=True, use_calib_mode=False)
# Create predictor
predictor = create_predictor(config)
print('*****************')
# Set input
img = cv2.imread(args.img_path)
img = preprocess(img)
#cv2.imshow('img',img)
#cv2.waitKey(0)
input_names = predictor.get_input_names()
print(input_names)
input_tensor = predictor.get_input_handle(input_names[0])
input_tensor.reshape(img.shape)
print(img.shape)
input_tensor.copy_from_cpu(np.random.randn(1,3,224,224).astype('float32'))
print(input_tensor)
# Run
a=time.time()
predictor.run()
b=time.time()
print('inference time: ',(b-a)*1000,'ms')
# Set output
output_names = predictor.get_output_names()
output_tensor = predictor.get_output_handle(output_names[0])
output_data = output_tensor.copy_to_cpu()
print("Predict class index: ", output_data)
您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档、常见问题、历史Issue、AI社区来寻求解答。祝您生活愉快~
Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the API,FAQ,Github Issue and AI community to get the answer.Have a nice day!
@wyh669 输入不太对,参考这个改下吧:https://github.com/PaddlePaddle/Paddle-Inference-Demo/tree/master/python/yolov3