# Deploying YOLOv8 with a custom backbone in Flask without module import errors

**URL:** <https://community.ultralytics.com/t/deploying-yolov8-with-a-custom-backbone-in-flask-without-module-import-errors/1599>\
**Category:** Support\
**Tags:** question, yolov8-world, bug-fix\
**Created:** [October 31, 2025, 11:28am UTC](https://community.ultralytics.com/t/deploying-yolov8-with-a-custom-backbone-in-flask-without-module-import-errors/1599 "2025-10-31T11:28:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rdEliza](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/rdeliza/32/1104_2.png) [@rdEliza](https://community.ultralytics.com/u/rdEliza)\
**Post date:** [October 31, 2025, 11:28am UTC](https://community.ultralytics.com/t/deploying-yolov8-with-a-custom-backbone-in-flask-without-module-import-errors/1599/1 "2025-10-31T11:28:04Z")

</div>

I have trained a YOLOv8 model but modified its backbone by adding a custom component (`APConv`). I want to deploy this model using Flask so it can receive images and return object counts. When I try to load the model with `YOLO('best.pt')` in Flask, I encounter module import errors for the custom layers, even though I have added the `.py` file for `APConv`.

My Flask code includes routes for uploading images and running inference, but the model fails to load due to missing custom modules. I need guidance on the best way to load or package the model for deployment so that my custom layers are recognized and inference works without errors.

---

<div class="post-metadata">

**Author:** ![BurhanQ](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/burhanq/32/7_2.png) [@BurhanQ](https://community.ultralytics.com/u/BurhanQ)\
**Post date:** [October 31, 2025, 11:30am UTC](https://community.ultralytics.com/t/deploying-yolov8-with-a-custom-backbone-in-flask-without-module-import-errors/1599/2 "2025-10-31T11:30:52Z")

</div>

You will have to fully clone the modified Ultralytics repository code where you made the modifications to the layers. If you try to run using the standard library installed from PyPi, it won’t work. If you haven’t yet, it would likely make sense to containerize your application and during that process you can copy the Ultralytics repo code you modified, then install the package using the local directory instead of the PyPi package.

---

<div class="post-metadata">

**Author:** ![rdEliza](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/rdeliza/32/1104_2.png) [@rdEliza](https://community.ultralytics.com/u/rdEliza)\
**Post date:** [November 2, 2025, 5:52am UTC](https://community.ultralytics.com/t/deploying-yolov8-with-a-custom-backbone-in-flask-without-module-import-errors/1599/3 "2025-11-02T05:52:53Z")

</div>

Thanks @BurhanQ for your response , it works now 😀 .  
Also, I was wondering what to do so I can see mAP@30 for my model in addition to mAP50 and mAP50-95?

I added this to metrics.py  
trial#1  
`def map30(self) -> float:`  
` return self.all_ap[:, 3].mean() and later tried`

trial#2  
`def map30(self) -> float:`  
` return self.all_ap[:, 0].mean() along with`

`val_metrics = model.val(`  
` data="data.yaml", iou=0.3)`  
but the value of mAP@30 does not make sense. It is either less than or equal to mAP@50.

---

<div class="post-metadata">

**Author:** ![Toxite](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/toxite/32/123_2.png) [@Toxite](https://community.ultralytics.com/u/Toxite)\
**Post date:** [November 2, 2025, 2:45pm UTC](https://community.ultralytics.com/t/deploying-yolov8-with-a-custom-backbone-in-flask-without-module-import-errors/1599/4 "2025-11-02T14:45:45Z")

</div>

It’s not calculated.

You can check this’

> <https://github.com/ultralytics/ultralytics/issues/17815#issuecomment-2501887818>
>
> \### Search before asking
> 
> \- \[X\] I have searched the Ultralytics YOLO \[issues\](ht…tps://github.com/ultralytics/ultralytics/issues) and \[discussions\](https://github.com/ultralytics/ultralytics/discussions) and found no similar questions.
> 
> 
> \### Question
> 
> The current validation outputs mAP50, 70 and 50:95, how can I compute mAP25 or mAP at any other IoU?
> 
> \### Additional
> 
> \_No response\_

---

<div class="post-metadata">

**Author:** ![rdEliza](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/rdeliza/32/1104_2.png) [@rdEliza](https://community.ultralytics.com/u/rdEliza)\
**Post date:** [November 2, 2025, 10:10pm UTC](https://community.ultralytics.com/t/deploying-yolov8-with-a-custom-backbone-in-flask-without-module-import-errors/1599/5 "2025-11-02T22:10:50Z")

</div>

Thank you @Toxite

---

<div class="post-metadata">

**Author:** ![pderrenger](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/pderrenger/32/73_2.png) [@pderrenger](https://community.ultralytics.com/u/pderrenger)\
**Post date:** [November 3, 2025, 1:29pm UTC](https://community.ultralytics.com/t/deploying-yolov8-with-a-custom-backbone-in-flask-without-module-import-errors/1599/6 "2025-11-03T13:29:26Z")

</div>

Glad it’s working!

On AP@0.30: Ultralytics YOLO only reports AP at 0.50 and 0.50:0.95 by default. The `iou` argument in `model.val(iou=0.3)` controls NMS IoU, not the evaluation IoU. To get AP@0.30 you can either:

- Modify the evaluator to include 0.30 in the IoU thresholds and re-run `val` (edit the IoU list in `ultralytics/utils/metrics.py`), then read it from `results.box.all_ap`.
- Or export predictions and use COCOeval with a custom IoU, for COCO-format datasets:

```python
# After: model.val(data="coco.yaml", save_json=True)
from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval
import numpy as np
gt = COCO("instances_val2017.json")
dt = gt.loadRes("predictions.json")
e = COCOeval(gt, dt, "bbox"); e.params.iouThrs = np.array([0.30])
e.evaluate(); e.accumulate(); e.summarize()

```

For what is computed out of the box, see the metrics properties in the docs, for example the explanations of `map`, `map50`, and `map75` in the [metrics reference](https://docs.ultralytics.com/reference/utils/metrics/).
