dog-qiuqiu / FastestDet

:zap: A newly designed ultra lightweight anchor free target detection algorithm, weight only 250K parameters, reduces the time consumption by 10% compared with yolo-fastest, and the post-processing is simpler
BSD 3-Clause "New" or "Revised" License
768 stars 131 forks source link

Set custom input resolution #46

Open susanin1970 opened 1 year ago

susanin1970 commented 1 year ago

Hi :) Thanks for this repo

I have a problem with setting a custom input resolution in YAML config

DATASET:
  TRAIN: path\to\train\txt
  VAL: path\to\test\txt 
  NAMES: path\to\names
MODEL:
  NC: 1
  INPUT_WIDTH: 240
  INPUT_HEIGHT: 240
TRAIN:
  LR: 0.001
  THRESH: 0.25
  WARMUP: true
  BATCH_SIZE: 64
  END_EPOCH: 200
  MILESTIONES:
    - 50
    - 100
    - 150

When I try to train FastestDet with different resolution, not default 352x352 (for example, 240x240), I got RuntimeError:

Load yaml sucess...
<utils.tool.LoadYaml object at 0x00000299198CD8B0>
Initialize params from:./module/shufflenetv2.pth
Traceback (most recent call last):
  File "E:\Repositories\FastestDet\train.py", line 134, in <module>
    model = FastestDet()
  File "E:\Repositories\FastestDet\train.py", line 42, in __init__
    summary(self.model, input_size=(3, self.cfg.input_height, self.cfg.input_width))
  File "C:\Users\Reutov\.anaconda3\envs\experimental_env\lib\site-packages\torchsummary\torchsummary.py", line 72, in summary
    model(*x)
  File "C:\Users\Reutov\.anaconda3\envs\experimental_env\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "E:\Repositories\FastestDet\module\detector.py", line 25, in forward
    P = torch.cat((P1, P2, P3), dim=1)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 15 but got size 16 for tensor number 2 in the list.

Shapes of P1, P2 and P3 (240х240): torch.Size([2, 48, 30, 30]) torch.Size([2, 96, 15, 15]) torch.Size([2, 192, 8, 8])
Shapes of P1, P2 and P3 (358x358): torch.Size([2, 48, 44, 44]) torch.Size([2, 96, 22, 22]) torch.Size([2, 192, 11, 11])

I can guess that I need to change the architecture of the backbone network a little bit, but pretrained weights will not to load correctly in this case

How can I to change input resolution for training FastestDet? Can I to change input resolution of FastestDet in convert to ONNX process?

Thanks in advance :)

superbayes commented 12 months ago

i know that yolov5 support Dynamic size input

susanin1970 commented 12 months ago

i know that yolov5 support Dynamic size input

That's right, but I dont think, that FastestDet is based on YOLOv5