# YOLOV5 Models on Android

**URL:** <https://discuss.ai.google.dev/t/yolov5-models-on-android/31590>\
**Category:** General Discussion\
**Tags:** android, tflite, help\_request\
**Created:** [October 27, 2023, 6:49am UTC](https://discuss.ai.google.dev/t/yolov5-models-on-android/31590 "2023-10-27T06:49:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laura1](https://avatars.discourse-cdn.com/v4/letter/l/47e85d/32.png) [@Laura1](https://discuss.ai.google.dev/u/Laura1)\
**Post date:** [October 27, 2023, 6:49am UTC](https://discuss.ai.google.dev/t/yolov5-models-on-android/31590/1 "2023-10-27T06:49:42Z")

</div>

Hello everyone,  
I used two yolov5 models.  
My first model detects the tray. In my second model, it finds food types.

The size of the first model was 416, then I cropped it. I sent it to  
the second model. The size of my second model is 224.

my question: There is a shift in the second model in the example\_output.jpg  
image. Second model failed to draw bounding boxes properly.I would love any advice.

Thank you very much.

 ![example_output](https://d3qe71uytubmmx.cloudfront.net/original/2X/3/372cd34078f3de72c96ef57a34fcbf60a33136cd.jpeg)

---

<div class="post-metadata">

**Author:** ![LK\_Kadali](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/lk_kadali/32/13996_2.png) [@LK\_Kadali](https://discuss.ai.google.dev/u/LK_Kadali)\
**Post date:** [February 13, 2024, 7:09am UTC](https://discuss.ai.google.dev/t/yolov5-models-on-android/31590/3 "2024-02-13T07:09:18Z")

</div>

Hi @Laura1 ,

First adjust the horizontal and vertical scaling factors and then offset the X , Y coordinates based on the center coordinates of the original image. Here is the sample code to adjust the coordinates. Please change according to your data structure.

```auto
        # Apply scaling factors
        if not normalized:
            left *= scaling_factors[0]
            top *= scaling_factors[1]
            right *= scaling_factors[0]
            bottom *= scaling_factors[1]

        # Offset both X, Y coordinates by tray center
        left += tray_center[0]
        top += tray_center[1]
        right += tray_center[0]
        bottom += tray_center[1]

```

Thank You

---

<div class="post-metadata">

**Author:** ![Laura1](https://avatars.discourse-cdn.com/v4/letter/l/47e85d/32.png) [@Laura1](https://discuss.ai.google.dev/u/Laura1)\
**Post date:** [February 13, 2024, 7:37am UTC](https://discuss.ai.google.dev/t/yolov5-models-on-android/31590/5 "2024-02-13T07:37:26Z")

</div>

Hello @LK_Kadali ,

Thank you very much for reply. I will try.
