Ragdoll_X_Furry

Ragdoll_X_Furry t1_iwcxiv6 wrote

Adam is usually more likely to overfit, so using SGD with Nesterov momentum might help a bit. I'd also recommend augmenting contrast, brightness, saturation and hue if those options are available for the ImageDataGenerator class.

Also does the rotation in the ImageDataGenerator fill the background with black pixels or is there the option to extend/reflect the image? In my experience simply filling the background with black after rotation tends to hinder the accuracy.

One trick that might also help is to extract the outputs not only from the last layer of the pretrained network but also from earlier layers to feed into your network. In my experience this can help improve the accuracy. I've done this with the EfficientNet B0, so I've pasted some example code here to help you out, though if you don't want to use an EfficientNet I'm sure this can be adapted to the DenseNet201 too.

Of course, sometimes transfer learning just doesn't help really, so if nothing else helps you push the accuracy above 90% it might be best to just build and train your own model from scratch to better suit your needs.

2

Ragdoll_X_Furry t1_iwc23i9 wrote

A few more details about your implementation would be useful for us to help you.

  1. How many images are you using for validation?

  2. What batch size and optimizer are you using during training?

  3. What's the dropout rate in the Dropout layers?

  4. How are you preprocessing the images before feeding them to your model? Are you using the tf.keras.applications.densenet.preprocess_input function as suggested in the Keras documentation?

You should try increasing the batch size if you can, and use data augmentation as others have already suggested.

You can also try other networks besides DenseNet, like one of the ResNet or EfficientNet models, and you can replace the Flatten layer by a GlobalAvgPool2D or GlobalMaxPool2D layer to reduce parameter size (in my experience the former gives better results). Also that resizing layer might not necessary to improve accuracy.

1