segment-anything icon indicating copy to clipboard operation
segment-anything copied to clipboard

onnx inference:ValueError: cannot reshape array of size 8640000 into shape (1200,1800,1)

Open likecv opened this issue 2 years ago • 3 comments

ValueError Traceback (most recent call last) in <cell line: 3>() 1 plt.figure(figsize=(10,10)) 2 plt.imshow(image) ----> 3 show_mask(masks, plt.gca()) 4 show_points(input_point, input_label, plt.gca()) 5 plt.axis('off')

in show_mask(mask, ax) 2 color = np.array([30/255, 144/255, 255/255, 0.6]) 3 h, w = mask.shape[-2:] ----> 4 mask_image = mask.reshape(h, w, 1) * color.reshape(1, 1, -1) 5 ax.imshow(mask_image) 6

ValueError: cannot reshape array of size 8640000 into shape (1200,1800,1)

likecv avatar Oct 30 '23 02:10 likecv

I'm not familiar with the formatting of the onnx output, but at least from the error message it looks like you're getting an array which is 4x bigger than expected, that is: 8640000 = 4 * (1200 * 1800)

So I either the mask image is 4x bigger than the 1200x1800 sizing (e.g. 2400x3600) or maybe you're getting 4 masks. If the sizing is the problem, you could quickly fix it by hard-coding in the extra scaling by adding a 2*h and 2*w on the line with the error:

mask_image = mask.reshape(2*h, 2*w, 1) * color.reshape(1, 1, -1)

It seems more likely that you're getting 4 masks, in which case you could reshape the mask output accordingly, though you'll then need to pick which index to use when drawing the image with something like:

mask_index = 0
mask_image = mask.reshape(4, h, w, 1)[mask_index] * color.reshape(1, 1, -1)

heyoeyo avatar Oct 30 '23 14:10 heyoeyo

try return_single_mask when output decoder, maybe help

tacom1 avatar Nov 10 '23 01:11 tacom1

modify "mask_image = mask.reshape(h, w, 1) * color.reshape(1, 1, -1)" to "mask_image = mask.reshape(h, w, -1) * color.reshape(1, 1, -1)" is ok

xpp726 avatar Dec 20 '23 07:12 xpp726