Create Keras input array, numpy.append does not work correctly

ⅰ亾dé卋堺 提交于 2019-12-13 01:34:52

问题


I'm trying to create an input array for a functional Keras model. I have a set of images that I collect in a single np array, so the array has the shape: (nr_images,img_width,img_height,nr_channels)

I use this code:

files = glob.glob ("data/train/part2/*.png")
for myFile in files:
    image = cv2.imread (myFile)
    image=cv2.resize(image,(256,256))
    train.append (image)
train = np.array(train,dtype='float32')
np.save('train',train)

The resulting array dimension is (426, 256, 256, 3). So it seems to work.

But if I look at the images stored in the array by:

image_train=np.load("train.npy")
image=image_train[0]       #Look at the first image
img = Image.fromarray(image,'RGB')
img.show()

I get rubbish:

My Keras results are super bad, so I suspect that it has something to do with the input.

Am I doing something wrong?

来源:https://stackoverflow.com/questions/51423972/create-keras-input-array-numpy-append-does-not-work-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!