我使用Tensorflow 2 Object Detection API训练了SSD ResNet V1模型,然后想在C++代码中使用OpenCV这个模型。首先,在训练后我有三个文件:
- checkpoint - ckpt-101.data-00000-of-00001 - ckpt-101.index
请注意,我没有.meta文件,因为它没有生成。接着,我使用Object Detection API中的exporter_main_v2.py脚本从这些文件中创建了SavedModel。
- checkpoint - ckpt-101.data-00000-of-00001 - ckpt-101.index
请注意,我没有.meta文件,因为它没有生成。接着,我使用Object Detection API中的exporter_main_v2.py脚本从这些文件中创建了SavedModel。
python3 exporter_main_v2.py input_type=image_tensor --pipeline_config_path /path/to/pipeline.config --trained_checkpoint_dir=/path/to/checkouts --output_directory=/path/to/output/directory
运行此脚本后,我得到了saved_model.pb文件。
我尝试在OpenCV中使用此文件的方式如下:
cv::dnn::Net net = cv::dnn::readNetFromTensorflow("/path/to/saved_model.pb");
但我收到了以下错误:
OpenCV(4.2.0) /home/andrew/opencv/modules/dnn/src/tensorflow/tf_io.cpp:42: error: (-2:Unspecified error) FAILED: ReadProtoFromBinaryFile(param_file, param). Failed to parse GraphDef file: /home/andrew/Documents/tensorflow_detection/workspace/pb_model/saved_model/saved_model.pb in function 'ReadTFNetParamsFromBinaryFileOrDie'
我尝试冻结saved_model.pb,但是据我所知,在TF2.x中这是不可能的,因为TF2.x不支持Sessions和Graphs。此外,我没有.pbtxt文件。
我的问题是:是否可以在OpenCV C++中使用使用TF2目标检测API训练的模型?
如果您能帮助我解决这些问题或提供任何有用的建议,我将非常感激。
ValueError: Input 1 of node StatefulPartitionedCall was passed float from 53831:0 incompatible with expected resource.
你知道如何解决吗?另外,正如我在问题中提到的,我想使用OpenCV C++,而不是Python。 - Андрей Диденко