NAJI Abdessamad
NAJI Abdessamad

Reputation: 81

training model CNN KERAS

hello everyone i am trying to train a model using cnn and keras but the training don't finish and i got this warning and it stops training , i don't know why and i didn't understand where the problem is can anyone gives me a advice or what i should change in the code

 def myModel():
        no_Of_Filters=60
        size_of_Filter=(5,5) # THIS IS THE KERNEL THAT MOVE AROUND THE IMAGE TO GET THE FEATURES.
                             # THIS WOULD REMOVE 2 PIXELS FROM EACH BORDER WHEN USING 32 32 IMAGE
        size_of_Filter2=(3,3)
        size_of_pool=(2,2)  # SCALE DOWN ALL FEATURE MAP TO GERNALIZE MORE, TO REDUCE OVERFITTING
        no_Of_Nodes = 500   # NO. OF NODES IN HIDDEN LAYERS
        model= Sequential()
        model.add((Conv2D(no_Of_Filters,size_of_Filter,input_shape=(imageDimesions[0],imageDimesions[1],1),activation='relu')))  # ADDING MORE CONVOLUTION LAYERS = LESS FEATURES BUT CAN CAUSE ACCURACY TO INCREASE
        model.add((Conv2D(no_Of_Filters, size_of_Filter, activation='relu')))
        model.add(MaxPooling2D(pool_size=size_of_pool)) # DOES NOT EFFECT THE DEPTH/NO OF FILTERS
     
        model.add((Conv2D(no_Of_Filters//2, size_of_Filter2,activation='relu')))
        model.add((Conv2D(no_Of_Filters // 2, size_of_Filter2, activation='relu')))
        model.add(MaxPooling2D(pool_size=size_of_pool))
        model.add(Dropout(0.5))
     
        model.add(Flatten())
        model.add(Dense(no_Of_Nodes,activation='relu'))
        model.add(Dropout(0.5)) # INPUTS NODES TO DROP WITH EACH UPDATE 1 ALL 0 NONE
        model.add(Dense(noOfClasses,activation='softmax')) # OUTPUT LAYER
        # COMPILE MODEL
        model.compile(Adam(lr=0.001),loss='categorical_crossentropy',metrics=['accuracy'])
        return model
     
     
    ############################### TRAIN
    model = myModel()
    print(model.summary())
    history=model.fit_generator(dataGen.flow(X_train,y_train,batch_size=batch_size_val),steps_per_epoch=steps_per_epoch_val,epochs=epochs_val,validation_data=(X_validation,y_validation),shuffle=1)
WARNING:tensorflow:Your input ran out of data; interrupting training. Make sure that your dataset or generator can generate at least `steps_per_epoch * epochs` batches (in this case, 20000 batches). You may need to use the repeat() function when building your dataset.

Upvotes: 1

Views: 114

Answers (1)

user11530462
user11530462

Reputation:

While using generators, you can either run the model without the step_per_epoch parameter and let the model figure out how many steps are there to cover an epoch.

    history=model.fit_generator(dataGen.flow(X_train,y_train,batch_size=batch_size_val),
            epochs=epochs_val,
            validation_data=(X_validation,y_validation),
            shuffle=1)

OR

you'll have to calculate steps_per_epoch and use it while training as follows;

history=model.fit_generator(dataGen.flow(X_train,y_train,batch_size=batch_size_val),
            steps_per_epoch=(data_samples/batch_size)
            epochs=epochs_val,
            validation_data=(X_validation,y_validation),
            shuffle=1)

Let us know if the issue still persists. Thanks!

Upvotes: 1

Related Questions