keras-retinanet: Loading model fails
Running on MacOS, Docker Desktop 2.3.0.3, python:3.7 image. Installed all dependencies. When loading model resnet50_coco_best_v2.1.0.h5 following log ends up with error
Code pretty straightforward:
from keras_retinanet.models import load_model model = load_model('./models/resnet50_coco_best_v2.1.0.h5', backbone_name='resnet50')
Using TensorFlow backend.
2020-06-23 03:53:58.307402: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2020-06-23 03:53:58.307474: E tensorflow/stream_executor/cuda/cuda_driver.cc:313] failed call to cuInit: UNKNOWN ERROR (303)
2020-06-23 03:53:58.307510: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (c701da7b5de1): /proc/driver/nvidia/version does not exist
2020-06-23 03:53:58.307683: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-06-23 03:53:58.313914: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 2592000000 Hz
2020-06-23 03:53:58.314329: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7f1404000b20 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-06-23 03:53:58.314386: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
Traceback (most recent call last):
File "conertmodel.py", line 2, in <module>
model = load_model('./models/resnet50_coco_best_v2.1.0.h5', backbone_name='resnet50')
File "/usr/local/lib/python3.7/site-packages/keras_retinanet/models/__init__.py", line 87, in load_model
return keras.models.load_model(filepath, custom_objects=backbone(backbone_name).custom_objects)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/saving/save.py", line 184, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 178, in load_model_from_hdf5
custom_objects=custom_objects)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/saving/model_config.py", line 55, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/layers/serialization.py", line 109, in deserialize
printable_module_name='layer')
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 373, in deserialize_keras_object
list(custom_objects.items())))
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/engine/network.py", line 987, in from_config
config, custom_objects)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/engine/network.py", line 2019, in reconstruct_from_config
process_layer(layer_data)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/engine/network.py", line 2001, in process_layer
layer = deserialize_layer(layer_data, custom_objects=custom_objects)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/layers/serialization.py", line 109, in deserialize
printable_module_name='layer')
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 373, in deserialize_keras_object
list(custom_objects.items())))
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/engine/network.py", line 987, in from_config
config, custom_objects)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/engine/network.py", line 2029, in reconstruct_from_config
process_node(layer, node_data)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/engine/network.py", line 1977, in process_node
output_tensors = layer(input_tensors, **kwargs)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 897, in __call__
self._maybe_build(inputs)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 2416, in _maybe_build
self.build(input_shapes) # pylint:disable=not-callable
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/layers/convolutional.py", line 172, in build
dtype=self.dtype)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 577, in add_weight
caching_device=caching_device)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/training/tracking/base.py", line 743, in _add_variable_with_custom_getter
**kwargs_for_getter)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 141, in make_variable
shape=variable_shape if variable_shape else None)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/variables.py", line 259, in __call__
return cls._variable_v1_call(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/variables.py", line 220, in _variable_v1_call
shape=shape)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/variables.py", line 198, in <lambda>
previous_getter = lambda **kwargs: default_variable_creator(None, **kwargs)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/variable_scope.py", line 2598, in default_variable_creator
shape=shape)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/variables.py", line 263, in __call__
return super(VariableMetaclass, cls).__call__(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 1434, in __init__
distribute_strategy=distribute_strategy)
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 1567, in _init_from_args
initial_value() if init_from_fn else initial_value,
File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 121, in <lambda>
init_val = lambda: initializer(shape, dtype=dtype)
File "/usr/local/lib/python3.7/site-packages/keras_retinanet/initializers.py", line 37, in __call__
result = np.ones(shape, dtype=dtype) * -math.log((1 - self.probability) / self.probability)
File "/usr/local/lib/python3.7/site-packages/numpy/core/numeric.py", line 192, in ones
a = empty(shape, dtype, order)
TypeError: Cannot interpret 'tf.float32' as a data type
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 20 (1 by maintainers)
I had the same problem. Turns out that 8 days ago Keras updated to version 2.4 with a note saying that some workflows may break. I rolled back to keras 2.3.1 and everything worked again:
pip3 install keras==2.3.1
Try downgrading Tf=2.1, it solved this problem to me. i changed my original comment to make it more understandable š
Seems that Colab has changed the versions of Keras and TF. This problems are solved downgrading Keras and TF to versions Keras=2.3.1 and TF=2.1. Using newer versions of Keras and Tensorflow make this problem appear. Hope it helps.
Iām having the same issue with python3.8.