使用Intel OpenVINO Model Optimizer转换TensorFlow模型报错求助
技术求助:TensorFlow模型转OpenVINO报错处理
问题详情
我用以下代码保存图像分类模型:
import tensorflow as tf model = tf.keras.models.load_model('model.h5') tf.saved_model.save(model,'model')
环境信息
- Google Colab上TensorFlow版本:2.9.2
- 本地Intel OpenVINO开发工具版本:2021.4.2 LTS
执行命令及报错
运行Model Optimizer命令后出现框架错误,命令及完整输出如下:
C:\Program Files (x86)\Intel\openvino_2021.4.752\deployment_tools\model_optimizer>python mo_tf.py --saved_model_dir C:\Users\dchoi\CNNProejct_Only_saved_English\saved_model --input_shape [1,32,320,240,3] --output_dir C:\Users\dchoi\CNNproject_only_output_English\output_model Model Optimizer arguments: Common parameters: - Path to the Input Model: None - Path for generated IR: C:\Users\dchoi\CNNproject_only_output_English\output_model - IR output name: saved_model - Log level: ERROR - Batch: Not specified, inherited from the model - Input layers: Not specified, inherited from the model - Output layers: Not specified, inherited from the model - Input shapes: [1,32,320,240,3] - Mean values: Not specified - Scale values: Not specified - Scale factor: Not specified - Precision of IR: FP32 - Enable fusing: True - Enable grouped convolutions fusing: True - Move mean values to preprocess section: None - Reverse input channels: False TensorFlow specific parameters: - Input model in text protobuf format: False - Path to model dump for TensorBoard: None - List of shared libraries with TensorFlow custom layers implementation: None - Update the configuration file with input/output node names: None - Use configuration file used to generate the model with Object Detection API: None - Use the config file: None - Inference Engine found in: C:\Users\dchoi\AppData\Local\Programs\Python\Python38\lib\site-packages\openvino Inference Engine version: 2021.4.0-3839-cd81789d294-releases/2021/4 Model Optimizer version: 2021.4.2-3974-e2a469a3450-releases/2021/4 [ WARNING ] Model Optimizer and Inference Engine versions do no match. [ WARNING ] Consider building the Inference Engine Python API from sources or reinstall OpenVINO (TM) toolkit using "pip install openvino==2021.4" 2022-11-19 01:34:44.207311: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found 2022-11-19 01:34:44.207542: 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. C:\Users\dchoi\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\autograph\impl\api.py:22: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses import imp 2022-11-19 01:34:46.961002: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set 2022-11-19 01:34:46.961949: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found 2022-11-19 01:34:46.962904: W tensorflow/stream_executor/cuda/cuda_driver.cc:326] failed call to cuInit: UNKNOWN ERROR (303) 2022-11-19 01:34:46.969471: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-SCBPOUA 2022-11-19 01:34:46.969727: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-SCBPOUA 2022-11-19 01:34:46.970663: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2022-11-19 01:34:46.971135: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set [ FRAMEWORK ERROR ] Cannot load input model: SavedModel format load failure: NodeDef mentions attr 'validate_shape' not in Op<name=AssignVariableOp; signature=resource:resource, value:dtype -> ; attr=dtype:type; is_stateful=true>; NodeDef: {{node AssignNewValue}}. (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.).
已尝试运行install_prerequirement/install_prerequisites_tf2.bat,但报错依旧,寻求解决方法。
解决方法
版本兼容性修复
OpenVINO 2021.4仅支持TensorFlow 2.5.x及以下版本,你使用的TensorFlow 2.9.2超出兼容范围,导致AssignVariableOp节点属性不匹配。降级TensorFlow重新导出模型
在Colab中切换到TensorFlow 2.5版本,重新加载并导出SavedModel:!pip install tensorflow==2.5.0 import tensorflow as tf model = tf.keras.models.load_model('model.h5') tf.saved_model.save(model, 'tf25_model')将新导出的
tf25_model文件夹下载到本地,重新运行Model Optimizer命令。升级OpenVINO版本
若不想降级TensorFlow,可升级OpenVINO到2022.1及以上版本(该版本开始支持TensorFlow 2.8+),确保工具链版本与TensorFlow匹配。修复版本不匹配警告
先按提示重新安装对应版本的OpenVINO Python API:pip install openvino==2021.4
内容的提问来源于stack exchange,提问作者newbieLife
相关产品推荐
相关产品推荐

