Unable to use model.fit for ImageDataGenerator (Week 4)

Hi,

I have been trying to do this week’s practice (horses-or-humans) locally using a jupyter notebook. I’ve set downloaded both datasets (training and validation) and set them up in the data directory of my folder. I’ve modified my code to point to the directories containing these datasets relative to my working directory. Everything works fine up until I run model.fit() which produces this error:

__ array__() takes 1 positional argument but 2 were given.

I’m not sure why this is happening, I’ve set up all my parts of my code to work and I also looked in to the tensorflow documentation and ran the following command:

data_gen_args = dict(featurewise_center=True,
featurewise_std_normalization=True,
rotation_range=90,
width_shift_range=0.1,
height_shift_range=0.1,
zoom_range=0.2)
image_datagen = ImageDataGenerator(**data_gen_args)
mask_datagen = ImageDataGenerator(**data_gen_args)
seed = 1
image_datagen.fit(images, augment=True, seed=seed)
mask_datagen.fit(masks, augment=True, seed=seed)
image_generator = image_datagen.flow_from_directory(
train_dir,
class_mode=None,
seed=seed)
mask_generator = mask_datagen.flow_from_directory(
train_dir,
class_mode=None,
seed=seed)
train_generator = zip(image_generator, mask_generator)
model.fit(
train_generator,
steps_per_epoch=2000,
epochs=50)

Where I’ve set train_dir to be the directory that holds the directories which have the horses and humans images. Yet I still face the same error. I’ve also opened the google collab book in my local jupyter, and configured all the files to look on my local computer for the training and validation data yet I still get the same error. I’ve attached my code below along with images of my code, the error, and how I’ve set my directories up on my computer.


Course Folder: Contains Code (Horse-Human-Binary-Classifer) and Data Folder
Screen Shot 2022-01-29 at 1.17.49 PM

Data Folder Within Course Folder
Screen Shot 2022-01-29 at 1.17.58 PM

Validatation-horse-or-human folder
Screen Shot 2022-01-29 at 1.18.04 PM

horse-or-human folder
Screen Shot 2022-01-29 at 1.18.11 PM

Here is the code file I’ve used: Horse-Human-Binary-Classifer.ipynb (15.5 KB)

Please help and let me know if there is any additional information I need to provide.

I am working with on MacOS Catalina with tensorflow 2.7.0.

What version of TF is running if you use either the Coursera AWS or Colab (wherever the class exercise is executed by default)? I ask because any time I or anyone else tries running the class notebooks locally there are version issues to deal with. If your code runs on the cloud but not locally, there is an API changed somewhere.

Hi yes, my code will work if I open it in google collab and adjust the directories as shown in the lab. How can I get this to work on jupyter?

Here is the code I’ve used on collab.

Horse_Human_Binary_Classifer-collab.ipynb (16.4 KB)

Restating my question above, which TF version is running in each environment? Assuming you have

import tensorflow as tf

can find out the version by adding

print(tf.__version__)

I have gotten in the habit of printing out the Python,Keras, and TensorFlow versions at the beginning of any program. Further analysis of your issue depends on what you find out from that.