YOLOv7-tiny .nb (NBG) model inference shows no bounding boxes on Amb82-mini

The Core Issue: I have successfully converted a custom-trained YOLOv7-tiny model into the .nb (Network Binary) format for the Amb82-mini (AmebaPro2) IoT device. Although the conversion process (both local and online) completes without errors, the model fails to output any bounding boxes during inference on the device.

1. YOLO Training Procedure

I trained the model using the following configurations:

  • Model Architecture: YOLOv7-tiny.

  • Custom Config: yolov7-tiny-custom.yaml with 2 classes (nc: 2).

  • Hyperparameters: Used hyp.scratch.tiny.yaml.

  • Training Command: python train.py --weights yolov7-tiny.pt --cfg cfg/training/yolov7-tiny-custom.yaml --img 640 640 ....

  • Result: Obtained best.pt.

2. Online Conversion Steps

I tested the official online conversion service with these steps:

  1. Reparameterization: Used reparam_yolov7-tiny.py (with yolov7-tiny-deploy.yaml) on best.pt to generate a simplified .pt file. (nc is correct)

  2. Packaging: Compressed the simplified .pt into a .zip archive.

  3. Uploading: Uploaded to the service with the following settings:

    • Model Type: YOLOv7-TINY-Pytorch.

    • Input Size: 640x640.

    • Quantization: UINT8.

    • Calibration: Provided 10 training images.

3. Local Conversion Procedure

This is the full workflow I followed using the local Acuity Toolkit (v6.18.8):

  1. Reparameterization (Pre-export): Before exporting to ONNX, I processed best.pt using a custom script reparam_yolov7-tiny.py and the yolov7-tiny-deploy.yaml (with nc: 2 correctly set) to merge weights.

  2. ONNX Export: Exported the reparameterized model using: python export.py --weights best_deploy.pt --grid --simplify.

  3. Acuity Pipeline (Import → Preprocess → Quantize → Export): Ran custom scripts (01 to 04) to generate the final .nb file

[Custom Scripts]

Below are the scripts I used for the conversion, which are not provided by the official toolkit by default:

Model Import (01_import_yolov7.sh)

#!/bin/bash


MODEL_NAME="best"
ONNX_FILE="best.onnx"

INPUT_NAME="images"
INPUT_SHAPE="3,640,640"

OUTPUT_NAME="output"


PEGASUS_SCRIPT="$HOME/verisilicon_conv_tool/acuity-toolkit-whl-6.18.8/bin/pegasus.py"

if [ ! -f "$PEGASUS_SCRIPT" ]; then
    echo "cant find pegasus.py!"
    exit 1
fi

python $PEGASUS_SCRIPT import onnx \
    --model  $ONNX_FILE \
    --output-model  ${MODEL_NAME}.json \
    --output-data   ${MODEL_NAME}.data \
    --inputs  $INPUT_NAME \
    --input-size-list $INPUT_SHAPE \
    --outputs "$OUTPUT_NAME"

Preprocessing (02_preprocess.sh)

#!/bin/bash

MODEL_JSON="best.json"
META_FILE="best_inputmeta.yml"
DATA_LIST="dataset.txt"


PEGASUS_SCRIPT="$HOME/verisilicon_conv_tool/acuity-toolkit-whl-6.18.8/bin/pegasus.py"

if [ ! -f "$PEGASUS_SCRIPT" ]; then
    echo "cant find pegasus.py!"
    exit 1
fi

python $PEGASUS_SCRIPT generate inputmeta \
    --model $MODEL_JSON \
    --input-meta-output $META_FILE

if [ "$(uname)" == "Darwin" ]; then
    sed -i '' "s|source_file:|source_file: $DATA_LIST|g" $META_FILE
else
    sed -i "s|source_file:|source_file: $DATA_LIST|g" $META_FILE
fi

if [ "$(uname)" == "Darwin" ]; then
    sed -i '' 's/scale: 1.0/scale: 0.00392156862/g' $META_FILE
    sed -i '' 's/scale: 1/scale: 0.00392156862/g' $META_FILE
else
    sed -i 's/scale: 1.0/scale: 0.00392156862/g' $META_FILE
    sed -i 's/scale: 1/scale: 0.00392156862/g' $META_FILE
fi

Quantization (03_quantize.sh)

#!/bin/bash

MODEL_NAME="best"
JSON_FILE="${MODEL_NAME}.json"
DATA_FILE="${MODEL_NAME}.data"
META_FILE="${MODEL_NAME}_inputmeta.yml"

PEGASUS_SCRIPT="$HOME/verisilicon_conv_tool/acuity-toolkit-whl-6.18.8/bin/pegasus.py"

python $PEGASUS_SCRIPT quantize \
    --model $JSON_FILE \
    --model-data $DATA_FILE \
    --with-input-meta $META_FILE \
    --rebuild \
    --model-quantize "${MODEL_NAME}.quantize" \
    --quantizer asymmetric_affine \
    --qtype uint8

NBG Export (04_export.sh)

#!/bin/bash

MODEL_NAME="best"
QUANTIZE_FILE="${MODEL_NAME}.quantize"
META_FILE="${MODEL_NAME}_inputmeta.yml"
DATA_FILE="${MODEL_NAME}.data"
JSON_FILE="${MODEL_NAME}.json"
EXPORT_DIR="export_out"

SDK_ROOT="$HOME/verisilicon_conv_tool/acuity-toolkit-whl-6.18.8/sdk/VivanteIDE5.8.1.1/cmdtools"
VIV_SDK_ROOT="$SDK_ROOT"  

export VIVANTE_SDK_DIR="$SDK_ROOT/vsimulator"
export AQROOT="$SDK_ROOT"

# 清理輸出
rm -rf $EXPORT_DIR
mkdir $EXPORT_DIR

echo "Target SDK Path: $VIV_SDK_ROOT"

python $HOME/verisilicon_conv_tool/acuity-toolkit-whl-6.18.8/bin/pegasus.py export ovxlib \
    --model $JSON_FILE \
    --model-data $DATA_FILE \
    --model-quantize $QUANTIZE_FILE \
    --with-input-meta $META_FILE \
    --dtype quantized \
    --output-path $EXPORT_DIR \
    --pack-nbg-unify \
    --optimize VIP8000NANONI_PID0XAD \
    --target-ide-project linux64 \
    --viv-sdk $VIV_SDK_ROOT

[Summary ]

Despite both conversion methods (local and online) completing successfully, the inference result on Amb82-mini remains empty (no boxes).

Hi @t114c75035 ,

Thank you for the report. May I know if you have modified models/yolo.py file in the YOLOv7 repo? You may refer to the guide NN Example (Yolov7_tiny) to modify the forward function within class Detect. Kindly take note of the part of Convert PyTorch to onnx.

Thank you.

Hello,

I have not modified models/yolo.py previously. I just made the necessary updates, and training/testing is currently in progress. I will provide further updates on the status as the process continues.

Thank you for your guidance.

Hello,

Following your previous guidance, I have modified the forward function in the Detect class within models/yolo.py according to the NN Example (Yolov7_tiny) guide and retrained the model.

However, after retraining and converting the new weights to .nb format using both the Online Conversion Service and the Acuity Toolkit (v6.18.8), the model still fails to output any bounding boxes on the device. I am using the standard ObjectDetectionLoop example for testing.

Additionally, I suspect there may be an issue with the Online Conversion Service. When I attempted to upload another .pt file for testing, the loading icon (spinner) next to the submit button kept spinning indefinitely, and the upload could not be completed successfully.

Hello,

I have successfully resolved the issue. The model now outputs bounding boxes correctly on the Amb82-mini using the ObjectDetectionLoop example.

The root causes were related to the ONNX export parameters and the import script. Here are the steps that fixed the problem:

  1. Model Modification: Applied the changes to the forward function in the Detect class (models/yolo.py) as previously suggested.

  2. ONNX Export: Modified the export command to python export.py --weights reparam_best.pt --simplify --img-size 640 640. Importantly, removing the --grid flag was necessary for the model to work correctly after conversion.

  3. Acuity Import Script: In the 01_import_yolov7.sh script, I removed the --outputs argument, allowing the tool to automatically identify the output nodes.

Thank you for your initial guidance regarding the yolo.py modification, which was a key part of the solution.

Best regards,

1 Like