我已使用 Google Vision API 导出了一个模型。这会从 Edge 导出中生成 TF Lite 模型或 pb 模型(SavedModel 格式)。这些似乎都不能导入 OpenCV。我不确定这里出了什么问题。我需要转换格式吗?
我基于这个 GoCV 源 here .
并像这样调用它:
./main 0 ./saved_model.pb ./test.txt opencv cpu
导致此错误:
[libprotobuf ERROR /tmp/opencv-20190908-41416-17rm3ol/opencv-4.1.1/3rdparty/protobuf/src/google/protobuf/wire_format_lite.cc:629] String field 'opencv_tensorflow.FunctionDef.Node.ret' contains invalid UTF-8 data when parsing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes.
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(4.1.1) /tmp/opencv-20190908-41416-17rm3ol/opencv-4.1.1/modules/dnn/src/tensorflow/tf_io.cpp:42: error: (-2:Unspecified error) FAILED: ReadProtoFromBinaryFile(param_file, param). Failed to parse GraphDef file: ./saved_model.pb in function 'ReadTFNetParamsFromBinaryFileOrDie'
SIGABRT: abort
PC=0x7fff7e2f22c6 m=0 sigcode=0
signal arrived during cgo execution
最佳答案
Vision API 使用 TensorFlow 模型,可以使用 readNetFromTensorflow() 将其加载到 OpenCV 中函数,包含在 dnn module 中。此函数加载 SavedModel 格式的模型(.pb 文件扩展名)。
但是,这可能不会直接适用于您链接到的代码,因为它期望 HAAR or Cascade Classifier 。这些分类器与 TensorFlow 模型非常不同,如果您想测试 TensorFlow 模型,则需要对代码进行额外的更改。
关于opencv - 如何将 Cloud Vision API 导出模型与 Open CV 程序结合使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58212114/