Home > database >  how to convert list of images to Batches for tensorflow classification
how to convert list of images to Batches for tensorflow classification

Time:03-08

I have a question about the input baches (if understand it correctly). (i refer this for the classification)

There is a train_images.shape of fashion dataset is (60000, 28, 28). if understand it correctly, it is 60000 images with 28*28 shape. train_labels is array([9, 0, 0, ..., 3, 0, 5], dtype=uint8)

In my case, I have a list which has images in it. The size of the list is 2000 and each image have the shape of 250*250. I convert my labels using np.array(y_train).

problem is-: i cant not use my "train_images" in model.fit(train_images, train_labels, epochs=50) because it is not in a shape model needs.

I think, I need to convert the list of data into (2000,250,250).

can someone help me with how to do that? i directly convert into List to Numpy. which it did not work.

also suggest me what could be the change if i use (2000,250,250).

i did like this, but i think it is not optimal way to do it

final_traing = np.array([])
temp=X_train[0]
for i in range(1,len(X_train)):
  data_final=np.concatenate([temp, X_train[i]], axis=0)
  temp=final_traing

CodePudding user response:

If each image really has the shape (250*250), you can try something like this:

import numpy as np

samples = 3
image1 = np.random.random((250*250))
image2 = np.random.random((250*250))
image3 = np.random.random((250*250))
X_train = np.asarray([image1, image2, image3])
print(X_train.shape)
X_train = np.reshape(X_train, (samples, 250, 250))
print(X_train.shape)
(3, 62500)
(3, 250, 250)
  • Related