1

I am trying to work on an image colorizer using autoencoders. The 'input' is a grayscale image and the 'labels' are their corresponding color images. I am trying to get it to work on google colab on a subset of the dataset. The problem is that the session crashes when I try to convert the list of images to a numpy array. Here's what I tried:

X = []
y = []
errors = 0
count = 0
image_path = 'drive/My Drive/datasets/imagenette'
for file in tqdm(os.listdir(image_path)):
  try:
    # Load, transform image
    color_image = io.imread(os.path.join(image_path,file))
    color_image = transform.resize(color_image,(224,224))
    lab_image = color.rgb2lab(color_image)
    L = lab_image[:,:,0]/100.
    ab = lab_image[:,:,1:]/128.
    # Append to list
    gray_scale_image = np.stack((L,L,L), axis=2)
    X.append(gray_scale_image)
    y.append(ab)
    count += 1
    if count == 5000:
      break
  except:
    errors += 1
print(f'Errors encountered: {errors}')

X = np.array(X)
y = np.array(y)
print(X.shape)
print(y.shape)

Is there a way to load only a few batches, feed them and while the model is being trained on them, load another set of batches?

2
  • Try converting your data into a TensorFlow dataset. you'll have access to methods like batch which allow you to load data in batches: tensorflow.org/guide/data Commented Jul 25, 2020 at 13:58
  • Thanks! I looked into tf.data and set up an input pipeline but I got an error. stackoverflow.com/questions/63092118/… Commented Jul 25, 2020 at 18:39

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.