heuritech / convnets-keras

MIT License
594 stars 185 forks source link

Problem retraining model with Softmax4D #20

Closed dvro closed 7 years ago

dvro commented 7 years ago

I am trying to retrain the VGG16 for a specific set of classes. It works with heatmap=False, (without Softmax4D), but I need to generate a heatmap.

Here is what I am doing:

    model.add(Convolution2D(3,1,1,name="dense_3"))
    model.add(Softmax4D(axis=1,name="softmax"))
model.fit(X_, y_, nb_epoch=10, batch_size=4)

However, I have a problem finding the adequate format for y_ (the classes).

I know that y must have 3 dimensions Exception: Error when checking model target: expected softmax to have 3 dimensions but not sure how to do that considering that my y currently has 1 dimension (values 0,1 and 2).

Even applying np_utils.to_categorical(y_, len(set(y_))), I still get only 2 dimensions.

Is the workflow correct? How can I solve this issue?

Thanks in advance,

ghost commented 7 years ago

@dvro can you please tell me how do you retrained the model for custom data sets (I dont need a heat map) . This is my guess

  1. go to /convnets-keras/convnetskeras/
  2. open convnets.py
  3. Edit VGG_16function
  4. Remove last layer
model.add(Dense(1000, name='dense_3'))
model.add(Activation("softmax",name="softmax"))
  1. Add a new layer (eg. for an yes/no output)
model.add(Dense(1, name='dense_3'))
model.add(Activation("softmax",name="softmax"))
  1. Load vgg16_weights
  2. Retrain using model.fit(X,y)

Am I in the right direction? Any help will be greatly appreciated.