I'm trying to make a self-driving AI that can drive around in GTA-San Andreas by following sentdex's videos on making a self-driving AI for GTA-V but my model always starts to overfit after 4 epochs or so.

Even after doubling the dataset that I originally had, the model is still overfitting.

The dataset made up of grayscale images (270x360) and is distributed into 250 .npy files with 1000 frames each totaling 250,000 frames.

I'm using Xception architecture without any pre-trained weights as the model. The code is given below:

def create_model():
    xception_model = Xception(include_top=False, weights=None, input_shape=dimensions)
    x = xception_model.output
    x = (GlobalAveragePooling2D()) (x)
    x = (Dense(1024, activation='relu')) (x)
    predictions = Dense(9, activation='softmax') (x)

    model = Model(inputs=xception_model.input, outputs=predictions)

    opt = adam(lr=1e-3, decay=1e-5)

    return model

model = create_model()
epochs = 30

allhistory = {'val_loss':[], 'val_acc':[], 'loss':[], 'acc':[]}

for e in range(1,epochs+1):
    data_order = [i for i in range(1,total_files+1)]

    for count,i in enumerate(data_order):
            filename = f'/content/drive/My Drive/Dataset/processed_data-{i}.npy'
            data_set = np.load(filename,allow_pickle=True)

            print(f"\n{e+1}:{count+1}:Data-{i}.npy Loaded!")
            X = np.array([np.repeat(data[0]/255.0,3,-1) for data in data_set]).reshape(-1,HEIGHT,WIDTH,3)
            y = np.array([data[1] for data in data_set])
            X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state = 5)

            history = model.fit(X_train, y_train, validation_data = (X_test,y_test), epochs=1)


            if (count+1)%10==0:
                print('\nSAVING MODEL!')
                model.save(f'/content/drive/My Drive/models/xceptionmodel-epoch-{e+1}.h5')
                np.save('/content/drive/My Drive/models/allhistory.npy',np.array(allhistory))

        except Exception as ex:

Here is a graph showing how the accuracy and validation accuracy starts diverging after 4 epochs: Accuracy Graph

Can anyone please help me and point out what mistakes I'm making.

  • $\begingroup$ Have you tried adding a dropout layer between the hidden layer and your final layer? $\endgroup$
    – Oxbowerce
    Mar 18 '20 at 18:21
  • $\begingroup$ Yes, during initial testing i tried a dropout of 0.5 between the hidden and final layer but without any significant change. Furthermore i recall reading that dropout shouldn't be used in the output layers. $\endgroup$ Mar 18 '20 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.