titu1994 / keras-efficientnets

Keras Implementation of EfficientNets
MIT License
187 stars 63 forks source link

No top weights #4

Closed ryzbaka closed 5 years ago

ryzbaka commented 5 years ago

Hi, I want to apply transfer learning to the model to detect oil storage tanks by applying transfer learning.However, when I import the EfficientNetB0 with include top=False, I get the error 'Operands could not be broadcast together with shapes (None, None, 24) (None, None, 16)', is this because its trying to apply the imagenet weight to a model without the top layer? If so, could you provide the weights for the same?

titu1994 commented 5 years ago

Thats odd. I can build EfficientNetB0 without any issue with no_top. Here's my output :

Downloading data from https://github.com/titu1994/keras-efficientnets/releases/download/v0.1/efficientnet-b0_notop.h5
16719872/16717576 [==============================] - 16s 1us/step
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_1 (InputLayer)            (None, None, None, 3 0                                            
__________________________________________________________________________________________________
conv2d_1 (Conv2D)               (None, None, None, 3 864         input_1[0][0]                    
__________________________________________________________________________________________________
batch_normalization_1 (BatchNor (None, None, None, 3 128         conv2d_1[0][0]                   
__________________________________________________________________________________________________
swish_1 (Swish)                 (None, None, None, 3 0           batch_normalization_1[0][0]      
__________________________________________________________________________________________________
depthwise_conv2d_1 (DepthwiseCo (None, None, None, 3 288         swish_1[0][0]                    
__________________________________________________________________________________________________
batch_normalization_2 (BatchNor (None, None, None, 3 128         depthwise_conv2d_1[0][0]         
__________________________________________________________________________________________________
swish_2 (Swish)                 (None, None, None, 3 0           batch_normalization_2[0][0]      
__________________________________________________________________________________________________
lambda_1 (Lambda)               (None, 1, 1, 32)     0           swish_2[0][0]                    
__________________________________________________________________________________________________
conv2d_2 (Conv2D)               (None, 1, 1, 8)      264         lambda_1[0][0]                   
__________________________________________________________________________________________________
swish_3 (Swish)                 (None, 1, 1, 8)      0           conv2d_2[0][0]                   
__________________________________________________________________________________________________
...
conv2d_64 (Conv2D)              (None, None, None, 3 368640      multiply_16[0][0]                
__________________________________________________________________________________________________
batch_normalization_48 (BatchNo (None, None, None, 3 1280        conv2d_64[0][0]                  
__________________________________________________________________________________________________
conv2d_65 (Conv2D)              (None, None, None, 1 409600      batch_normalization_48[0][0]     
__________________________________________________________________________________________________
batch_normalization_49 (BatchNo (None, None, None, 1 5120        conv2d_65[0][0]                  
__________________________________________________________________________________________________
swish_49 (Swish)                (None, None, None, 1 0           batch_normalization_49[0][0]     
==================================================================================================
Total params: 4,049,564
Trainable params: 4,007,548
Non-trainable params: 42,016
__________________________________________________________________________________________________

I truncated the vast majority of the model building script, but nevertheless, the weights are downloaded and the model built with weights without issues.

Are you changing the input shape to something other than 224x224x3 ?

ryzbaka commented 5 years ago

I'll check in a bit.