Reputation: 79
I want to finetune vgg in keras. I successfully performed the classification task of classifying images of fruit. Let's say I want a model to be able to predict both the fruit name and fruit color. I successfully trained two different models for predicting fruit type and color. But I want to have a model which can perform both. How can I achieve this? Can I use this solution:
How does Keras handle multilabel classification?
Another solution that came to mind, was using vgg to extract and store features, and then using those feature vectors to perform multiclass multilabel classification using sci-kit learn which I am more familiar with than keras. ButI'm mainly interested in using deep learning to perform the whole thing. Another thing is not all images have all the labels, i.e some images may not have fruit color for example. What can I do about this? One thing that comes to mind is removing these images from dataset, but this will also mean losing around 2 thousand of my training data.
Upvotes: 2
Views: 3338
Reputation: 11
You have to use a sigmoid activation function for the output layer and binary_crossentropy as the loss function.
nn = Sequential()
nn.add(Dense(10, activation="relu", input_shape=(10,)))
nn.add(Dense(5, activation="sigmoid"))
nn.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
You can find more details in this article I wrote a while ago.
Upvotes: 1