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
Is it possible to preload a model into the Coral Edge TPU and keep it there for some time? #522
Comments
Yes, It is possible to load a model into the Edge TPU. The script you are using also loading model into interpreter for only once when passing image directory as input. Can you please share the detect.tflite model you are using. Thanks! |
But I never execute the script for a group of images. Only for a single image. The most recent one. The workflow is: I create an image with the camera and execute the script for object detection for exactly this new image. And I do this this in an infinte loop. The question is: Can I load the model into the Edge TPU memory and keep it there for some time? And can I do object detection for a single image file without loading the model prior into the Edge TPU memory by telling to use the already uploaded one? |
Okay, I think, It is not possible to preload a model into the Coral Edge TPU and keep it there for some time. We can pass images in image directory or stream of images to avoid loading it for every image. Feel free to check the streaming examples from this repo: https://github.com/google-coral/examples-camera. Thanks! |
But this way (if I collect a number of images and do the object detection when I have a number X of images available), it is no longer "real time". I still hope there is another solution that includes working with single images but still performs well. If in the end object recognition is not possible without the prior upload of a model, then it is likely that the Coral TPU cannot be used to work efficiently with individual images (one image per process). BTW: The model I use is here now. |
The total script execution is more for single image when running edgeptu model is because of the time taken to make edgeptu interpreter line vs cpu tflite interpeter. You can check the inference time difference by calculating time taken for this line. ref: https://github.com/google-coral/pycoral/blob/master/examples/classify_image.py#L110 |
@christianbaun From what I can gather you have some other process which is saving images into a folder and then you trigger your python script to run inference on the images in that folder? Instead of creating a new edgetpu interpreter every time, you need to have a long running script that creates the interpreter, loads the model then loops indefinitely processing images as they become available. |
@cdrose This is a very good idea. Probably the approach that requires the least change to my existing software. I will try this way. |
@hjonnala As you suggested, I did some timing tests to find out where most time is lost, and responsible is not the line where the
This operation (here) costs approx. 2.75 seconds on a Raspberry Pi 4:
This finding does not change anything (I still need to rewrite my code), but it is worth knowing. |
Feel free to reopen if you have any questions. Thanks! |
For a software project, I want to do object detection with many individual images over some time (hours/days).
When using the Coral Edge TPU Accelerator (USB) on a RasPi 4 (4 GB) with the Raspberry Pi OS (I tested versions with Debian 10 or Debian 11), the performance for analyzing single images by just using the CPU is faster compared with using the Coral TPU.
Here, some measurements of this code
Without the Coral USB Accelerator:
With the Coral USB Accelerator:
I also tried a loop over 170 images and the result was a real time less than 2 minutes without the Coral Edge TPU Accelerator (USB) compared with more than 10 minutes when using the Coral TPU.
The reason is probably as mentioned here and on other places like here: the first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory. Thus when using the Coral USB Accelerator to several image files, the model is loaded into the TPU memory for every image file. This overhead does occur just a single time when a video file or stream is processed.
If this is the root cause for the bad performance, I see only two possible solutions:
If these assumptions are correct, is using the Coral TPU useful at all for analyzing single images?
Is it possible to speed up the process of loading the model into Edge TPU memory?
Can I load a model into the Edge TPU memory and keep it there for some time?
Thanks for any help.
The text was updated successfully, but these errors were encountered: