Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix AttributeError: module 'tensorflow' has no attribute 'space_to_depth'

I have python 3.7.4 installed and tensorflow version 2.2.0 installed on my Windows 10 x64. I am trying to execute this:

yolo_model = load_model("model_data/yolo.h5")

And it gives the mentioned error

Here is the stack trace:

Traceback (most recent call last):

 File "Object Detection.py", line 78, in <module>
    yolo_model = load_model("model_data/yolo.h5")
  File "E:\Python37\lib\site-packages\keras\engine\saving.py", line 492, in load_wrapper
    return load_function(*args, **kwargs)
  File "E:\Python37\lib\site-packages\keras\engine\saving.py", line 584, in load_model
    model = _deserialize_model(h5dict, custom_objects, compile)
  File "E:\Python37\lib\site-packages\keras\engine\saving.py", line 274, in _deserialize_model
    model = model_from_config(model_config, custom_objects=custom_objects)
  File "E:\Python37\lib\site-packages\keras\engine\saving.py", line 627, in model_from_config
    return deserialize(config, custom_objects=custom_objects)
  File "E:\Python37\lib\site-packages\keras\layers\__init__.py", line 168, in deserialize
    printable_module_name='layer')
  File "E:\Python37\lib\site-packages\keras\utils\generic_utils.py", line 147, in deserialize_keras_object
    list(custom_objects.items())))
  File "E:\Python37\lib\site-packages\keras\engine\network.py", line 1075, in from_config
    process_node(layer, node_data)
  File "E:\Python37\lib\site-packages\keras\engine\network.py", line 1025, in process_node
    layer(unpack_singleton(input_tensors), **kwargs)
  File "E:\Python37\lib\site-packages\keras\backend\tensorflow_backend.py", line 75, in symbolic_fn_wrapper
    return func(*args, **kwargs)
  File "E:\Python37\lib\site-packages\keras\engine\base_layer.py", line 489, in __call__
    output = self.call(inputs, **kwargs)
  File "E:\Python37\lib\site-packages\keras\layers\core.py", line 716, in call
    return self.function(inputs, **arguments)
  File "/Users/kian/Desktop/floydhub/yolo-03-oct/YAD2K/yad2k/models/keras_yolo.py", line 32, in space_to_depth_x2
AttributeError: module 'tensorflow' has no attribute 'space_to_depth'
like image 379
Joel Shaji Avatar asked Mar 03 '23 10:03

Joel Shaji


1 Answers

I think location of module is different, FYI

  • tensorflow 1.x : tensorflow.space_to_depth
  • tensorflow 2.x : tensorflow.nn.space_to_depth
like image 146
user14278571 Avatar answered Mar 05 '23 16:03

user14278571