-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to deply my own .Tflite file #20
Comments
I found the solution, it is not working very well, but I will update it in this issue. if you want deploy your own tflite model in the Coral, basically you need to follow these steps:
|
Basically, this is working if you convert your model correctly. But I get weird output now. And one thing that really bothers me is that the type of output in my .tflite file is UINT8, but actually, it is FLOAT32 in .pb file. I am still working on it. According to the official tflite, their output is FLOAT32, so I am checking the converting way, maybe there are some tricks. And you can use tensorflow/lite/tools/visualize.py to check the tensors of your tflite model. It is very convenient. |
I found a good softeware called netron. It is very powerful softeware to visualized your model, and find the name of input and output. It is more efficient than visualized.py. So I recommended netron now. |
Hi caiya have you solved the problem yet? I'm in a similar situation trying to get pose estimation running. |
Yes, as for the UINT8 output problem, it is solved, it seems like the official API will use code to convert your UINT8 output into float32. So finally you will get float32 output. Here is the source code from Coral support team:
But after that, I got a float32 output but it is not correct. Quickly I get the reason. Since the opt.pb provided by the open-pose GitHub project is not a quantization-Aware Training model, so the output from the open-pose model is very different from the correct output because you have to set the converter.default_ranges_stats when you convert the .pb file into the .tflite file. This is because the max-min numbers are required and the correct min-max numbers are missing from the original .pb file. I try different ranges, such as (0,6), (-1,2), or others, but I can't find a good range to make the final result even close to the correct results. If you can find one, please let me know. The recommended way is to train the open-pose estimation model again with quantization-aware training flag =1. As for the segmentation fault, sorry I didn't get that error before. Do Do you use the open-pose model from the here? Which model do you use, and does your model pass the Compile your model for the Edge TPU? Anyway, I'm glad there is someone working on a similar thing, Let's keep sharing information. |
I am also having difficulties to get my own model to run on the Edge TPU. I am using the local ubuntu compiler to compile my .tflite file. However I realized that the compilation does not work if my image input size is too large. The compilation just hangs and gives an internal error without further specifying what error actually occured. (Do you get any further errors during compilation or just a general internal error?) Did you try a bigger input size with your net (e.g. double your currently used image size) and did it still compile? I fell like there is a limit on the maximum number of nodes/calculations that can be done in one layer. If that is too high it feels like it is not compiling without telling me whats actually wrong. Do you maybe know more about that? And what inference times do you get right now with your current image size? Regarding your problem I think you should defenitly retrain your model with quantization aware training since it is really not straight forward to do post-quantization. Good to know I am not the only one having difficulties :) |
Yes, I get the model from ildoonet/tf-pose-estimation. I already get the quantized aware training model based on Mobilenet v2. Training script is available in tf_pose/train.py. You can change the quantization flag. After that, you can run the run_checkpoint.py model to obtain the eval_graph.pb, and freeze it and convert it to tflite. I get unsupported op error when I try to convert the frozen pb file intot tflite file. I am still working on it. If anyone has a similar problem like unsupported op (cast, size or Fusebatchnorm V3) for quantization, please share the information. |
Thank you @caiya55. I'm trying to train the model with quantization aware training but I'm having some issues with the training.py script. Can you please share your quantization aware trained model? Thank you! |
Do you have wechat? |
Check out this thread about quantization-aware training and the new tool for post-training quantization, might be useful for you |
Heyo marcel1991, did you make any progress or could you confirm it was the input size of the model that caused your problems? With what input size were you working? Much thanks for an answer! |
Hi @caiya55 hope you figured out your issues. As for running inference, you can just use one of the open-source demo script and from there modify it to your need: Hope this helps |
I tried to convert mobilenetv2 model into post-training quantized tflite model, and I got the following message:
I can't figure out why only QUANTIZE and DEQUANTIZE operations are not supported for coral dev board. Here is my python API code:
Maybe it doesn't matter. But later when I run it on edgetpu by using label_image.py example code, it shows the following error:
Does anyone have clue which step I took is problematic? thanks. |
@jk78346 what compiler version are you running? |
HI, my edgetpu compiler version is: 2.0.267685300 |
Looks like you're up to date on your compiler. |
Yes, I got the foo.html file and it seems like the same case that only an edgetpu-custom-op in between, no other detail layers displayed. I think my question is: |
@jk78346 bytes type is correct for the model, I'm saving mine in such manor:
does foo.html shows any float32 or any unusual types on the "type" column? |
Yes it has float32, hmm.
And I just use this model:
So I think here I tried to follow this example and still got the same situation. I can't get ride of the float32 operation. |
after some search, I'm not sure if the
actually give quantized input/output type. Because now every intermediate layer seems ok except the input/output layers. |
I've got similar problem as @jk78346 After converting with with flags
using latest nightly,
and
However converter still succeeds with log
But I still get RuntimeError on Edge TPU
|
I have found here that TensorFlow 2.0 supports only float input/output. That is the reason why my simple mnist test model compiles like this: Input: mnist_post_quant_model_io.tflite
Output: mnist_post_quant_model_io_edgetpu.tflite
Operator Count Status
DEQUANTIZE 1 Operation is working on an unsupported data type
SOFTMAX 1 Mapped to Edge TPU
FULLY_CONNECTED 2 Mapped to Edge TPU
QUANTIZE 1 Operation is otherwise supported, but not mapped due to some unspecified limitation The solution is to downgrade to version 1.15. |
For preparing .tflite model, I use tf=1.13.1 as well as tflite_convert from command line; when running tf2.0 is used since I want to use delegate. |
老哥中国人?你用这段代码没问题吗?我有一个 quantization-Aware Training model,转成tflite. float和int映射应该是zero_mean=128,scale=1/128 而且我自己写代码加载tflite做分类是没问题的. 但是不知道为什么,在coral上用编译后的edgetpu.tflite做推理
我加了打印,发现out_tensor->params.zero_point=0,out_tensor->params.scale=1/255 |
@caiya55 Were you successfully able to convert the openpose model for the edgetpu using the edgetpu compiler. I am curretly trying to do it ,but the edgetpu compiler just abort without any debug info. I downloaded the frozen graph from the same source as you (ildoonet/tf-pose-estimation). I also created a new thread regarding the issue. If you have successfully converted, then please let me know what I did wrong. |
@Eashwar93 Thanks for asking. I've been trying to convert openpose on coral last year. I've worked for several months, and finally, I succeeded. But the problem is: openpose is too slow for coral due to its pose processing step. The reason is obvious: coral is good for TPU, but I think its CPU is not powerful. The speed that I test is around1.5s/frame, and the post-process step takes 1.3s. My next step was to convert the post-processing step into C++ and improve the speed. I didn't continue this task, because, at that time, the Google Coral team just release its pose estimation model on coral, which is easy to implement, and its almost real-time (7-9 frame/s). So we just use their model. You can easily find the model from Google Coral official website. If you are still interested in converting the openpose model on coral, my experience is, using the Keras model! I found that the Keras model is easier to pass the TPU compiler, and less error, when I use this command: tf.compat.v1.lite.TFLiteConverter.from_keras_model_file. So, generally, my steps are, download the ckpt files, establish a Keras model, load the ckpt parameters to each layer of Keras model, and then save the model into h5 file. Trust me, compared with quantization-Aware Training the openpose from scratch, this is easier way. Finally, you can covert the .h5 model to .tflite file. If you are interested, you can check my colab file here, using colab file to convert is a good way to avoid the configuration and different-version errors. |
@caiya55 Thanks a lot for your detailed explanation. I tried Google's Posenet but I think the accuracy is not that great for a real world robot to use it. I wanted to evaluate if Openpose is offering the appropraite solution. Thanks for the heads up that the Openpose is slow in EdgeTPU. I think I would be next try to write the pose inference in C++ and probably try to find out if there is a way to postprocess using GPU if that would make it real time. I will try out your convert from keras file colab notebook to see if I'm able to convert if to edgetpu model. Once again thanks a lot. |
Do you have wechat, if you have, prviate message to me, and we can discuss on wechat.
获取 Outlook for Android<https://aka.ms/ghei36>
…________________________________
From: Eashwar <notifications@github.com>
Sent: Thursday, April 23, 2020 4:47:55 PM
To: f0cal/google-coral <google-coral@noreply.github.com>
Cc: ZHANG ZHAOXIANG <zhangzhaoxiang666@outlook.com>; Mention <mention@noreply.github.com>
Subject: Re: [f0cal/google-coral] How to deply my own .Tflite file (#20)
@caiya55<https://github.com/caiya55> Thanks a lot for your detailed explanation. I tried Google's Posenet but I think the accuracy is not that great for a real world robot to use it. I wanted to evaluate if Openpose is offering the appropraite solution. Thanks for the heads up that the Openpose is slow in EdgeTPU. I think I would be next try to write the pose inference in C++ and probably try to find out if there is a way to postprocess using GPU if that would make it real time.
I will try out your convert from keras file colab notebook to see if I'm able to convert if to edgetpu model.
Once again thanks a lot.
―
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#20 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AIBPFZMPZOOBM7X524UXZRLRN76DXANCNFSM4HLF2T5Q>.
|
@caiya55 thanks but unfortunately I don't use we-chat and even if I create one I don't have a friend here to verify my we chat account through the QR code scanning procedure. Thanks for your help. It does mean a lot. |
Hi @caiya55 I would like to know how were you able to convert your .pb model to the .tflie model. I want to do an inference on the Google Coral for Efficientdet. |
You can use the code below that was suitable for my model to convert it to a tflite model.
you need to modify the code according to your model. You will have to change the arguments |
First, which version of the Tensorflow converter did you use for converting the graph to the .tflite model? |
@Eashwar93 thanks for your quick response! |
@Ekta246 Could you share the codes that you used to convert the saved_model file to a quantised .tflite model? |
Yes, why not? import tensorflow as tf
concrete_func = saved_model_obj.signatures[tf.saved_model.DEFAULT_SERVING_SIGNATURE_DEF_KEY]
#concrete_func = model.signatures[tf.saved_model.DEFAULT_SERVING_SIGNATURE_DEF_KEY] converter.optimizations = [tf.lite.Optimize.DEFAULT] converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8] open("converted.tflite", "wb").write(tflite_quant_model)''' |
On using the, |
@Ekta246 I think you are not quantising the input and output layers. I'm not sure if that is supported by the edgetpu compiler yet. In-order to quantise the input and output layers you should probably add
before running
Also have a look at this visualizer netron to see if quantisation has happened. I'm not an expert either but I think quantising your input and output layers should solve your issue. |
Actually, I had already used the
inference_input_type =tf.unit8
inference_output_type=tf.unit8
And yes I have already visualised it in the Netron app, and yes I only see
w dequantize block.
Nothing more which may relate to a quantized model.
Do you mind sharing me your quantized file?
Thanks
…On Thu, May 21, 2020, 3:52 PM Eashwar ***@***.***> wrote:
@Ekta246 <https://github.com/Ekta246> I think you are not quantising the
input and output layers. I'm not sure if that is supported by the edgetpu
compiler yet. In-order to quantise the input and output layers you should
probably add
converter.inference_input_type = tf.uint8
converter.inference_output_type = tf.uint8
before running
tflite_quant_model = converter.convert()
Also have a look at this visualizer netron
<https://lutzroeder.github.io/netron/> to see if quantisation has
happened. I'm not an expert either but I think quantising your input and
output layers should solve your issue.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#20 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMQBWSP3PNMXIIHEXLTPI43RSWBARANCNFSM4HLF2T5Q>
.
|
@Ekta246 Oh ok. I could not find that in the code you shared, hence the suggestion. Sure I can share the quantized model. I am facing issues as well with the quantized model when I pass through the EdgeTPU compiler but its a different one. I would like to ask you to look at these issues if it was the same for you. If you could share your model that would be nice as well for me to have a look |
Now I have my own complied .tflite model, the file is already passed the Compile your model for the Edge TPU, and visualize.py shows that the operators are all become UINT8 type. Now I'd like to know how to deploy the model and make it run in TPU. The python API in the official website provides two engines, one is edgetpu.classification.engine, and another is edgetpu.detection.engine. But my mode is the open-pose (human pose estimation) model, so the output is different.
Is anyone working on the deployment of your own model? I will appreciate that if someone could give me some clues.
The text was updated successfully, but these errors were encountered: