hailo-ai / hailo_model_zoo

The Hailo Model Zoo includes pre-trained models and a full building and evaluation environment
MIT License
244 stars 38 forks source link

Mobilenetv2-ssd .hef conversion #21

Open aux82716 opened 1 year ago

aux82716 commented 1 year ago

Hi,

I'm trying to convert a mobilenetv2-ssd model trained using Tensorflow 1.15 object detection API on 1 class with 300x300x3 as input shape.

I tried to use hailo_model_zoo/main.py to convert this model and i modified the .yaml and .json files in the following way:

postprocessing:
  device_pre_post_layers:
    argmax: false
    softmax: false
    bilinear: false
    nms: true
  postprocess_config_json: my_model/mobilenet_v2_ssd_nms_postprocess_config.json
  meta_arch: ssd
  anchors:
    predefined: true
network:
  network_name: ssd_mobilenet_v2

-json

{
  "nms_scores_th": 0.3,
  "nms_iou_th": 0.6,
  "max_proposals_per_class": 20,
  "centers_scale_factor": 10,
  "scores_scale_factor": 5,
  "classes": 2,
  "background_removal": true,
  "background_removal_index": 0,
  "bbox_decoders": [
    {
      "name": "bbox_decoder28",
      "h": [
        0.1,
        0.1414213562373095,
        0.282842712474619
      ],
      "w": [
        0.1,
        0.282842712474619,
        0.1414213562373095
      ],
      "reg_layer": "conv28",
      "cls_layer": "conv29"
    },
    {
      "name": "bbox_decoder39",
      "h": [
        0.35,
        0.2474873734152916,
        0.4949747468305832,
        0.20207259421636903,
        0.6062480958117455,
        0.4183300132670378
      ],
      "w": [
        0.35,
        0.4949747468305833,
        0.24748737341529164,
        0.606217782649107,
        0.20206249033405482,
        0.4183300132670378
      ],
      "reg_layer": "conv39",
      "cls_layer": "conv40"
    },
    {
      "name": "bbox_decoder43",
      "h": [
        0.5,
        0.35355339059327373,
        0.7071067811865475,
        0.2886751345948129,
        0.8660687083024937,
        0.570087712549569
      ],
      "w": [
        0.5,
        0.7071067811865476,
        0.3535533905932738,
        0.8660254037844386,
        0.2886607004772212,
        0.570087712549569
      ],
      "reg_layer": "conv43",
      "cls_layer": "conv44"
    },
    {
      "name": "bbox_decoder47",
      "h": [
        0.65,
        0.4596194077712559,
        0.9192388155425117,
        0.37527767497325676,
        1.1258893207932419,
        0.7211102550927979
      ],
      "w": [
        0.65,
        0.9192388155425119,
        0.45961940777125593,
        1.12583302491977,
        0.3752589106203876,
        0.7211102550927979
      ],
      "reg_layer": "conv47",
      "cls_layer": "conv48"
    },
    {
      "name": "bbox_decoder51",
      "h": [
        0.8,
        0.565685424949238,
        1.131370849898476,
        0.46188021535170065,
        1.38570993328399,
        0.8717797887081347
      ],
      "w": [
        0.8,
        1.1313708498984762,
        0.5656854249492381,
        1.3856406460551018,
        0.46185712076355395,
        0.8717797887081347
      ],
      "reg_layer": "conv51",
      "cls_layer": "conv52"
    },
    {
      "name": "bbox_decoder54",
      "h": [
        0.95,
        0.67175144212722,
        1.34350288425444,
        0.5484827557301445,
        1.645530545774738,
        0.9746794344808963
      ],
      "w": [
        0.95,
        1.3435028842544403,
        0.6717514421272202,
        1.6454482671904334,
        0.5484553309067203,
        0.9746794344808963
      ],
      "reg_layer": "conv54",
      "cls_layer": "conv55"
    }
  ]
}

Running:

python hailo_model_zoo/main.py compile --ckpt my_model/model.ckpt --calib-path /my_images/test --yaml my_model/ssd_mobilenet_v2.yaml

I get the following error:

Traceback (most recent call last):
  File "hailo_model_zoo/main.py", line 178, in <module>
    main()
  File "hailo_model_zoo/main.py", line 174, in main
    run(args)
  File "hailo_model_zoo/main.py", line 163, in run
    return handlers[args.command](args)
  File "/home/giorgio/Project/hailo_model_zoo/hailo_model_zoo/main_driver.py", line 116, in compile
    _ensure_quantized(runner, logger, args, network_info)
  File "/home/giorgio/Project/hailo_model_zoo/hailo_model_zoo/main_driver.py", line 29, in _ensure_quantized
    _ensure_parsed(runner, logger, network_info, args)
  File "/home/giorgio/Project/hailo_model_zoo/hailo_model_zoo/main_driver.py", line 42, in _ensure_parsed
    parse_model(runner, network_info, ckpt_path=args.ckpt_path, results_dir=args.results_dir, logger=logger,
  File "/home/giorgio/Project/hailo_model_zoo/hailo_model_zoo/core/main_utils.py", line 134, in parse_model
    add_nms_postprocess(
  File "/home/giorgio/.virtualenvs/hailo_mz/lib/python3.8/site-packages/hailo_sdk_client/tools/core_postprocess/core_postprocess_api.py", line 197, in add_nms_postprocess
    new_hn, new_weights = create_nms_postprocess(runner.get_hn_model(),
  File "/home/giorgio/.virtualenvs/hailo_mz/lib/python3.8/site-packages/hailo_sdk_client/tools/core_postprocess/core_postprocess.py", line 33, in create_nms_postprocess
    postproc_creator.prepare_hn_and_weights()
  File "/home/giorgio/.virtualenvs/hailo_mz/lib/python3.8/site-packages/hailo_sdk_client/tools/core_postprocess/nms_postprocess.py", line 423, in prepare_hn_and_weights
    self._add_proposal_generator_layers()
  File "/home/giorgio/.virtualenvs/hailo_mz/lib/python3.8/site-packages/hailo_sdk_client/tools/core_postprocess/nms_postprocess.py", line 369, in _add_proposal_generator_layers
    proposal_generator_layer.update_output_shapes()
  File "/home/giorgio/.virtualenvs/hailo_mz/lib/python3.8/site-packages/hailo_sdk_common/hailo_nn/hn_layers/layer.py", line 506, in update_output_shapes
    output_shape = self._calc_output_shape()
  File "/home/giorgio/.virtualenvs/hailo_mz/lib/python3.8/site-packages/hailo_sdk_common/hailo_nn/hn_layers/proposal_generator.py", line 67, in _calc_output_shape
    raise UnsupportedModelError("Invalid input shapes for layer {}.".format(self.name))
hailo_sdk_common.hailo_nn.exceptions.UnsupportedModelError: Invalid input shapes for layer ssd_mobilenet_v2/proposal_generator1.

I put a print inside /.virtualenvs/hailo_mz/lib/python3.8/site-packages/hailo_sdk_common/hailo_nn/hn_layers/proposal_generator.py

print(boxes_shape, classes_shape, anchors, classes)

and I get these outputs: [-1, 19, 19, 12] [-1, 19, 19, 3] 3 1 [-1, 10, 10, 12] [-1, 10, 10, 128] 3 42

I suspect it is due to something related to layers inside the .json file "bbox_decoders" but I'm not able to solve this error; how can I solve it?

Thank you

batsheva-knecht commented 1 year ago

Hi, Thanks for addressing us regarding this issue. It is hard to identify the issue without .hn file. Please send us a ticket: https://hailo.ai/contact-customer-support/ with .hn file. Thank you