简体   繁体   English

运行 yad2k 以生成模型 h5 文件时,“tensorflow”在 tensorflow 2.3 中没有属性“space_to_depth”错误

[英]'tensorflow' has no attribute 'space_to_depth' error with tensorflow 2.3 when running yad2k to generate model h5 file

I am trying to generate YOLOv2 model yolo.h5 so that I can load this pre-trained model.我正在尝试生成 YOLOv2 模型 yolo.h5 以便我可以加载这个预先训练的模型。 I am trying to port Andrew Ng coursera Yolo assignment ( which runs in tensorflow 1.x) to tensorflow 2.3.我正在尝试将 Andrew Ng coursera Yolo 作业(在 tensorflow 1.x 中运行)移植到 tensorflow 2.3。

I was able to cleanly port it thanks to tensorflow uprade ( https://www.tensorflow.org/guide/upgrade ), But little did I realize that I cannot download the yolo.h5 file ( either its get corrupted or the download times out) and therefore I thought I should build one and I followed instructions from https://github.com/JudasDie/deeplearning.ai/issues/2 .由于 tensorflow uprade ( https://www.tensorflow.org/guide/upgrade ),我能够干净利落地移植它,但我几乎没有意识到我无法下载 yolo.h5 文件(要么它被损坏要么下载时间out),因此我认为我应该构建一个,并按照https://github.com/JudasDie/deeplearning.ai/issues/2 的说明进行操作。 It looked pretty straight forward as I cloned YAD2k repo and downloaded both the yolo.weights and yolo.cfg.当我克隆 YAD2k 存储库并下载 yolo.weights 和 yolo.cfg 时,它看起来非常简单。 I ran the following the command as per the instructions:我按照说明运行了以下命令:

python yad2k.py yolo.cfg yolo.weights model_data/yolo.h5 python yad2k.py yolo.cfg yolo.weights 模型数据/yolo.h5

But I got the following error:-但我收到以下错误:-

Traceback (most recent call last):
  _main(parser.parse_args())
File "yad2k.py", line 233, in _main
  Lambda(
File "/home/sunny/miniconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 
925, in __call__
  return self._functional_construction_call(inputs, args, kwargs,
File "/home/sunny/miniconda3/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 
1117, in _functional_construction_call
  outputs = call_fn(cast_inputs, *args, **kwargs)
File "/home/sunny/miniconda3/lib/python3.8/site-packages/tensorflow/python/keras/layers/core.py", line 903, i
n call
  result = self.function(inputs, **kwargs)
File "/home/sunny/YAD2K/yad2k/models/keras_yolo.py", line 32, in space_to_depth_x2
  return tf.space_to_depth(x, block_size=2)
AttributeError: module 'tensorflow' has no attribute 'space_to_depth'

From the all chats I figured out that the above needs to run in tensorflow 1.x .从所有聊天中我发现上述需要在 tensorflow 1.x 中运行。 However it puts me back where I started which is to run it in tensorflow 1.x.然而,它让我回到了开始的地方,即在 tensorflow 1.x 中运行它。 I would love to stick with tensorflow 2.3.我很想坚持使用 tensorflow 2.3。

Wondering if someone can guide me here.想知道是否有人可以在这里指导我。 Frankly, to get me going all I need is an model hd5 file.坦率地说,为了让我继续下去,我只需要一个模型 hd5 文件。 But I thought generating one would be a better learning than to get one.但我认为生成一个比得到一个更好的学习。

The above problem goes away when you upgrade all of your code under yad2k repo ( particularly yad2k.py and python files under models folder to tensorflow 2.x. The beautiful upgrade utility provided by tensorflow does the magic for you by replacing the original call to the compatible tf.compat.v1.space_to_depth(input=x, block_size=...)当您将 yad2k 存储库下的所有代码(特别是模型文件夹下的 yad2k.py 和 python 文件)升级到 tensorflow 2.x 时,上述问题就会消失。tensorflow 提供的漂亮升级实用程序通过替换对兼容的tf.compat.v1.space_to_depth(input=x, block_size=...)

Therefore for those who are planning to do the hard job of downgrading their tensorflow and keras, I would recommend them to try the tensorflow upgrade.因此,对于那些计划努力降级 tensorflow 和 keras 的人,我建议他们尝试升级 tensorflow。 This saves a lot of time.这样可以节省很多时间。

This takes care of my model h5 file creation.这负责我的模型 h5 文件创建。 My bad - I didn't think about it when I asking the question.我的不好 - 我问这个问题时没有考虑过。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tensorflow keras model 保存为h5文件时出现类型错误 - Type Error when saving Tensorflow keras model as h5 file 将模型另存为 H5 或 SavedModel 时出现 TensorFlow Hub 错误 - TensorFlow Hub error when Saving model as H5 or SavedModel 加载 Tensorflow keras Model (.h5) 时出错 - Error loading Tensorflow keras Model (.h5) (AttributeError: 'NoneType' 对象没有属性 'get' ) 在 tensorflow 2.1 中加载带有 .h5 扩展名的已保存 keras 模型 - (AttributeError: 'NoneType' object has no attribute 'get' ) while loading saved keras model with .h5 extension in tensorflow 2.1 尝试保存 tensorflow model 时,模块“h5py”没有属性“文件” - module 'h5py' has no attribute 'File' when trying to save a tensorflow model 加载在线托管的 TensorFlow (.h5) 模型 - Load a TensorFlow (.h5) model hosted online Tensorflow Object 检测 API - 错误运行 model_builder_test.py 模块 'tensorflow' 没有属性 'contrib' - Tensorflow Object Detection API - Error running model_builder_test.py module 'tensorflow' has no attribute 'contrib' 如何使用张量流模型从H5中获得预测 - How do I get a prediction out of a h5 with tensorflow model 通过相对路径保存 h5 模型 - Keras tensorflow - Saving h5 model by relative path - Keras tensorflow 在 virtualenv 中运行 tensorflow 时出错:模块 'tensorflow' 没有属性 'truncated_normal' - Error when running tensorflow in virtualenv: module 'tensorflow' has no attribute 'truncated_normal'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM