use resnet model to train from scratch

1,008 views
Skip to first unread message

Omar

unread,
Aug 18, 2016, 7:51:25 AM8/18/16
to Keras-users
Considering the resnet  model in:


I would like to use the imagnet weights as initialization to retrain the complete model in new data. Is there an easy way to do this?

I have tried the following:

model = ResNet50(include_top=True, weights=None)
model.compile(loss='categorical_crossentropy', optimizer='SGD', metrics=['accuracy'])
checkpointer = ModelCheckpoint(filepath='best_VGG_all_dataset_spatial_features', verbose=1, save_best_only=True)
model.fit(train_data, train_labels, nb_epoch=50, batch_size=32,
verbose=1, shuffle=True, validation_data=(validation_data, validation_labels), callbacks=[checkpointer])


But doesn't seem to work.  I get the following error:

Exception: Error when checking model target: expected fc1000 to have shape (None, 1000) but got array with shape (240, 1)

I need a way to easily add an fc(nb_classes) layer at the end of the model.

Any recommendation on how to fix this?


Regards

Omar

unread,
Aug 27, 2016, 11:37:19 AM8/27/16
to Keras-users
Does anyone has a suggestion for this?

Regards

Qixianbiao Qixianbiao

unread,
Aug 30, 2016, 5:29:41 AM8/30/16
to Keras-users

model = ResNet50(include_top=False, weights='imagenet')
model.add(Dense(240, activation='softmax'))     #if nb_classes = 240

include_top=False  ->  Remove the last classification, weight = 'imagenet' means loading the imagenet pretrained model


在 2016年8月18日星期四 UTC+8下午7:51:25,Omar写道:

edwinvar...@gmail.com

unread,
Dec 1, 2017, 7:23:48 AM12/1/17
to Keras-users
"expected fc1000 to have shape (None, 1000) but got array with shape (240, 1)". fc1000 is the labels(classes). It's default at 1000. You will have to predefine it as the number of classes you want. If you you have 2 classes. set it as 2. [Disclaimer: I am not an expert. It's best to talk to an expert on this.]
Reply all
Reply to author
Forward
0 new messages