I have trained new model on top of ssd_mobilenet_v1_coco for a custom data set. This model works fine in tensorflow. But now I want to use this in OpenCV.
net = cv2.dnn.readNetFromTensorflow("model/frozen_inference_graph.pb", "model/protobuf.pbtxt")
detections = net.forward()
So for the config file I convert frozen_graph to pbtxt and add it. But then I got the following error
[libprotobuf ERROR /home/chamath/Projects/opencv/opencv/3rdparty/protobuf/src/google/protobuf/text_format.cc:298] Error parsing text-format tensorflow.GraphDef: 731:5: Unknown enumeration value of "DT_RESOURCE" for field "type".
As suggested here I try to use this config file mentioned in the thread but when I use it object detection is not working properly. Incorrect number of squares detected and they are misplaced.
Is there any method to create a pbtxt config file that works with OpenCV? Or any suggestions how to make my model work in OpenCV?
Is likely that you havent generate the propper graph, after training.
You have to convert the graph like this:
python ../opencv/samples/dnn/tf_text_graph_ssd.py --input
trained-inference-graphs/inference_graph_v5.pb/frozen_inference_graph.pb
--output trained-inference-graphs/inference_graph_v5.pb/graph.pbtxt
Then pass the .pb and the graph.pbtxt to DNN.readNetFromTensorflow that should work for you :)
Related
I am trying to train a custom object detector using tflite model maker (https://www.tensorflow.org/lite/tutorials/model_maker_object_detection). I want to deploy trained tflite model to coral edgeTPU. I want to use tensorflow tfrecord (multiple) as input for training a model like object detection API. I tried with
tflite_model_maker.object_detector.DataLoader(
tfrecord_file_patten, size, label_map, annotations_json_file=None
) but I am not able to work around it. I have following questions.
Is it possible to tfrecord for training like mentioned above?
Is it also possible to pass multiple CSV files for training?
For multiple CSV files, you could probably just append one file to the other. Then you'd just have to pass one csv file.
As for passing a tfrecord instead, this should be possible. I'm also attempting to do this, so if I get it working I'll update my post. Looking at the source, it seems from_cache is the function internally used. Following that structure, should be able to create a DataLoader object similarly:
train_data = DataLoader(tfrecord_file_patten, meta_data['size'],
meta_data['label_map'], ann_json_file)
In this case, tfrecord_file_patten should be a tfrecord of your training data. You can construct the validation and test data the same way. This will work provided you're constructing your TFRecords correctly. There appears to be some inconsistency to how it's done in different places, so make sure you follow the same structure in creating the TFRecords as found in the ModelMaker source. This worked for me. One specific thing to watch out for is to use an integer for the 'image/source_id' feature in your TFExamples. If you use a string it'll throw an error.
I recently trained my own custom object detector model using mobilenetssd as my pretrained model. I have been following this tutorial to train my model, and used exporter_main_v2.py program in TensorFlow/models/research/object_detection/ to generate my save_model.pb file. I would like to use OpenCV DNN module where it requires a frozen model and the pbtext. In order to generate the pbtext file, I would need to convert it from the frozen_graph.pb. I would like to convert my save_model.pb to a frozen_graph.pb file, but it looks like freezing graphs has been deprecated in tensorflow 2.X. I tried this solution but I get this error:
AttributeError: '_UserObject' object has no attribute 'inputs'
Does anyone have recommendations or solutions on how I can covert my save_model.pb to a freeze_graph.pb? I would really appreciate the help!
Screenshot of the errorI have trained my own YOLO model with Darkflow and got the .pb file and the .meta file for license plate recognition. What i am trying now is to implement an android App that can use this model. To do so i have decided to convert it into tflite but always get this error about "tags=". I've checked the tags of my model with 'saved_model_cli show --dir=./' and i've got no tags. What should i do to fix this error ?
Tensorflow recently seems to have released pretrained model for instance segmentation using MaskRCNN as per below tweet.
https://twitter.com/TensorFlow/status/963472849511092225
I downloaded mask_rcnn_resnet101_atrous_coco_2018_01_28.tar.gz from this and was trying to figure out how to use it.I found frozen model (pb) file and loaded the graph in Tensorboard.
But I cant figure out what should be the input for the model.I couldn't find a node where simply I can input an image , though I was able to locate nodes where we get classes,masks,bounding boxes etc.
Also there seems to be no details online on how to use it (May be because it is new)
If you follow this tensorflow tutorial it will show you how to run the frozen model on a single/group of images. To apply this to the model you downloaded, the simplest way would be to first replace the line:
PATH_TO_CKPT = MODEL_NAME + '/frozen_inference_graph.pb'
with a path to your downloaded model i.e.
PATH_TO_CKPT = '/absolute/path/to/frozen_inference_graph.pb'
Then there is no need to run the code under the section Download Model. The rest should work the same.
This is probably a very basic question...
But how do I convert checkpoint files into a single .pb file.
My goal is to serve the model using probably C++
These are the files that I'm trying to convert.
As a side note I'm using tflearn with tensorflow.
Edit 1:
I found an article that explains how to do this: https://blog.metaflow.fr/tensorflow-how-to-freeze-a-model-and-serve-it-with-a-python-api-d4f3596b3adc
The problem is that I'm stuck with the following error
KeyError: "The name 'Adam' refers to an Operation not in the graph."
How do I fix this?
Edit 2:
Maybe this will shed some light on the problem.
The error that I get comes from the regression layer, if I use: sgd.
I'll get
KeyError: "The name 'SGD' refers to an Operation not in the graph."
The tutorial on https://blog.metaflow.fr/tensorflow-how-to-freeze-a-model-and-serve-it-with-a-python-api-d4f3596b3adc works just fine.
The problem was that I was loading the model using tensorflow instead of using tflearn.
So... instead of:
tf.train.import_meta_graph(...)
We do:
model.load(...)
TFLearn knows how to parse the graph properly.