I can successfully show color images in .rec file by using this code blow:
import mxnet as mx
import numpy as np
import matplotlib.pyplot as plt
batch_size = 10
data_shape = (3, 100, 100)
rec_file = "/Users/zuekiWork/Documents/mxnet_jd/data/train_all_100.rec"
rec_list = "/Users/zuekiWork/Documents/mxnet_jd/data/train_all.lst"
rec_iter = mx.io.ImageRecordIter(
path_imgrec = rec_file,
path_imglist= rec_list,
data_shape = data_shape,
batch_size = batch_size,
shuffle = False,
flat = True)
X_test = rec_iter.getdata().asnumpy()
for i in range(batch_size):
plt.subplot(1,batch_size,i+1)
X=X_test[i]
print "before:", X.shape
X=np.swapaxes(X, 0, 2)
X=np.swapaxes(X, 0, 1)
print "after:", X.shape
#plt.imshow(X,cmap='Greys_r')
plt.imshow(X.astype(np.uint8))
plt.axis('off')
plt.show()
Then I modified the data_shape to (1,100,100) . When I show gray files in .rec file I get an error :
....
Traceback (most recent call last):
File "show_img_in_rec.py", line 28, in
plt.imshow(X_test[0], cmap='Greys_r')
File "/Users/zuekiWork/anaconda2/lib/python2.7/site-packages/matplotlib/pyplot.py", line 3022, in imshow
*_kwargs)
File "/Users/zuekiWork/anaconda2/lib/python2.7/site-packages/matplotlib/init.py", line 1812, in inner
return func(ax, *args, *_kwargs)
File "/Users/zuekiWork/anaconda2/lib/python2.7/site-packages/matplotlib/axes/_axes.py", line 4947, in imshow
im.set_data(X)
File "/Users/zuekiWork/anaconda2/lib/python2.7/site-packages/matplotlib/image.py", line 453, in set_data
raise TypeError("Invalid dimensions for image data")
TypeError: Invalid dimensions for image data
could someone help me ?
This issue is closed due to lack of activity in the last 90 days. Feel free to reopen if this is still an active issue. Thanks!
The input of imshow can only be a 2D input - grayscale
or a 3D where the last dimension can have 3 ( RGB ) or 4 ( RGBA )
A good idea is to reshape the (x, y, 1) array to (x, y)
Most helpful comment
The input of
imshowcan only be a2Dinput - grayscaleor a 3D where the last dimension can have 3 (
RGB) or 4 (RGBA)A good idea is to reshape the (x, y, 1) array to (x, y)