Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__init__() got multiple values for keyword argument 'filters' TypeError while loading saved model #12316

Closed
nitink133 opened this issue Feb 21, 2019 · 6 comments
Labels
type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.

Comments

@nitink133
Copy link

Saving model

import h5py
keras_mnist_model = 'mobilenet_model_keras_.h5'
m.save(filepath = keras_mnist_model)

While loading model

# from tensorflow.keras.models import load_model
from keras.models import load_model
model = load_model(filepath = keras_mnist_model)

Error :

ypeError                                 Traceback (most recent call last)
<ipython-input-32-8b3b788ba66d> in <module>
      1 # from tensorflow.keras.models import load_model
      2 from keras.models import load_model
----> 3 model = load_model(filepath = keras_mnist_model)

~/code/data-science/tflite_face_recognition/model/venv/lib/python3.6/site-packages/keras/engine/saving.py in load_model(filepath, custom_objects, compile)
    417 
    418     # Arguments
--> 419         group: A pointer to a HDF5 group.
    420         name: A name of the attributes to load.
    421 

~/code/data-science/tflite_face_recognition/model/venv/lib/python3.6/site-packages/keras/engine/saving.py in _deserialize_model(f, custom_objects, compile)
    223         """Handles custom object lookup.
    224 
--> 225         # Arguments
    226             obj: object, dict, or list.
    227 

~/code/data-science/tflite_face_recognition/model/venv/lib/python3.6/site-packages/keras/engine/saving.py in model_from_config(config, custom_objects)
    456         save_attributes_to_hdf5_group(g, 'weight_names', weight_names)
    457         for name, val in zip(weight_names, weight_values):
--> 458             param_dset = g.create_dataset(name, val.shape,
    459                                           dtype=val.dtype)
    460             if not val.shape:

~/code/data-science/tflite_face_recognition/model/venv/lib/python3.6/site-packages/keras/layers/__init__.py in deserialize(config, custom_objects)
     53                                     module_objects=globs,
     54                                     custom_objects=custom_objects,
---> 55                                     printable_module_name='layer')

~/code/data-science/tflite_face_recognition/model/venv/lib/python3.6/site-packages/keras/utils/generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    143                     config['config'],
    144                     custom_objects=dict(list(_GLOBAL_CUSTOM_OBJECTS.items()) +
--> 145                                         list(custom_objects.items())))
    146             with CustomObjectScope(custom_objects):
    147                 return cls.from_config(config['config'])

~/code/data-science/tflite_face_recognition/model/venv/lib/python3.6/site-packages/keras/engine/network.py in from_config(cls, config, custom_objects)
   1020         # does not yet exist) are re-enqueued, and the process
   1021         # is repeated until all nodes are processed.
-> 1022         while unprocessed_nodes:
   1023             for layer_data in config['layers']:
   1024                 layer = created_layers[layer_data['name']]

~/code/data-science/tflite_face_recognition/model/venv/lib/python3.6/site-packages/keras/engine/network.py in process_layer(layer_data)
   1006             # Gather layer inputs.
   1007             inbound_nodes_data = layer_data['inbound_nodes']
-> 1008             for node_data in inbound_nodes_data:
   1009                 # We don't process nodes (i.e. make layer calls)
   1010                 # on the fly because the inbound node may not yet exist,

~/code/data-science/tflite_face_recognition/model/venv/lib/python3.6/site-packages/keras/layers/__init__.py in deserialize(config, custom_objects)
     53                                     module_objects=globs,
     54                                     custom_objects=custom_objects,
---> 55                                     printable_module_name='layer')

~/code/data-science/tflite_face_recognition/model/venv/lib/python3.6/site-packages/keras/utils/generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    145                                         list(custom_objects.items())))
    146             with CustomObjectScope(custom_objects):
--> 147                 return cls.from_config(config['config'])
    148         else:
    149             # Then `cls` may be a function returning a class.

~/code/data-science/tflite_face_recognition/model/venv/lib/python3.6/site-packages/keras/engine/base_layer.py in from_config(cls, config)
   1107             A layer instance.
   1108         """
-> 1109         return cls(**config)
   1110 
   1111     def count_params(self):

~/code/data-science/tflite_face_recognition/model/venv/lib/python3.6/site-packages/keras/layers/convolutional.py in __init__(self, kernel_size, strides, padding, depth_multiplier, data_format, activation, use_bias, depthwise_initializer, bias_initializer, depthwise_regularizer, bias_regularizer, activity_regularizer, depthwise_constraint, bias_constraint, **kwargs)
   1795             regularizer=self.depthwise_regularizer,
   1796             constraint=self.depthwise_constraint)
-> 1797 
   1798         if self.use_bias:
   1799             self.bias = self.add_weight(shape=(input_dim * self.depth_multiplier,),

TypeError: __init__() got multiple values for keyword argument 'filters'
@jvishnuvardhan jvishnuvardhan added type:tensorFlow type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited. labels Feb 22, 2019
@zrx1046
Copy link

zrx1046 commented Jun 20, 2019

Hello, how do you solve this problem, I am also a custom function, the following problems arise:
TypeError: init() missing 1 required positional arguments: 'pool_size'

@zrx1046
Copy link

zrx1046 commented Jun 24, 2019

@beNitinhere Hello, how do you solve this problem, I am also a custom function, the following problems arise:
TypeError: init() missing 1 required positional arguments: 'pool_size'

@nitink133
Copy link
Author

@zrx1046 Hi, Sorry for the late response. This is a bug in Keras which is still not fixed and In my case I just reprogrammed my model in tensorflow

@zrx1046
Copy link

zrx1046 commented Jun 28, 2019

@beNitinhere OK. Thank you for your reply. I'll find the answer again.

@xup5
Copy link

xup5 commented Dec 11, 2019

@zrx1046 Do you include 'pool_size' in overwrited get_config()?

@AliSheheryar
Copy link

What do you mean by reprogramming the code. nitik133???
I still have to use keras and tf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.
Projects
None yet
Development

No branches or pull requests

6 participants