# CUSTOM YOLOv7-tiny model on AMB82 MINI: succesfully implemented but not working properly

**URL:** <https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162>\
**Category:** AI\
**Tags:** rtl8735b, evb-amb82\
**Created:** [July 22, 2024, 9:10pm UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162 "2024-07-22T21:10:16Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alberto\_Rino](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/alberto_rino/32/2199_2.png) [@Alberto\_Rino](https://forum.amebaiot.com/u/Alberto_Rino)\
**Post date:** [July 22, 2024, 9:10pm UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/1 "2024-07-22T21:10:16Z")

</div>

-I’ve been able to install my own custom YOLOv7-tiny model on the AMB82 mini without any problems at all, following all the instructions from the video example. However, the model seems to detect random objects where there is nothing to detect, up to the point that the model, which is trained to detect face features, is printing a lot of random boxes even when there are no faces in front of the camera.

-I’ve modified the class “ObjectClassList.h” to fit my model detections.

-Something I haven’t done is the reparameterization. I don’t know if that strictly necessary, it is mentioned in the video but not done, I have no idea if this is problem.

This options I selected in the conversion page: YOLOv7-TINY-Pytorch, UINT8, width: 640, height: 480.

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![Kelvin\_Huang](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/kelvin_huang/32/2130_2.png) [@Kelvin\_Huang](https://forum.amebaiot.com/u/Kelvin_Huang)\
**Post date:** [July 23, 2024, 1:15am UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/2 "2024-07-23T01:15:25Z")

</div>

Hi @Alberto_Rino,

Can you retrain with reparameterization step done and try again?

Thank you.

---

<div class="post-metadata">

**Author:** ![allen31880139](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/allen31880139/32/2200_2.png) [@allen31880139](https://forum.amebaiot.com/u/allen31880139)\
**Post date:** [July 23, 2024, 9:10am UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/3 "2024-07-23T09:10:09Z")

</div>

I also encountered the same problem.

---

<div class="post-metadata">

**Author:** ![Alberto\_Rino](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/alberto_rino/32/2199_2.png) [@Alberto\_Rino](https://forum.amebaiot.com/u/Alberto_Rino)\
**Post date:** [July 23, 2024, 3:51pm UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/4 "2024-07-23T15:51:56Z")

</div>

Yeah, it’s the reparameterization. I’ve tried it, and it works now without any problems at all.

Thanks.

---

<div class="post-metadata">

**Author:** ![allen31880139](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/allen31880139/32/2200_2.png) [@allen31880139](https://forum.amebaiot.com/u/allen31880139)\
**Post date:** [July 24, 2024, 3:47pm UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/5 "2024-07-24T15:47:28Z")

</div>

@Alberto_Rino may I ask what model you use for reparameterization?  
Can you provide me the relevant code?

---

<div class="post-metadata">

**Author:** ![Ameer\_Hamza](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/ameer_hamza/32/2178_2.png) [@Ameer\_Hamza](https://forum.amebaiot.com/u/Ameer_Hamza)\
**Post date:** [July 26, 2024, 5:05am UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/6 "2024-07-26T05:05:01Z")

</div>

Hello @Alberto_Rino  
I’ve modified the class “ObjectClassList.h” to fit my model detections.  
I haven’t done the reparameterization; [swig](https://swigmenu.us/) I don’t know if it’s strictly necessary.  
Options selected in the conversion page: YOLOv7-TINY-Pytorch, UINT8, width: 640, height: 480.

---

<div class="post-metadata">

**Author:** ![Alberto\_Rino](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/alberto_rino/32/2199_2.png) [@Alberto\_Rino](https://forum.amebaiot.com/u/Alberto_Rino)\
**Post date:** [July 26, 2024, 11:27am UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/7 "2024-07-26T11:27:06Z")

</div>

@allen31880139 the two necessary files are provided by realtek in the AmebaPro2 libraries, you can see them if you go to the following path in your computer:

AppData\Local\Arduino15\packages\realtek\hardware\AmebaPro2\4.0.7\libraries\NeuralNetwork\src\

Here they are:

[Yolov7\_reparam\_scripts.zip|attachment]  
(upload://u4b9MkhHoOOLX2f3q5xby6TWA8q.zip) (2,0 KB)

---

<div class="post-metadata">

**Author:** ![Alberto\_Rino](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/alberto_rino/32/2199_2.png) [@Alberto\_Rino](https://forum.amebaiot.com/u/Alberto_Rino)\
**Post date:** [July 26, 2024, 11:39am UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/8 "2024-07-26T11:39:41Z")

</div>

######reparam\_yolov7-tiny######

#This script is written by Zhang Chang Ren from Realtek.

# import

from copy import deepcopy  
from models.yolo import Model  
import torch  
from utils.torch\_utils import select\_device, is\_parallel  
import yaml

device = select\_device(‘0’, batch\_size=1)

# model trained by cfg/training/\*.yaml

ckpt = torch.load(‘path to your custom trained yolov7-tiny.pt model: …/…/yolov7-tiny.pt’, map\_location=device)

# reparameterized model in cfg/deploy/\*.yaml

model = Model(‘path to the file yolov7-tiny-deploy.yaml’, ch=3, nc=8).to(device)

with open(‘path to the yaml file provided by realtek: …/…/yolov7-tiny-deploy.yaml’) as f:  
yml = yaml.load(f, Loader=yaml.SafeLoader)  
anchors = len(yml[‘anchors’][0]) // 2

# copy intersect weights

state\_dict = ckpt[‘model’].float().state\_dict()  
exclude =   
intersect\_state\_dict = {k: v for k, v in state\_dict.items() if k in model.state\_dict() and not any(x in k for x in exclude) and v.shape == model.state\_dict()[k].shape}  
model.load\_state\_dict(intersect\_state\_dict, strict=False)  
model.names = ckpt[‘model’].names  
model.nc = ckpt[‘model’].nc

# reparametrized YOLOR

for i in range((model.nc+5)\*anchors):  
model.state\_dict()[‘model.77.m.0.weight’].data[i, :, :, :] \*= state\_dict[‘model.77.im.0.implicit’].data[:, i, : :].squeeze()  
model.state\_dict()[‘model.77.m.1.weight’].data[i, :, :, :] \*= state\_dict[‘model.77.im.1.implicit’].data[:, i, : :].squeeze()  
model.state\_dict()[‘model.77.m.2.weight’].data[i, :, :, :] \*= state\_dict[‘model.77.im.2.implicit’].data[:, i, : :].squeeze()  
model.state\_dict()[‘model.77.m.0.bias’].data += state\_dict[‘model.77.m.0.weight’].mul(state\_dict[‘model.77.ia.0.implicit’]).sum(1).squeeze()  
model.state\_dict()[‘model.77.m.1.bias’].data += state\_dict[‘model.77.m.1.weight’].mul(state\_dict[‘model.77.ia.1.implicit’]).sum(1).squeeze()  
model.state\_dict()[‘model.77.m.2.bias’].data += state\_dict[‘model.77.m.2.weight’].mul(state\_dict[‘model.77.ia.2.implicit’]).sum(1).squeeze()  
model.state\_dict()[‘model.77.m.0.bias’].data \*= state\_dict[‘model.77.im.0.implicit’].data.squeeze()  
model.state\_dict()[‘model.77.m.1.bias’].data \*= state\_dict[‘model.77.im.1.implicit’].data.squeeze()  
model.state\_dict()[‘model.77.m.2.bias’].data \*= state\_dict[‘model.77.im.2.implicit’].data.squeeze()

# model to be saved

ckpt = {‘model’: deepcopy(model.module if is\_parallel(model) else model).half(),  
‘optimizer’: None,  
‘training\_results’: None,  
‘epoch’: -1}

# save reparameterized model

torch.save(ckpt,‘path to deploy your reparameterized .pt model: …/…/yolov7-tiny\_reparameterized.pt’)

#####yolov7-tiny-deploy.yaml#####

#This script is provided by Zhang Chang Ren from Realtek.

# Running of script:

# python reparam\_yolov7-tiny.py --weights weights/best.pt --custom\_yaml custom/yolov7-tiny-deploy.yaml --output best\_reparam.pt

# Note that for yolov7-tiny-deploy.yaml, last line of yaml need to be changed to Detect.

# It has already been changed in this repository.

# parameters

nc: 2 # number of classes  
depth\_multiple: 1.0 # model depth multiple  
width\_multiple: 1.0 # layer channel multiple

# anchors

anchors:

- [10,13, 16,30, 33,23] # P3/8
- [30,61, 62,45, 59,119] # P4/16
- [116,90, 156,198, 373,326] # P5/32

# yolov7-tiny backbone

backbone:

# [from, number, module, args] c2, k=1, s=1, p=None, g=1, act=True

[[-1, 1, Conv, [32, 3, 2, None, 1, nn.LeakyReLU(0.1)]], # 0-P1/2

[-1, 1, Conv, [64, 3, 2, None, 1, nn.LeakyReLU(0.1)]], # 1-P2/4

[-1, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-2, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[[-1, -2, -3, -4], 1, Concat, [1]],  
[-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 7

[-1, 1, MP,], # 8-P3/8  
[-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[[-1, -2, -3, -4], 1, Concat, [1]],  
[-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 14

[-1, 1, MP,], # 15-P4/16  
[-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-2, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[[-1, -2, -3, -4], 1, Concat, [1]],  
[-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 21

[-1, 1, MP,], # 22-P5/32  
[-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-2, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[[-1, -2, -3, -4], 1, Concat, [1]],  
[-1, 1, Conv, [512, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 28  
]

# yolov7-tiny head

head:  
[[-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-2, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, SP, [5]],  
[-2, 1, SP, [9]],  
[-3, 1, SP, [13]],  
[[-1, -2, -3, -4], 1, Concat, [1]],  
[-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[[-1, -7], 1, Concat, [1]],  
[-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 37

[-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, nn.Upsample, [None, 2, ‘nearest’]],  
[21, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # route backbone P4  
[[-1, -2], 1, Concat, [1]],

[-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[[-1, -2, -3, -4], 1, Concat, [1]],  
[-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 47

[-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, nn.Upsample, [None, 2, ‘nearest’]],  
[14, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # route backbone P3  
[[-1, -2], 1, Concat, [1]],

[-1, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-2, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[[-1, -2, -3, -4], 1, Concat, [1]],  
[-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 57

[-1, 1, Conv, [128, 3, 2, None, 1, nn.LeakyReLU(0.1)]],  
[[-1, 47], 1, Concat, [1]],

[-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[[-1, -2, -3, -4], 1, Concat, [1]],  
[-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 65

[-1, 1, Conv, [256, 3, 2, None, 1, nn.LeakyReLU(0.1)]],  
[[-1, 37], 1, Concat, [1]],

[-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-2, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[[-1, -2, -3, -4], 1, Concat, [1]],  
[-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 73

[57, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[65, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]],  
[73, 1, Conv, [512, 3, 1, None, 1, nn.LeakyReLU(0.1)]],

[[74,75,76], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)  
]

---

<div class="post-metadata">

**Author:** ![allen31880139](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/allen31880139/32/2200_2.png) [@allen31880139](https://forum.amebaiot.com/u/allen31880139)\
**Post date:** [July 29, 2024, 8:39am UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/9 "2024-07-29T08:39:08Z")

</div>

What SDK version you use? i’m using the “4.0.6-bulid20240202” than i cant find the reparam\_yolov7-tiny.py

---

<div class="post-metadata">

**Author:** ![Alberto\_Rino](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/alberto_rino/32/2199_2.png) [@Alberto\_Rino](https://forum.amebaiot.com/u/Alberto_Rino)\
**Post date:** [July 29, 2024, 7:39pm UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/10 "2024-07-29T19:39:07Z")

</div>

# reparam\_yolov7-tiny.py

```auto
#This script is written by Zhang Chang Ren from Realtek.

# import
from copy import deepcopy
from models.yolo import Model
import torch
from utils.torch_utils import select_device, is_parallel
import yaml

device = select_device('0', batch_size=1)
# model trained by cfg/training/*.yaml
ckpt = torch.load('path to your custom trained yolov7-tiny.pt model: .../.../yolov7-tiny.pt', map_location=device)
# reparameterized model in cfg/deploy/*.yaml
model = Model('path to the file yolov7-tiny-deploy.yaml', ch=3, nc=8).to(device)

with open('path to the yaml file provided by realtek: .../.../yolov7-tiny-deploy.yaml') as f:
    yml = yaml.load(f, Loader=yaml.SafeLoader)
anchors = len(yml['anchors'][0]) // 2

# copy intersect weights
state_dict = ckpt['model'].float().state_dict()
exclude = []
intersect_state_dict = {k: v for k, v in state_dict.items() if k in model.state_dict() and not any(x in k for x in exclude) and v.shape == model.state_dict()[k].shape}
model.load_state_dict(intersect_state_dict, strict=False)
model.names = ckpt['model'].names
model.nc = ckpt['model'].nc

# reparametrized YOLOR
for i in range((model.nc+5)*anchors):
    model.state_dict()['model.77.m.0.weight'].data[i, :, :, :] *= state_dict['model.77.im.0.implicit'].data[:, i, : :].squeeze()
    model.state_dict()['model.77.m.1.weight'].data[i, :, :, :] *= state_dict['model.77.im.1.implicit'].data[:, i, : :].squeeze()
    model.state_dict()['model.77.m.2.weight'].data[i, :, :, :] *= state_dict['model.77.im.2.implicit'].data[:, i, : :].squeeze()
model.state_dict()['model.77.m.0.bias'].data += state_dict['model.77.m.0.weight'].mul(state_dict['model.77.ia.0.implicit']).sum(1).squeeze()
model.state_dict()['model.77.m.1.bias'].data += state_dict['model.77.m.1.weight'].mul(state_dict['model.77.ia.1.implicit']).sum(1).squeeze()
model.state_dict()['model.77.m.2.bias'].data += state_dict['model.77.m.2.weight'].mul(state_dict['model.77.ia.2.implicit']).sum(1).squeeze()
model.state_dict()['model.77.m.0.bias'].data *= state_dict['model.77.im.0.implicit'].data.squeeze()
model.state_dict()['model.77.m.1.bias'].data *= state_dict['model.77.im.1.implicit'].data.squeeze()
model.state_dict()['model.77.m.2.bias'].data *= state_dict['model.77.im.2.implicit'].data.squeeze()

# model to be saved
ckpt = {'model': deepcopy(model.module if is_parallel(model) else model).half(),
        'optimizer': None,
        'training_results': None,
        'epoch': -1}

# save reparameterized model
torch.save(ckpt,'path to deploy your reparameterized .pt model: .../.../yolov7-tiny_reparameterized.pt')

```

# yolov7-tiny-deploy.yaml

```auto
#This script is provided by Zhang Chang Ren from Realtek.

# Running of script:
# python reparam_yolov7-tiny.py --weights weights/best.pt --custom_yaml custom/yolov7-tiny-deploy.yaml --output best_reparam.pt

# Note that for yolov7-tiny-deploy.yaml, last line of yaml need to be changed to Detect.
# It has already been changed in this repository.

# parameters
nc: 2 # number of classes
depth_multiple: 1.0 # model depth multiple
width_multiple: 1.0 # layer channel multiple

# anchors
anchors:
  - [10,13, 16,30, 33,23] # P3/8
  - [30,61, 62,45, 59,119] # P4/16
  - [116,90, 156,198, 373,326] # P5/32

# yolov7-tiny backbone
backbone:
  # [from, number, module, args] c2, k=1, s=1, p=None, g=1, act=True
  [[-1, 1, Conv, [32, 3, 2, None, 1, nn.LeakyReLU(0.1)]], # 0-P1/2  
  
   [-1, 1, Conv, [64, 3, 2, None, 1, nn.LeakyReLU(0.1)]], # 1-P2/4    
   
   [-1, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-2, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [[-1, -2, -3, -4], 1, Concat, [1]],
   [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 7
   
   [-1, 1, MP, []], # 8-P3/8
   [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [[-1, -2, -3, -4], 1, Concat, [1]],
   [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 14
   
   [-1, 1, MP, []], # 15-P4/16
   [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-2, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [[-1, -2, -3, -4], 1, Concat, [1]],
   [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 21
   
   [-1, 1, MP, []], # 22-P5/32
   [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-2, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [[-1, -2, -3, -4], 1, Concat, [1]],
   [-1, 1, Conv, [512, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 28
  ]

# yolov7-tiny head
head:
  [[-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-2, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, SP, [5]],
   [-2, 1, SP, [9]],
   [-3, 1, SP, [13]],
   [[-1, -2, -3, -4], 1, Concat, [1]],
   [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [[-1, -7], 1, Concat, [1]],
   [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 37
  
   [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [21, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # route backbone P4
   [[-1, -2], 1, Concat, [1]],
   
   [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [[-1, -2, -3, -4], 1, Concat, [1]],
   [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 47
  
   [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, nn.Upsample, [None, 2, 'nearest']],
   [14, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # route backbone P3
   [[-1, -2], 1, Concat, [1]],
   
   [-1, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-2, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [[-1, -2, -3, -4], 1, Concat, [1]],
   [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 57
   
   [-1, 1, Conv, [128, 3, 2, None, 1, nn.LeakyReLU(0.1)]],
   [[-1, 47], 1, Concat, [1]],
   
   [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [[-1, -2, -3, -4], 1, Concat, [1]],
   [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 65
   
   [-1, 1, Conv, [256, 3, 2, None, 1, nn.LeakyReLU(0.1)]],
   [[-1, 37], 1, Concat, [1]],
   
   [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-2, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [[-1, -2, -3, -4], 1, Concat, [1]],
   [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 73
      
   [57, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [65, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
   [73, 1, Conv, [512, 3, 1, None, 1, nn.LeakyReLU(0.1)]],

   [[74,75,76], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
  ]

```

Im using the last version, the 4.0.7.

---

<div class="post-metadata">

**Author:** ![Ashlie\_Jane\_Balidio](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/ashlie_jane_balidio/32/2311_2.png) [@Ashlie\_Jane\_Balidio](https://forum.amebaiot.com/u/Ashlie_Jane_Balidio)\
**Post date:** [October 20, 2024, 5:51am UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/11 "2024-10-20T05:51:06Z")

</div>

how to develop a custom yolo v 7 tiny model

---

<div class="post-metadata">

**Author:** ![Aditya\_Jawa](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/aditya_jawa/32/2459_2.png) [@Aditya\_Jawa](https://forum.amebaiot.com/u/Aditya_Jawa)\
**Post date:** [February 12, 2025, 6:09am UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/12 "2025-02-12T06:09:08Z")

</div>

Please help, I want to create a standalone pothole detection from AMB82 mini. I am totally noob and have no ida what to do.

---

<div class="post-metadata">

**Author:** ![Pammy](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/pammy/32/936_2.png) [@Pammy](https://forum.amebaiot.com/u/Pammy)\
**Post date:** [February 14, 2025, 1:15am UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/13 "2025-02-14T01:15:31Z")

</div>

Hi @Aditya_Jawa ,

Once you have your model trained, you may refer to this website ([AI Related Guides — Ameba Arduino Documentation v1.1 documentation](https://ameba-doc-arduino-sdk.readthedocs-hosted.com/en/latest/amebapro2/Other_Guides/AI_Related_Guides/index.html)) for reference on how to convert and load model onto AMB82 Mini.

Previously, there’s a professor who trained this model as well, you can also refer to his kaggle ([YOLOv7 Pothole | Kaggle](https://www.kaggle.com/code/rkuo2000/yolov7-pothole)). Thank you.

---

<div class="post-metadata">

**Author:** ![shashank\_bewoor](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/shashank_bewoor/32/2537_2.png) [@shashank\_bewoor](https://forum.amebaiot.com/u/shashank_bewoor)\
**Post date:** [March 10, 2025, 9:28am UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/14 "2025-03-10T09:28:05Z")

</div>

in the reparamterization.py file where should we make changes to achieve custom object detection

---

<div class="post-metadata">

**Author:** ![Pammy](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/pammy/32/936_2.png) [@Pammy](https://forum.amebaiot.com/u/Pammy)\
**Post date:** [March 12, 2025, 1:46am UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/15 "2025-03-12T01:46:28Z")

</div>

Hi @shashank_bewoor, you need not change anything in the script.

You may refer to this example guide and run the command stated in the guide.

> **[Object Detection — Ameba Arduino AIoT Documentation v1.1 documentation](https://ameba-doc-arduino-sdk.readthedocs-hosted.com/en/latest/ameba_pro2/amb82-mini/Example_Guides/Neural%20Network/Object%20Detection.html)**

---

<div class="post-metadata">

**Author:** ![shashank\_bewoor](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/shashank_bewoor/32/2537_2.png) [@shashank\_bewoor](https://forum.amebaiot.com/u/shashank_bewoor)\
**Post date:** [March 13, 2025, 10:14am UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/16 "2025-03-13T10:14:19Z")

</div>

when i run the command python reparam\_yolov7-tiny.py –weights weights/best.pt –custom\_yaml custom/yolov7-tiny-deploy.yaml –output best\_reparam.pt it’s givivng an error IndexError: index 39 is out of bounds for dimension 0 with size 39

---

<div class="post-metadata">

**Author:** ![Pammy](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/pammy/32/936_2.png) [@Pammy](https://forum.amebaiot.com/u/Pammy)\
**Post date:** [March 17, 2025, 6:48am UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/17 "2025-03-17T06:48:19Z")

</div>

> [@shashank\_bewoor](#):
>
> IndexError: index 39 is out of bounds for dimension 0 with size 39

You have this error could be the number of classes is incorrect in yolov7-tiny-deploy.yaml ([ameba-arduino-pro2/Arduino\_package/hardware/libraries/NeuralNetwork/src/Yolov7\_reparam\_scripts/yolov7-tiny-deploy.yaml at dev · Ameba-AIoT/ameba-arduino-pro2 · GitHub](https://github.com/Ameba-AIoT/ameba-arduino-pro2/blob/dev/Arduino_package/hardware/libraries/NeuralNetwork/src/Yolov7_reparam_scripts/yolov7-tiny-deploy.yaml))

You can try changing it to 39.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/ameba/original/2X/6/6ee4991a916b1ffe8acdfa56bd930a21896cac6c.png)

---

<div class="post-metadata">

**Author:** ![MJK](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/mjk/32/2487_2.png) [@MJK](https://forum.amebaiot.com/u/MJK)\
**Post date:** [April 5, 2025, 4:03am UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/18 "2025-04-05T04:03:21Z")

</div>

how to train using YOLO v7-tiny i have no idea where to get?? Yolov7 only i saw

---

<div class="post-metadata">

**Author:** ![KevinKL](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/kevinkl/32/2632_2.png) [@KevinKL](https://forum.amebaiot.com/u/KevinKL)\
**Post date:** [April 24, 2025, 1:55am UTC](https://forum.amebaiot.com/t/custom-yolov7-tiny-model-on-amb82-mini-succesfully-implemented-but-not-working-properly/3162/19 "2025-04-24T01:55:21Z")

</div>

Hello

YOLOv7-tiny is a faster and less resource-intensive version of YOLOv7, you can find the trained model here [Release YOLOv7 · WongKinYiu/yolov7 · GitHub](https://github.com/WongKinYiu/yolov7/releases/tag/v0.1)

Thank you.
