0

I am trying to implement a simple classification model, but there seems to be a problem with the "Dataset" object.

import matplotlib.pyplot as plt
import numpy as np
import PIL
import tensorflow as tf

The code to generate training dataset is:

train_ds = tf.keras.utils.image_dataset_from_directory(
   TRAIN_DIR,
   validation_split = 0.25,
   seed = 3,
   image_size = (224, 224), 
   batch_size = batch_size,
   subset = 'training',
   shuffle = True,
   labels = 'inferred',
   label_mode = 'categorical'
)

and for validation it is:

validation_data = tf.keras.utils.image_dataset_from_directory(
    TRAIN_DIR,
    validation_split = 0.25,
    seed = 3,
    image_size = (224, 224), 
    batch_size = batch_size,
    subset = 'validation',
    shuffle = True,
    labels = 'inferred',
    label_mode = 'categorical'
)

i dont think there is anything special about the code but when i execute the following code:

class_names = train_ds.class_names

plt.figure(figsize=(10, 10))
for images, labels in train_ds.take(1):
      for i in range(9):
        ax = plt.subplot(3, 3, i + 1)
        plt.imshow(images[i].numpy().astype("uint8"))
        plt.title(class_names[np.argmax(labels[i])])
        plt.axis("off")

it shows "Cleanup called..." in several lines.

same thing happens when i try to fit the model using model.fit function.

I am using a simple Kaggle notebook and tensorflow version is 2.6.4.

i tried several solutions found in the site, such as downgrading to a lower version of tensorflow, but in that case tf.keras.utils.image_dataset_from_directory does not seem to work at all.

i tried to hide error messages by:

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' 

and this didn't work either.

i tried rest of the solutions in here, but they didn't.

I checked other codes for the same dataset, they were using the deprecated ImageDataGenerator.

So my question is, is there a work around or a simple solution to disable these "Cleanup Called..." messages and still use tf.keras.utils.image_dataset_from_directory?

PS: Most of the code is copied from Image Classification, when implementing this dataset there seems to be no problem, but when implementing other datasets, that are added to the input or output of a kernel, this problem occures.

Me Bottle O Scrumpy
  • 266
  • 1
  • 3
  • 12
  • 1
    Hi @MeBottleOScrumpy, found a similar issue [here](https://stackoverflow.com/a/73256702/14290697), it might help in resolving the issue. Thank you! –  Sep 28 '22 at 13:00
  • @Tfer3 thanks mate, but the link you provided suggests downgrading `tensorflow`, which i stated in the question creates problems with `image_dataset_from_directory`. – Me Bottle O Scrumpy Sep 29 '22 at 05:05
  • 1
    As mentioned [here](https://stackoverflow.com/a/73219868/14290697), you can try using `from IPython.display import clear_output` followed by `clear_output()` whithout downgrading the version of Tensorflow –  Sep 29 '22 at 06:38
  • @Tfer3 even thought it hides progress bars and stuff it is nice work around. thanks. – Me Bottle O Scrumpy Sep 29 '22 at 06:47

0 Answers0