【发布时间】:2021-08-14 01:22:14
【问题描述】:
从下面的 codw 传递 1 张图像时,我得到的形状是 (1,3,640,640)。
def shape(im1):
image_src = Image.open(im1)
print('Loaded Image Info : ',image_src.format, image_src.size, image_src.mode) # size order : width*height
# Resize to img_size_w, img_size_h
resized = image_src.resize((640, 640)) # To be imblemnated : letterbox_image(image_src, (img_size_w, img_size_h))
print('After resizing :' ,resized.size, resized.mode) # size order : width*height
#display(resized)
# Preprocess the image
img_in = np.transpose(resized, (2, 0, 1)).astype(np.float32) # HWC -> CHW
img_in = np.expand_dims(img_in, axis=0) # Add redundant dimension for batch-size (Assumed to be 1, check batch_size = session.get_inputs()[0].shape[0])
img_in /= 255.0 # Normalize all pixels
print('Batch-Size, Channel, Height, Width : ',img_in.shape)
return img_in
在代码中进行哪些更改,以便在传递 2 张图像时将它们堆叠在一起并给出形状为 (2,3,640,640)。
【问题讨论】: