Transfer learning with Resnet50 fail with Exception
See original GitHub issueHi, I am using Resnet50 to do transfer learning. The backend is tensorflow. I tried to stack three more layers on top of the Resnet but fail with following error:
Exception: The shape of the input to "Flatten" is not fully defined (got (None, None, 2048).
Make sure to pass a complete "input_shape" or "batch_input_shape" argument to the first layer in your model.
The code for stacking two models are as following:
model = ResNet50(include_top=False, weights='imagenet')
top_model = Sequential()
top_model.add(Flatten(input_shape=model.output_shape[1:]))
top_model.add(Dense(256, activation='relu'))
top_model.add(Dropout(0.5))
top_model.add(Dense(1, activation='sigmoid'))
top_model.load_weights(top_model_weights_path)
model = Model(input=model.input, output=top_model(model.output))
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:5
Top Results From Across the Web
Keras Transfer learning with Resnet50 fail with Exception
I am using Resnet50 to do transfer learning. The backend is tensorflow. I tried to stack three more layers on top of the...
Read more >Keras resnet50 transfer learning - kaggle kernel could not ...
I am trying to use resnet50 pretrained model on Kaggle kernel. But, when I run the following code, Error occurs and it could...
Read more >Keras vs PyTorch: how to distinguish Aliens vs Predators with ...
As training from scratch is unfeasible in most cases (as it is very data hungry), we'll perform transfer learning using ResNet-50 pre-trained on...
Read more >Resnet50 and other pre-trained models with cross-validation
Resnet50, densnet201, resnet18, vgg16, exception net, test network are pre-trained models with cross-validation Matlab code. all evaluation metrics are ...
Read more >What Makes Transfer Learning Work for Medical Images
Transfer learning is a standard technique to transfer knowledge from one domain to another. For applications in medical imaging, transfer from ImageNet has ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I solved the problem after reading through source code for
Resnet50.py
. If anyone encounter the same problem, please add theinput_shape
parameter when you callResnet50()
:If you are using Keras
ImageDataGenerator
, the input shape will be automatically inferred.Regarding the error:
Had the same issue, but disappeared after upgrading keras to 2.2.4 (with backend tensorflow 1.12.0 in case it matters).