models icon indicating copy to clipboard operation
models copied to clipboard

Unable to import ssd_mobilenet_v1_coco model using latest OpenCV.

Open GuyTraveler opened this issue 9 years ago • 5 comments

I am attempting to perform multiple object detection using the frozen graph protobuf file available under /models/object_detection/g3doc/detection_model_zoo.md (ssd_mobilenet_v1_coco_11_06_2017). I am using the OpenCV example that leverages tensorflow neural networks found here https://github.com/opencv/opencv/blob/master/samples/dnn/tf_inception.cpp (I have modified the code to use the proper input and output names) While trying to run the example it throws an exception when trying to populate the network:

cv::Ptrcv::dnn::Importer importer = cv::dnn::createTensorflowImporter(modelFile); cv::dnn::Net net; importer->populateNet(net);

Exception: ToFloat:Cast(image_tensor) SrcT:[ ] DstT:[ ] OpenCV Error: Unspecified error (Unknown layer type Cast in op ToFloat) in `anon ymous-namespace'::TFImporter::populateNet, file C:\Repos\opencv_contrib\modules
dnn\src\tensorflow\tf_importer.cpp, line 730

I have not had any issue using the frozen model for Inception V1 or other caffe models. The model that I am using is labeled frozen_inference_graph.pb and is 28,502KB. From some of the demonstrations and literature it seems like the non-quantized network should be between 17-23MB so something seems awry.

I would like to compare inference times between networks on single board computers. Please advise on how I can resolve this issue. Thanks.

GuyTraveler avatar Jul 13 '17 04:07 GuyTraveler

@AshwinRajendraprasad I was using the graph they list in the example from https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip and the default input (input) and output (softmax2) names. I tried to test one of the Inception V3 models (inception_v3_2016_08_28_frozen.pb) but I get a separate exception.

OpenCV Error: Unspecified error (More than one input is Const op) in `anonymous- namespace'::TFImporter::getConstBlob, file C:\Repos\opencv_contrib\modules\dnn\s rc\tensorflow\tf_importer.cpp, line 460

GuyTraveler avatar Jul 13 '17 20:07 GuyTraveler

@GuyTraveler The code you're referencing is in the OpenCV repository. You might get better support on StackOverflow or filing an issue with OpenCV. If there's a bug in unmodified tensorflow/models code, let me know and I'll re-open.

jart avatar Jul 13 '17 21:07 jart

Just curious did you find a solution? I am getting the same message, and did not find a solution so far.

Best Regards

ronalnd12 avatar Sep 05 '17 09:09 ronalnd12

Have you found a solution? Please help!

soufianesabiri avatar Mar 14 '19 08:03 soufianesabiri

Off the top of my I head I do not recall how I overcame that issue. I think that the OpenCV repository for TensorFlow support has advanced to support the particular operations that were previously not supported. My particular use case was to avoid having a runtime python dependency. At the moment my current workflow is to train and freeze utilizing python and using TensorFlowSharp to load my graph and perform inferences.

GuyTraveler avatar Mar 14 '19 18:03 GuyTraveler