# Computer Vision (TensorFlow Lite)

&#x20;Main steps

> 1 - Video/Roboflow: Gather images for dataset
>
> 2 - Colab: Train Custom Model
>
> 3 - Export Model
>
> 4 - Set up Pi
>
> 5 - Run on Pi

### 1 - Video/Roboflow: Gather images for dataset

| Logo                                                                                                                                                                                                                                                      | Description                                                                                                                                                                                                                           |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <img src="https://439555438-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FElvkNRN6rYA6sAuRlm5I%2Fuploads%2FwmxT6JmmV3WHUPyvgOUn%2Fimage.png?alt=media&#x26;token=84e3dc49-607b-45f2-a85e-b5b474eedb73" alt="" data-size="original"> | We can film a video of the item we want to detect and then upload to Roboflow. On the Roboflow website, we can extract frames every X seconds to create a .jpg file each interval. Then we can begin labeling each image on Roboflow. |

> Roboflow is a website where you upload images, label them, and export a zip file (images & .xml files).&#x20;
>
> \
> Useful to share dataset and have 3 people label at the same time

### 1.1 - Unlabeled Images to Labeled Images&#x20;

| Unlabled                                                                                                                                                                                                                                                  | Labeled (Desired Outcome)                                                                                                                                                                                                                                 |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <img src="https://439555438-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FElvkNRN6rYA6sAuRlm5I%2Fuploads%2FBGAcFzeGQqSAiOtpQVnE%2Fimage.png?alt=media&#x26;token=791dda0e-298b-4a5f-9b4a-0fc3794513dd" alt="" data-size="original"> | <img src="https://439555438-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FElvkNRN6rYA6sAuRlm5I%2Fuploads%2FLDpIXUBIM1OzRT2tQXh4%2Fimage.png?alt=media&#x26;token=e37422f4-12f0-4e5f-99c0-5afe7cd0bc2f" alt="" data-size="original"> |

{% embed url="<https://www.youtube.com/watch?v=a3SBRtILjPI>" %}

### 2 - Colab: Train Custom Model

{% hint style="info" %}
&#x20;**WARNING**: This Colab began having issues in May 2023.&#x20;
{% endhint %}

<table><thead><tr><th width="365">Logo</th><th>Description</th></tr></thead><tbody><tr><td><img src="https://439555438-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FElvkNRN6rYA6sAuRlm5I%2Fuploads%2FOclF7SI6nijqd1Juthoq%2Fimage.png?alt=media&#x26;token=68f8210d-1f1b-404b-bf61-ffcdec7e78e3" alt="" data-size="original"></td><td><p>-The following website uses Python </p><p>-here we set up libraries </p><p>     - collections of pre-written code that you </p><p>        can use to perform specific tasks</p><p>-Prepare the dataset</p><p>-Train the model</p><p>-Evaluate the model performance with validation data</p><p>-Export the model as .tflite file </p></td></tr></tbody></table>

Open up this pre-made online coding website called [Google Colab](https://colab.research.google.com/github/khanhlvg/tflite_raspberry_pi/blob/main/object_detection/Train_custom_model_tutorial.ipynb)

### 3 - Export Model

We can export the custom model after training as a .tflite file which will be uploaded to the Raspberry Pi and then can be used for Object Detection. [Demo here](https://youtu.be/-ZyFYniGUsw?t=627)

### 4 - Set up Pi

| Original Tensorflow Video - 2 yrs ago                                                            | November 2023 - Recent Video                                |
| ------------------------------------------------------------------------------------------------ | ----------------------------------------------------------- |
| [YouTube Link](https://youtube.com/watch?v=mNjXEybFn98\&list=PLQY2H8rRoyvz_anznBg6y3VhuSMcpN9oe) | [YouTube Link](https://www.youtube.com/watch?v=ldvlAMcGWIk) |
| 0cyyUyl9smt2-hWdK8ivKExIY                                                                        | 0cyyUyl9smt2-5gal0Pt2blrl                                   |

***

### Installation

| Original Tensorflow Video - 2 yrs ago                                                                                                                     | November 2023 - Recent Video                                                                                                                     |
| --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| [YouTube Link](https://youtube.com/watch?v=mNjXEybFn98\&list=PLQY2H8rRoyvz_anznBg6y3VhuSMcpN9oe)                                                          | [YouTube Link](https://www.youtube.com/watch?v=ldvlAMcGWIk)                                                                                      |
| <p>NOTE: (2:54)</p><p>-click top left</p><p>-preferences</p><p>-raspberry pi configuration</p><p>-tabs: interfaces</p><p>-enable camera</p><p>-reboot</p> | <p>NOTE: <br>-click top left</p><p>-preferences</p><p>-raspberry pi configuration</p><p>-tabs: interfaces</p><p>-enable camera</p><p>-reboot</p> |
| uaYq12tCsfz3-hWdK8ivKExIY                                                                                                                                 | uaYq12tCsfz3-5gal0Pt2blrl                                                                                                                        |

### 5 - Run on Pi

| Original Tensorflow Video - 2 yrs ago                      |
| ---------------------------------------------------------- |
| source tflite/bin/activate                                 |
| cd examples/lite/examples/object\_detection/raspberry\_pi/ |
| cp \~/Downloads/android.tflite .                           |
| python detect.py                                           |
| python detect.py --model android.tflite                    |

### Sources

\[1] [Tensorflow Video](https://youtu.be/-ZyFYniGUsw)[b](https://colab.research.google.com/drive/1wRkzzI_MYYkbFGcRtP60NbSDyYgrJiyw?usp=sharing) (The Colab they have doesn't work with newer Python versions)
