yeyupiaoling/PP-YOLOE

How to do inference with batch_size > 1 ?

sinjhih opened this issue · 2 comments

您好, 目前使用infer.py可以進行batch_size=1的預測
請問有辦法使其進行batch_size>1的預測嗎?
謝謝

@sinjhih 你可以看下這個
https://github.com/yeyupiaoling/PP-YOLO/blob/974d0410c13e4381247b81ef21e0cd9097c5c91a/infer_path.py#L53

這個代碼是把圖像(608, 608, 3)變成(1, 608, 608, 3),其實這個1就是代表一張的意思,你可以改成list,將多張圖像append到這個list就好。

@yeyupiaoling 謝謝您的回覆
我試著將
img = np.expand_dims(img, axis=0).astype(np.float32)
改成
1.
all_img = []
all_img.append(img)
all_img.append(img)
all_img = np.array(all_img).astype(np.float32)
2.
img1 = np.expand_dims(img, axis=0).astype(np.float32)
img = np.concatenate((img1,img1),axis=0)
這兩種改法都讓圖像變為 (2,3,608,608)
但運行時都出現以下錯誤
InvalidArgumentError: The 0-th dimension of input[0] and input[1] is expected to be equal.But received input[0]'s shape = [2, 2048, 19, 19], input[1]'s shape = [1, 1, 19, 19].
[Hint: Expected inputs_dims[0][j] == inputs_dims[i][j], but received inputs_dims[0][j]:2 != inputs_dims[i][j]:1.] at (/paddle/paddle/fluid/operators/concat_op.h:63)
[operator < concat > error]
請問可以如何修正?
另外 im_size = np.array([[img.shape[0], img.shape[1]]]).astype(np.int32)
若batch_size改變, im_size是否需要做修改?
謝謝