Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NotImplementedError: `fit_generator` is not yet enabled for unbuilt Model subclasses

I am using the following code:

import tensorflow as tf
##############################################################

traindata = tf.keras.preprocessing.image.ImageDataGenerator(
    rescale=1. / 255,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True)

input = traindata.flow_from_directory('VS/train')

    modelo = tf.keras.Sequential()
    modelo.add(tf.keras.layers.Conv2D(32, (3, 3), 
 activation=tf.keras.activations.relu))
    modelo.add(tf.keras.layers.Flatten())
    modelo.add(tf.keras.layers.Dense(64, activation=tf.keras.activations.relu))
    modelo.add(tf.keras.layers.Dense(2, activation=tf.keras.activations.relu))
    modelo.compile(loss='categorical_crossentropy', optimizer='rmsprop')

modelo.fit_generator(input, epochs=1)

However, I am getting this error:

So by running the code below I get this error

NotImplementedError: `fit_generator` is not yet enabled for unbuilt Model subclasses 

Can someone tell me what's wrong?

like image 865
Tim AI Avatar asked Mar 06 '23 03:03

Tim AI


1 Answers

You didn't specify the input_shape in the first layer, so the model is not fully defined. This process has not been implemented with fit_generator, so you should fully define the model with the initial input_shape.

like image 177
Dr. Snoopy Avatar answered Mar 16 '23 06:03

Dr. Snoopy