heuritech / convnets-keras

MIT License
594 stars 185 forks source link

Load weights error in theano #48

Open mkbl126 opened 6 years ago

mkbl126 commented 6 years ago

I loaded the pretrained alexnet model in keras 2.06 and theano 0.9, got the error. Could anyone help me ?

The code : model = convnet('alexnet',weights_path=".\model\alexnet_weights.h5", heatmap=False)

The error :

c:\DL\keras_test\a3rdparty\convnets_keras_master\convnetskeras\convnets.pyc in convnet(network, weights_path, heatmap, trainable) 63 elif network == 'alexnet': 64 convnet_init = AlexNet ---> 65 convnet = convnet_init(weights_path, heatmap=False) 66 67 if not heatmap:

c:\DL\keras_test\a3rdparty\convnets_keras_master\convnetskeras\convnets.pyc in AlexNet(weights_path, heatmap) 230 231 conv_2 = MaxPooling2D((3, 3), strides=(2,2))(conv_1) --> 232 conv_2 = crosschannelnormalization(name="convpool_1")(conv_2) 233 conv_2 = ZeroPadding2D((2,2))(conv_2) 234 conv_2 = merge([

C:\Anaconda2\lib\site-packages\keras\engine\topology.pyc in call(self, inputs, kwargs) 594 595 # Actually call the layer, collecting output(s), mask(s), and shape(s). --> 596 output = self.call(inputs, kwargs) 597 output_mask = self.compute_mask(inputs, previous_mask) 598

C:\Anaconda2\lib\site-packages\keras\layers\core.pyc in call(self, inputs, mask) 645 if has_arg(self.function, 'mask'): 646 arguments['mask'] = mask --> 647 return self.function(inputs, **arguments) 648 649 def compute_mask(self, inputs, mask=None):

c:\DL\keras_test\a3rdparty\convnets_keras_master\convnetskeras\customlayers.pyc in f(X) 17 square = K.square(X) 18 extra_channels = K.spatial_2d_padding(K.permute_dimensions(square, (0,2,3,1)) ---> 19 , (0,half)) 20 extra_channels = K.permute_dimensions(extra_channels, (0,3,1,2)) 21 scale = k

C:\Anaconda2\lib\site-packages\keras\backend\theano_backend.pyc in spatial_2d_padding(x, padding, data_format) 1036 """ 1037 assert len(padding) == 2 -> 1038 assert len(padding[0]) == 2 1039 assert len(padding[1]) == 2 1040 top_pad, bottom_pad = padding[0]

TypeError: object of type 'int' has no len()

shaheryar1 commented 4 years ago

Any updates on this issue ?

JohnGBA commented 3 years ago

Hi @shaheryar1. in customlayers.py, line 22, change (0,half) to ((0,0),(half,half))) (by @erralves from issue#44)