keras-team / keras-applications

Reference implementations of popular deep learning models.
Other
2k stars 910 forks source link

Add new classes in InceptionResNetV2 model #57

Closed AtulCIS closed 5 years ago

AtulCIS commented 5 years ago

Hello, I am trying to fine tune InceptionResNetV2 model and I want to add few more classes in it like Watermelon, tomato etc so I tried many ways and every time I am getting an error "a 2D array of shape (samples, 1000)). Found array with shape: 5", so Is it possible to add new classes in existing model or how can I merge my new trained model with InceptionResNetV2 ?

taehoonlee commented 5 years ago

@AtulCIS, You can refer the section "Fine-tune InceptionV3 on a new set of classes" in the official docs.

AtulCIS commented 5 years ago

Thanks @taehoonlee for the reply. Yes I tried it and when I did that I got the model for my 5 new classes and all the data for 1000 categories disappeared.

taehoonlee commented 5 years ago

@AtulCIS, Then, you can try the following:

base_model = InceptionV3(weights='imagenet')
x = base_model.layers[-k].output
x = GlobalAveragePooling2D()(x)
predictions = Dense(5, activation='softmax')(x)
your_model = Model(inputs=base_model.input, outputs=predictions)
AtulCIS commented 5 years ago

Ok let me try this.

AtulCIS commented 5 years ago

Hi @taehoonlee, What will be the value for "k" in above code ?

taehoonlee commented 5 years ago

The last 4D feature map. An index "k" depends on a model.

AtulCIS commented 5 years ago

Ok so can you please tell in my case what value I can use ? for eg. k=5 ?

taehoonlee commented 5 years ago

I think you need to figure it out.