tensorflow / models

Models and examples built with TensorFlow
Other
76.94k stars 45.8k forks source link

Unable to import ssd_mobilenet_v1_coco model using latest OpenCV. #1939

Closed GuyTraveler closed 7 years ago

GuyTraveler commented 7 years ago

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::Ptr 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 commented 7 years ago

@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

jart commented 7 years ago

@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.

ronalnd12 commented 7 years ago

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

Best Regards

soufianesabiri commented 5 years ago

Have you found a solution? Please help!

GuyTraveler commented 5 years ago

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.