Skip to content

[edgeai-mmdetection] No Detections Derived from Image Demo for YOLO*_lite Models #21

Description

@YuleYangX

Describe the bug
The official edgeai-tensorlab/edgeai-mmdetection/demo/image_demo.py cannot derive correct detections for yolo*_lite models. For example the following command (in edgeai-tensorlab/edgeai-mmdetection direcotory) with the pretrained yolox_tiny_lite model cannot detect any object in the demo image.

# python demo/image_demo.py demo/demo.jpg configs_edgeailite/yolox/yolox_tiny_lite.py --weights yolox_tiny_lite_416x416_20220217_checkpoint.pth

Versions
Release 11.0

Proposed Workaround
To make it work properly, I modified edgeai-tensorlab/edgeai-mmdetection/mmdet/apis/det_inferencer.py to convert the model before loading weights as that in edgeai-tensorlab/edgeai-mmdetection/mmdet/tools/test.py.

  • Initialize self.replacement_dict in DetInferencer.__init__() if the given model is a config file
  • Convert model acccording to self.replacement_dict if needed at the begining of DetInferencer._load_weights_to_model()
...
from mmengine.config import Config
from mmdet.utils.model_optimization import get_replacement_dict
from edgeai_torchmodelopt import xmodelopt
...
class DetInferencer(BaseInferencer):
    ...
    def __init__(self,
                 model: Optional[Union[ModelType, str]] = None,
                 weights: Optional[str] = None,
                 device: Optional[str] = None,
                 scope: Optional[str] = 'mmdet',
                 palette: str = 'none',
                 show_progress: bool = True) -> None:
        self.replacement_dict = None
        if isinstance(model, str):
            cfg = Config.fromfile(model)
            if hasattr(cfg,'convert_to_lite_model'):
                self.replacement_dict = get_replacement_dict(cfg.convert_to_lite_model.model_surgery, cfg)
        ...

    def _load_weights_to_model(self, model: nn.Module,
                               checkpoint: Optional[dict],
                               cfg: Optional[ConfigType]) -> None:
        """Loading model weights and meta information from cfg and checkpoint.

        Args:
            model (nn.Module): Model to load weights and meta information.
            checkpoint (dict, optional): The loaded checkpoint.
            cfg (Config or ConfigDict, optional): The loaded config.
        """
        if self.replacement_dict:
            model = xmodelopt.surgery.v1.convert_to_lite_model(model, replacement_dict=self.replacement_dict)
        ....

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions