didi / maskdetection

Apache License 2.0
179 stars 55 forks source link

Problem after converting from caffe to keras in number of layers #3

Open Manideep08 opened 4 years ago

Manideep08 commented 4 years ago

I am new to C++. Can you please shed some light on what they are and how I should tweak them to make the repo in working condition?

Also, is it possible to use the .caffemodel and .prototxt files inside model folder for inference in Python?

Update : I used this to convert the .caffemodel and .prototxt file into .hdf5 file in Keras. Now when trying to load resnet50 inbuilt in keras with the computed .hdf5 file, I am getting the following error.

It is telling there are more number of layers in your architecture. Could you please assist me on this?

My code from keras.applications import resnet model = resnet.ResNet50(include_top=True, weights='mask_dete1.h5', input_tensor=None, input_shape=(224, 224, 3), pooling=None, classes=2)

Error

ValueError Traceback (most recent call last)

in () ----> 1 model = resnet.ResNet50(include_top=True, weights='mask_dete1.h5', input_tensor=None, input_shape=(224, 224, 3), pooling=None, classes=2) 6 frames /usr/local/lib/python3.6/dist-packages/keras/applications/__init__.py in wrapper(*args, **kwargs) 18 kwargs['models'] = models 19 kwargs['utils'] = utils ---> 20 return base_fun(*args, **kwargs) 21 22 return wrapper /usr/local/lib/python3.6/dist-packages/keras/applications/resnet.py in ResNet50(*args, **kwargs) 12 @keras_modules_injection 13 def ResNet50(*args, **kwargs): ---> 14 return resnet.ResNet50(*args, **kwargs) 15 16 /usr/local/lib/python3.6/dist-packages/keras_applications/resnet_common.py in ResNet50(include_top, weights, input_tensor, input_shape, pooling, classes, **kwargs) 433 input_tensor, input_shape, 434 pooling, classes, --> 435 **kwargs) 436 437 /usr/local/lib/python3.6/dist-packages/keras_applications/resnet_common.py in ResNet(stack_fn, preact, use_bias, model_name, include_top, weights, input_tensor, input_shape, pooling, classes, **kwargs) 411 model.load_weights(weights_path) 412 elif weights is not None: --> 413 model.load_weights(weights) 414 415 return model /usr/local/lib/python3.6/dist-packages/keras/engine/saving.py in load_wrapper(*args, **kwargs) 490 os.remove(tmp_filepath) 491 return res --> 492 return load_function(*args, **kwargs) 493 494 return load_wrapper /usr/local/lib/python3.6/dist-packages/keras/engine/network.py in load_weights(self, filepath, by_name, skip_mismatch, reshape) 1228 else: 1229 saving.load_weights_from_hdf5_group( -> 1230 f, self.layers, reshape=reshape) 1231 if hasattr(f, 'close'): 1232 f.close() /usr/local/lib/python3.6/dist-packages/keras/engine/saving.py in load_weights_from_hdf5_group(f, layers, reshape) 1207 'containing ' + str(len(layer_names)) + 1208 ' layers into a model with ' + -> 1209 str(len(filtered_layers)) + ' layers.') 1210 1211 # We batch weight value assignments in a single backend call ValueError: You are trying to load a weight file containing 112 layers into a model with 107 layers.
2016110071 commented 4 years ago

There are other layers between block3 and block4 of resnet50. maybe you can remove them.