2
$\begingroup$

I am using transfer learning approach to train my keras model to identify objects which have same structure but the colors are different i.e objects are to be identified by their respective color.

Model used = vgg16

Total object classes = 7

Number of training images = 2100

Number of Validation images = 525

Image size = (224, 224)

Following is my model compilation details:

model.compile(Adam(lr = .0001), loss = 'categorical_crossentropy', metrics=['accuracy'])

Number of epochs = 500

Code Snippet:

model.layers.pop()  #removed the last layer of the pre-trained model
#adding output layer as per my requirement
model.add(Dense(7, activation='softmax'))  

# Here reading my train, test and validation dataset
    train_batches = ImageDataGenerator().flow_from_directory(train_path, target_size = (224,224), classes = ['N52204400D','N52204403M','N52204406G','N52204500DA','N52204503M','N52204506G','N522044064A'],batch_size = 20)
valid_batches = ImageDataGenerator().flow_from_directory(valid_path, target_size = (224,224), classes = ['N52204400D','N52204403M','N52204406G','N52204500DA','N52204503M','N52204506G','N522044064A'],batch_size = 5)
test_batches = ImageDataGenerator().flow_from_directory(test_path, target_size = (224,224), classes = ['N52204400D','N52204403M','N52204406G','N52204500DA','N52204503M','N52204506G','N522044064A'],batch_size = 7)

#Finally Training the new model
model.compile(Adam(lr = .0001), loss = 'categorical_crossentropy', metrics=['accuracy'])
model.fit_generator(train_batches, steps_per_epoch=<>, validation_data=valid_batches, validation_steps=<>, epochs=<>, verbose=2)

Issue faced:

Accuracy of my model is not improving beyond 60%.

Is there anything I am missing? Do I need to tweak my code?If yes, then how? Or if there is any better way to train a model to identify differently colored object, please advice.

Thanks in advance!

$\endgroup$
  • $\begingroup$ Welcome to this site! About your question, I am a bit confused. As far as I know, transfer learning is used for using knowledge learned from a problem, but to solve a different problem. So, I guess that you are transferring the knowledge in the pre-trained model vgg16 (a model trained for solving object classification problem where shape matters significantly), into another model where it solves a different object classification problem where shape does not matter, and only color matters. Am I right? If so, may I know which code line is doing the transferring part? $\endgroup$ – caveman Mar 23 at 13:25
  • $\begingroup$ @caveman I have edited my post to incorporate the codebase. I have added comments along with the code to explain where exactly the pre-trained model is being tailored as per my requirement. $\endgroup$ – Learn123 Mar 23 at 14:11

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.