This is the stack trace I'm getting when trying to instanciate a NudeClassifier
. A pretty much identical error occurs when trying to instanciate a NudeDetector
.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-9-7465e1bf88d0> in <module>
----> 1 classifier = NudeClassifier()
~\Python\portable\python\Lib\site-packages\nudenet\classifier.py in __init__(self)
137 pydload.dload(url, save_to_path=model_path, max_time=None)
138
--> 139 self.nsfw_model = keras.models.load_model(model_path)
140
141 def classify_video(
~\Python\portable\python\Lib\site-packages\keras\engine\saving.py in load_model(filepath, custom_objects, compile)
417 f = h5dict(filepath, 'r')
418 try:
--> 419 model = _deserialize_model(f, custom_objects, compile)
420 finally:
421 if opened_new_file:
~\Python\portable\python\Lib\site-packages\keras\engine\saving.py in _deserialize_model(f, custom_objects, compile)
223 raise ValueError('No model found in config.')
224 model_config = json.loads(model_config.decode('utf-8'))
--> 225 model = model_from_config(model_config, custom_objects=custom_objects)
226 model_weights_group = f['model_weights']
227
~\Python\portable\python\Lib\site-packages\keras\engine\saving.py in model_from_config(config, custom_objects)
456 '`Sequential.from_config(config)`?')
457 from ..layers import deserialize
--> 458 return deserialize(config, custom_objects=custom_objects)
459
460
~\Python\portable\python\Lib\site-packages\keras\layers\__init__.py in deserialize(config, custom_objects)
50 globs['Model'] = models.Model
51 globs['Sequential'] = models.Sequential
---> 52 return deserialize_keras_object(config,
53 module_objects=globs,
54 custom_objects=custom_objects,
~\Python\portable\python\Lib\site-packages\keras\utils\generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
140 custom_objects = custom_objects or {}
141 if has_arg(cls.from_config, 'custom_objects'):
--> 142 return cls.from_config(
143 config['config'],
144 custom_objects=dict(list(_GLOBAL_CUSTOM_OBJECTS.items()) +
~\Python\portable\python\Lib\site-packages\keras\engine\network.py in from_config(cls, config, custom_objects)
1020 # First, we create all layers and enqueue nodes to be processed
1021 for layer_data in config['layers']:
-> 1022 process_layer(layer_data)
1023 # Then we process nodes in order of layer depth.
1024 # Nodes that cannot yet be processed (if the inbound node
~\Python\portable\python\Lib\site-packages\keras\engine\network.py in process_layer(layer_data)
1005 from ..layers import deserialize as deserialize_layer
1006
-> 1007 layer = deserialize_layer(layer_data,
1008 custom_objects=custom_objects)
1009 created_layers[layer_name] = layer
~\Python\portable\python\Lib\site-packages\keras\layers\__init__.py in deserialize(config, custom_objects)
50 globs['Model'] = models.Model
51 globs['Sequential'] = models.Sequential
---> 52 return deserialize_keras_object(config,
53 module_objects=globs,
54 custom_objects=custom_objects,
~\Python\portable\python\Lib\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.
~\Python\portable\python\Lib\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):
~\Python\portable\python\Lib\site-packages\keras\legacy\interfaces.py in wrapper(*args, **kwargs)
89 warnings.warn('Update your `' + object_name + '` call to the ' +
90 'Keras 2 API: ' + signature, stacklevel=2)
---> 91 return func(*args, **kwargs)
92 wrapper._original_function = func
93 return wrapper
~\Python\portable\python\Lib\site-packages\keras\engine\input_layer.py in __init__(self, input_shape, batch_size, batch_input_shape, dtype, input_tensor, sparse, name)
82 if input_tensor is None:
83 self.is_placeholder = True
---> 84 input_tensor = K.placeholder(shape=batch_input_shape,
85 dtype=dtype,
86 sparse=self.sparse,
~\Python\portable\python\Lib\site-packages\keras\backend\tensorflow_backend.py in placeholder(shape, ndim, dtype, sparse, name)
515 x = tf.sparse_placeholder(dtype, shape=shape, name=name)
516 else:
--> 517 x = tf.placeholder(dtype, shape=shape, name=name)
518 x._keras_shape = shape
519 x._uses_learning_phase = False
AttributeError: module 'tensorflow' has no attribute 'placeholder'
I've googled around and these seem to be issues with Keras that have since been fixed? Basically, when I use keras==2.2.4 (which is listed in this library's setup.py) I can't get past this stage.
I've tried upgrading to the latest version of keras for my own curiosity (keras==2.4.3) and the NudeClassifier
then works perfectly! However, the NudeDetector
now errors like this when I try to instanciate it:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-8-c0ac40df705b> in <module>
----> 1 detector = NudeDetector()
~\Python\portable\python\Lib\site-packages\nudenet\detector.py in __init__(self, model_name)
76 pydload.dload(classes_url, save_to_path=classes_path, max_time=None)
77
---> 78 self.detection_model = models.load_model(
79 checkpoint_path, backbone_name="resnet50"
80 )
~\Python\portable\python\Lib\site-packages\keras_retinanet\models\__init__.py in load_model(filepath, backbone_name)
81 """
82 import keras.models
---> 83 return keras.models.load_model(filepath, custom_objects=backbone(backbone_name).custom_objects)
84
85
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\saving\save.py in load_model(filepath, custom_objects, compile, options)
180 if (h5py is not None and (
181 isinstance(filepath, h5py.File) or h5py.is_hdf5(filepath))):
--> 182 return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
183
184 filepath = path_to_string(filepath)
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\saving\hdf5_format.py in load_model_from_hdf5(filepath, custom_objects, compile)
175 raise ValueError('No model found in config file.')
176 model_config = json.loads(model_config.decode('utf-8'))
--> 177 model = model_config_lib.model_from_config(model_config,
178 custom_objects=custom_objects)
179
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\saving\model_config.py in model_from_config(config, custom_objects)
53 '`Sequential.from_config(config)`?')
54 from tensorflow.python.keras.layers import deserialize # pylint: disable=g-import-not-at-top
---> 55 return deserialize(config, custom_objects=custom_objects)
56
57
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\layers\serialization.py in deserialize(config, custom_objects)
169 """
170 populate_deserializable_objects()
--> 171 return generic_utils.deserialize_keras_object(
172 config,
173 module_objects=LOCAL.ALL_OBJECTS,
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\utils\generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
352
353 if 'custom_objects' in arg_spec.args:
--> 354 return cls.from_config(
355 cls_config,
356 custom_objects=dict(
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\training.py in from_config(cls, config, custom_objects)
2236 # be constructed for FunctionalModel
2237 from tensorflow.python.keras.engine import functional # pylint: disable=g-import-not-at-top
-> 2238 return functional.Functional.from_config(
2239 config, custom_objects=custom_objects)
2240
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\functional.py in from_config(cls, config, custom_objects)
614 ValueError: In case of improperly formatted config dict.
615 """
--> 616 input_tensors, output_tensors, created_layers = reconstruct_from_config(
617 config, custom_objects)
618 model = cls(inputs=input_tensors, outputs=output_tensors,
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\functional.py in reconstruct_from_config(config, custom_objects, created_layers)
1202 # First, we create all layers and enqueue nodes to be processed
1203 for layer_data in config['layers']:
-> 1204 process_layer(layer_data)
1205 # Then we process nodes in order of layer depth.
1206 # Nodes that cannot yet be processed (if the inbound node
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\functional.py in process_layer(layer_data)
1184 from tensorflow.python.keras.layers import deserialize as deserialize_layer # pylint: disable=g-import-not-at-top
1185
-> 1186 layer = deserialize_layer(layer_data, custom_objects=custom_objects)
1187 created_layers[layer_name] = layer
1188
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\layers\serialization.py in deserialize(config, custom_objects)
169 """
170 populate_deserializable_objects()
--> 171 return generic_utils.deserialize_keras_object(
172 config,
173 module_objects=LOCAL.ALL_OBJECTS,
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\utils\generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
352
353 if 'custom_objects' in arg_spec.args:
--> 354 return cls.from_config(
355 cls_config,
356 custom_objects=dict(
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\training.py in from_config(cls, config, custom_objects)
2236 # be constructed for FunctionalModel
2237 from tensorflow.python.keras.engine import functional # pylint: disable=g-import-not-at-top
-> 2238 return functional.Functional.from_config(
2239 config, custom_objects=custom_objects)
2240
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\functional.py in from_config(cls, config, custom_objects)
614 ValueError: In case of improperly formatted config dict.
615 """
--> 616 input_tensors, output_tensors, created_layers = reconstruct_from_config(
617 config, custom_objects)
618 model = cls(inputs=input_tensors, outputs=output_tensors,
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\functional.py in reconstruct_from_config(config, custom_objects, created_layers)
1212 if layer in unprocessed_nodes:
1213 for node_data in unprocessed_nodes.pop(layer):
-> 1214 process_node(layer, node_data)
1215
1216 input_tensors = []
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\functional.py in process_node(layer, node_data)
1160 if input_tensors is not None:
1161 input_tensors = base_layer_utils.unnest_if_single_tensor(input_tensors)
-> 1162 output_tensors = layer(input_tensors, **kwargs)
1163
1164 # Update node index map.
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\base_layer.py in __call__(self, *args, **kwargs)
923 # >> model = tf.keras.Model(inputs, outputs)
924 if _in_functional_construction_mode(self, inputs, args, kwargs, input_list):
--> 925 return self._functional_construction_call(inputs, args, kwargs,
926 input_list)
927
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list)
1096 # Build layer if applicable (if the `build` method has been
1097 # overridden).
-> 1098 self._maybe_build(inputs)
1099 cast_inputs = self._maybe_cast_inputs(inputs, input_list)
1100
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\base_layer.py in _maybe_build(self, inputs)
2641 # operations.
2642 with tf_utils.maybe_init_scope(self):
-> 2643 self.build(input_shapes) # pylint:disable=not-callable
2644 # We must set also ensure that the layer is marked as built, and the build
2645 # shape is stored since user defined build functions may not be calling
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\layers\convolutional.py in build(self, input_shape)
204 dtype=self.dtype)
205 if self.use_bias:
--> 206 self.bias = self.add_weight(
207 name='bias',
208 shape=(self.filters,),
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\base_layer.py in add_weight(self, name, shape, dtype, initializer, regularizer, trainable, constraint, partitioner, use_resource, synchronization, aggregation, **kwargs)
595 caching_device = None
596
--> 597 variable = self._add_variable_with_custom_getter(
598 name=name,
599 shape=shape,
~\Python\portable\python\Lib\site-packages\tensorflow\python\training\tracking\base.py in _add_variable_with_custom_getter(self, name, shape, dtype, initializer, getter, overwrite, **kwargs_for_getter)
743 initializer = checkpoint_initializer
744 shape = None
--> 745 new_variable = getter(
746 name=name,
747 shape=shape,
~\Python\portable\python\Lib\site-packages\tensorflow\python\keras\engine\base_layer_utils.py in make_variable(name, shape, dtype, initializer, trainable, caching_device, validate_shape, constraint, use_resource, collections, synchronization, aggregation, partitioner)
131 # can remove the V1.
132 variable_shape = tensor_shape.TensorShape(shape)
--> 133 return tf_variables.VariableV1(
134 initial_value=init_val,
135 name=name,
~\Python\portable\python\Lib\site-packages\tensorflow\python\ops\variables.py in __call__(cls, *args, **kwargs)
258 def __call__(cls, *args, **kwargs):
259 if cls is VariableV1:
--> 260 return cls._variable_v1_call(*args, **kwargs)
261 elif cls is Variable:
262 return cls._variable_v2_call(*args, **kwargs)
~\Python\portable\python\Lib\site-packages\tensorflow\python\ops\variables.py in _variable_v1_call(cls, initial_value, trainable, collections, validate_shape, caching_device, name, variable_def, dtype, expected_shape, import_scope, constraint, use_resource, synchronization, aggregation, shape)
204 if aggregation is None:
205 aggregation = VariableAggregation.NONE
--> 206 return previous_getter(
207 initial_value=initial_value,
208 trainable=trainable,
~\Python\portable\python\Lib\site-packages\tensorflow\python\ops\variables.py in <lambda>(**kwargs)
197 shape=None):
198 """Call on Variable class. Useful to force the signature."""
--> 199 previous_getter = lambda **kwargs: default_variable_creator(None, **kwargs)
200 for _, getter in ops.get_default_graph()._variable_creator_stack: # pylint: disable=protected-access
201 previous_getter = _make_getter(getter, previous_getter)
~\Python\portable\python\Lib\site-packages\tensorflow\python\ops\variable_scope.py in default_variable_creator(next_creator, **kwargs)
2581 if use_resource:
2582 distribute_strategy = kwargs.get("distribute_strategy", None)
-> 2583 return resource_variable_ops.ResourceVariable(
2584 initial_value=initial_value,
2585 trainable=trainable,
~\Python\portable\python\Lib\site-packages\tensorflow\python\ops\variables.py in __call__(cls, *args, **kwargs)
262 return cls._variable_v2_call(*args, **kwargs)
263 else:
--> 264 return super(VariableMetaclass, cls).__call__(*args, **kwargs)
265
266
~\Python\portable\python\Lib\site-packages\tensorflow\python\ops\resource_variable_ops.py in __init__(self, initial_value, trainable, collections, validate_shape, caching_device, name, dtype, variable_def, import_scope, constraint, distribute_strategy, synchronization, aggregation, shape)
1505 self._init_from_proto(variable_def, import_scope=import_scope)
1506 else:
-> 1507 self._init_from_args(
1508 initial_value=initial_value,
1509 trainable=trainable,
~\Python\portable\python\Lib\site-packages\tensorflow\python\ops\resource_variable_ops.py in _init_from_args(self, initial_value, trainable, collections, caching_device, name, dtype, constraint, synchronization, aggregation, distribute_strategy, shape)
1649 with ops.name_scope("Initializer"), device_context_manager(None):
1650 initial_value = ops.convert_to_tensor(
-> 1651 initial_value() if init_from_fn else initial_value,
1652 name="initial_value", dtype=dtype)
1653 if shape is not None:
~\Python\portable\python\Lib\site-packages\keras_retinanet\initializers.py in __call__(self, shape, dtype)
35 def __call__(self, shape, dtype=None):
36 # set bias to -log((1 - p)/p) for foreground
---> 37 result = np.ones(shape, dtype=dtype) * -math.log((1 - self.probability) / self.probability)
38
39 return result
~\Python\portable\python\Lib\site-packages\numpy\core\numeric.py in ones(shape, dtype, order)
205
206 """
--> 207 a = empty(shape, dtype, order)
208 multiarray.copyto(a, 1, casting='unsafe')
209 return a
TypeError: data type not understood
Do you know why this is happening? I'd love to play around with this library but I can't figure out how to get past these errors.
If it helps, I'm running Python 3.8.2
Thanks in advance!
Support TF new versions