简体   繁体   English

ValueError: None 仅在第一维中受支持。 张量“input_tensor”的形状无效“[1, None, None, 3]”

[英]ValueError: None is only supported in the 1st dimension. Tensor 'input_tensor' has invalid shape '[1, None, None, 3]'

I trained a custom MobileNetV2 SSD model for object detection.我训练了一个用于对象检测的自定义 MobileNetV2 SSD 模型。 I saved the .pb file and now I want to convert it into a .tflite-file in order to use it with Coral edge-tpu.我保存了 .pb 文件,现在我想将其转换为 .tflite 文件,以便与 Coral edge-tpu 一起使用。

I use Tensorflow 2.2 on Windows 10 on CPU.我在 CPU 上的 Windows 10 上使用 Tensorflow 2.2。

The code I'm using:我正在使用的代码:

import tensorflow as tf

saved_model_dir = r"C:/Tensorflow/Backup_Training/my_MobileNetV2_fpnlite_320x320/saved_model"
num_calibration_steps = 100

def representative_dataset_gen():
    for _ in range(num_calibration_steps):
        # Get sample input data as a numpy array
        yield [np.random.uniform(0.0, 1.0, size=(1,416,416, 3)).astype(np.float32)]

converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
converter.optimizations = [tf.lite.Optimize.DEFAULT]

converter.experimental_new_converter = True

converter.representative_dataset = representative_dataset_gen
converter.target_spec.supported_ops = [
    #tf.lite.OpsSet.TFLITE_BUILTINS_INT8,
    tf.lite.OpsSet.TFLITE_BUILTINS,
    tf.lite.OpsSet.SELECT_TF_OPS
    ]
converter.inference_input_type = tf.int8
converter.inference_output_type = tf.int8

tflite_quant_model = converter.convert()

with open('model.tflite', 'wb') as f:
    f.write(tflite_model)

I tried several proposed solutions from other threads and I also tried it with tf-nightly, tf2.3 & tf1.14 but none of it worked (there was always another error message I couldn't handle).我尝试了来自其他线程的几个建议的解决方案,我也尝试过 tf-nightly、tf2.3 和 tf1.14,但都没有奏效(总是有另一个我无法处理的错误消息)。 Since I trained with tf2.2 I thought it might be a good idea to proceed with tf2.2.由于我使用 tf2.2 进行培训,因此我认为继续使用 tf2.2 可能是个好主意。

Since I'm new to Tensorflow I have several questions: what exactly is the input tensor and where do I define it?由于我是 Tensorflow 的新手,我有几个问题:输入张量到底是什么以及我在哪里定义它? Is there a possibility to see or extract this input tensor?有没有可能看到或提取这个输入张量? Does anybody know how to fix this issue?有谁知道如何解决这个问题?

The whole error message:整个错误信息:

(tf22) C:\Tensorflow\Backup_Training>python full_int_quant.py
2020-10-22 14:51:20.460948: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-10-22 14:51:20.466366: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2020-10-22 14:51:29.231404: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2020-10-22 14:51:29.239003: E tensorflow/stream_executor/cuda/cuda_driver.cc:313] failed call to cuInit: UNKNOWN ERROR (303)
2020-10-22 14:51:29.250497: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: ip3536
2020-10-22 14:51:29.258432: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: ip3536
2020-10-22 14:51:29.269261: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2020-10-22 14:51:29.291457: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x2ae2ac3ffc0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-10-22 14:51:29.298043: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-10-22 14:52:03.785341: I tensorflow/core/grappler/devices.cc:55] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0
2020-10-22 14:52:03.790251: I tensorflow/core/grappler/clusters/single_machine.cc:356] Starting new session
2020-10-22 14:52:04.559832: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:797] Optimization results for grappler item: graph_to_optimize
2020-10-22 14:52:04.564529: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: Graph size after: 3672 nodes (3263), 5969 edges (5553), time = 136.265ms.
2020-10-22 14:52:04.570187: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   function_optimizer: function_optimizer did nothing. time = 2.637ms.
2020-10-22 14:52:10.742013: I tensorflow/core/grappler/devices.cc:55] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0
2020-10-22 14:52:10.746868: I tensorflow/core/grappler/clusters/single_machine.cc:356] Starting new session
2020-10-22 14:52:12.358897: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:797] Optimization results for grappler item: graph_to_optimize
2020-10-22 14:52:12.363657: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   constant_folding: Graph size after: 1714 nodes (-1958), 2661 edges (-3308), time = 900.347ms.
2020-10-22 14:52:12.369137: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:799]   constant_folding: Graph size after: 1714 nodes (0), 2661 edges (0), time = 60.628ms.
Traceback (most recent call last):
  File "full_int_quant.py", line 40, in <module>
    tflite_model = converter.convert()
  File "C:\Users\schulzyk\Anaconda3\envs\tf22\lib\site-packages\tensorflow\lite\python\lite.py", line 480, in convert
    raise ValueError(
ValueError: None is only supported in the 1st dimension. Tensor 'input_tensor' has invalid shape '[1, None, None, 3]'.

Whatever I change in the code, there is always the same error message.无论我如何更改代码,总是有相同的错误信息。 I don't know if this is a sign that during training something went wrong but there were no eye-catching occurences.我不知道这是否是训练过程中出现问题但没有引人注目的迹象。

I'd be happy for any kind of feedback!我很高兴收到任何反馈!

Ahh, object detection API with tensorflow 2.0 for coral is still a WIP.啊,带有 tensorflow 2.0 的珊瑚对象检测 API 仍然是一个 WIP。 We are having many roadblocks and may not see this feature soon.我们遇到了很多障碍,可能不会很快看到此功能。 I suggest using tf1.x aPI for now.我建议现在使用 tf1.x API。 Here is a good tutorial :) https://github.com/Namburger/edgetpu-ssdlite-mobiledet-retrain这是一个很好的教程:) https://github.com/Namburger/edgetpu-ssdlite-mobiledet-retrain

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

相关问题 ValueError: None 仅在第一维中受支持。 张量“flatbuffer_data”的形状无效“[None, None, 1, 512]” - ValueError: None is only supported in the 1st dimension. Tensor 'flatbuffer_data' has invalid shape '[None, None, 1, 512]' 张量“embedding_input”的形状无效“[None, None]” - Tensor 'embedding_input' has invalid shape '[None, None]' 加载集合 keras model 给出 ValueError: Invalid input_shape argument (None, 224, 224, 3): Z20F35E630DAF44DBFA4C3F608F5399D8C 有输入 - Loading ensemble keras model gives ValueError: Invalid input_shape argument (None, 224, 224, 3): model has 0 tensor inputs 张量的 ValueError(“变量 {} 有 `None` 的梯度。”) - ValueError(“Variable {} has `None` for gradient. ”) for Tensor 使用占位符创建时,Tensor的形状为[无,无] - Tensor has shape [None, None] when created with placeholders 如何切片张量为“无”的张量? - How to slice a tensor with 'None' dimension? tensorflow 向张量添加“无”维度 - tensorflow add 'None' dimension to a tensor keras:用无尺寸重整张量 - keras: reshape a tensor with None dimension 通道尺寸“无”,但是已通过tensor.get_shape()进行了定义 - Channel dimension Found 'None', however through tensor.get_shape() it has been defined ValueError:Tensor(“inputs:0”, shape=(None, 256, 256, 3), dtype=uint8) - ValueError:Tensor(“inputs:0”, shape=(None, 256, 256, 3), dtype=uint8)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM