Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MobilenetV3 Grove AI vision V2 board #282

Open
rn776 opened this issue Feb 17, 2025 · 3 comments
Open

MobilenetV3 Grove AI vision V2 board #282

rn776 opened this issue Feb 17, 2025 · 3 comments
Assignees
Labels
ModelAssistant Label for ModelAssistant UAY Unassigned yet

Comments

@rn776
Copy link

rn776 commented Feb 17, 2025

Hello, I have a classification model with MobilenetV3 as the backbone. The trained model was exported to 'vela' format as suggested. However, the flashed board fails to invoke. The classifier model with MobilenetV2 invokes without issue. Is there any way to run the MobilenetV3 models on the board?
My training config files is below, Please let me know if its an error in the config file.

from mmengine.config import read_base
from mmengine.dataset import DefaultSampler
with read_base():
    from .._base_.default_runtime import *
    from .._base_.schedules.schedule_1x import *
from sscma.datasets import CustomDataset
# from sscma.deploy.models.fomo_infer import FomoInfer
from sscma.deploy.models.classification_infer import ClassificationInfer
from mmengine.optim import LinearLR, MultiStepLR
from sscma.datasets.transforms import (
    Resize,
    PackInputs,
    LoadImageFromFile,
    RandomFlip,
)
from sscma.visualization import UniversalVisualizer
from sscma.datasets import ClsDataPreprocessor
from sscma.models import ImageClassifier, CrossEntropyLoss, GlobalAveragePooling
from sscma.models import MobileNetV3, LinearClsHead
from sscma.evaluation import Accuracy


# ========================Suggested optional parameters========================
num_classes = 2
widen_factor = 0.1
dataset_type = CustomDataset
data_root = "/home/pip_dataset"
height = 192
width = 192
imgsz = (width, height)
batch = 8
workers = 2
persistent_workers = True
val_batch = 8
val_workers = 2
lr = 0.02
epochs = 100

default_hooks = dict(param_scheduler=dict(type=ParamSchedulerHook))
visualizer = dict(type=UniversalVisualizer, vis_backends=[dict(type='WandbVisBackend')])

train_pipeline = [
    dict(type=LoadImageFromFile,imdecode_backend='cv2'),
    dict(type=Resize, scale=height),
    dict(type=RandomFlip, prob=0.5, direction="horizontal"),
    dict(type=RandomFlip, prob=0.5, direction="vertical"),
    dict(type=PackInputs),
]

test_pipeline = [
    dict(type=LoadImageFromFile,imdecode_backend='cv2'),
    # dict(type=ResizeEdge, scale=height, edge="short"),
    dict(type=Resize, scale=height),
    dict(type=PackInputs),
]

train_dataloader = dict(
    batch_size=batch,
    num_workers=workers,
    persistent_workers=persistent_workers,
    drop_last=False,
    # pin_memory=True,
    dataset=dict(
        type=dataset_type,
        data_root=data_root,
        data_prefix=dict(img_path="train"),
        pipeline=train_pipeline,
    ),
    sampler=dict(type=DefaultSampler, shuffle=True),
)

val_dataloader = dict(
    batch_size=val_batch,
    num_workers=val_workers,
    persistent_workers=persistent_workers,
    drop_last=False,
    # pin_memory=True,
    dataset=dict(
        type=dataset_type,
        data_root=data_root,
        data_prefix=dict(img_path="valid"),
        pipeline=test_pipeline,
    ),
    sampler=dict(type=DefaultSampler, shuffle=False),
)
val_evaluator = dict(type=Accuracy, topk=(1, ))

test_dataloader = val_dataloader
test_evaluator = val_evaluator

# ===================================================================

data_preprocessor = dict(
    type=ClsDataPreprocessor,
    mean=[0, 0, 0],
    std=[255.0, 255.0, 255.0],
    to_rgb=True,
    num_classes=num_classes,

)


model = dict(
    type=ImageClassifier,
    data_preprocessor=data_preprocessor,
    backbone=dict(
        type=MobileNetV3, widen_factor=widen_factor, out_indices=(2,), rep=False,
    ),
    neck=dict(type=GlobalAveragePooling),
    head=dict(
        type=LinearClsHead,
        in_channels=8,
        num_classes=num_classes,
        loss=dict(
            type=CrossEntropyLoss,
            loss_weight=1.0,
        ),
    ),
)


train_cfg = dict(by_epoch=True, max_epochs=epochs)


# learning policy
param_scheduler = [
    dict(type=LinearLR, begin=0, end=30, start_factor=0.001, by_epoch=False), 
    dict(
        type=MultiStepLR,
        begin=1,
        end=100,
        milestones=[50, 70, 90],
        gamma=0.3,
        by_epoch=True,
    ),
]

deploy = dict(
    type=ClassificationInfer,
    data_preprocessor=data_preprocessor,
)
@baorepo
Copy link
Member

baorepo commented Feb 19, 2025

@rn776 There is not much difference between v3 and v2. Do you have a visual model? How about a comparison?

@rn776
Copy link
Author

rn776 commented Feb 21, 2025

Image
Image

Here are the two models. The mobilenetv3 flashes into the board but it says 'invoke failed'.

@Lesords Lesords added UAY Unassigned yet ModelAssistant Label for ModelAssistant labels Feb 24, 2025
@iChizer0
Copy link
Contributor

iChizer0 commented Feb 25, 2025

Hi @rn776, the two are almost identical from the model structure you provided, but I suspect that you have an exception in the configuration using MobileNet v3, where the Hardswish Act is not handled correctly by the Vela converter. You can try use Relu6 as an activation function, or if it's convenient, please also provide the pre-exported TFLite and post-exported Vela models, we will do further confirmation and fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ModelAssistant Label for ModelAssistant UAY Unassigned yet
Projects
Status: No status
Development

No branches or pull requests

5 participants