Pytorch-yolov3: use yolo-tiny to train own dataset error

Created on 28 Nov 2019  ·  5Comments  ·  Source: eriklindernoren/PyTorch-YOLOv3

i modify the classes in yolov3-tiny.cfg. Then I run the model with errors.
`/home/huangfu/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/huangfu/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/huangfu/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/huangfu/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/huangfu/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/huangfu/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
Namespace(batch_size=2, checkpoint_interval=1, compute_map=False, data_config='config/coco.data', epochs=10, evaluation_interval=1, gradient_accumulations=2, img_size=416, model_def='config/yolov3-tiny_my.cfg', multiscale_training=True, n_cpu=8, pretrained_weights=None)
WARNING:tensorflow:From /home/huangfu/github/PyTorch-YOLOv3/utils/logger.py:7: The name tf.summary.FileWriter is deprecated. Please use tf.compat.v1.summary.FileWriter instead.

Traceback (most recent call last):
File "train.py", line 107, in
loss, outputs = model(imgs, targets)
File "/home/huangfu/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 541, in __call__
result = self.forward(input, *kwargs)
File "/home/huangfu/github/PyTorch-YOLOv3/models.py", line 259, in forward
x, layer_loss = module0
File "/home/huangfu/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 541, in __call__
result = self.forward(input, *kwargs)
File "/home/huangfu/github/PyTorch-YOLOv3/models.py", line 147, in forward
x.view(num_samples, self.num_anchors, self.num_classes + 5, grid_size, grid_size)
RuntimeError: shape '[2, 3, 7, 14, 14]' is invalid for input of size 99960
`

Most helpful comment

First, you need to modify yolov3-tiny.cfg(or better to create another one yolov3-tiny-custom.cfg):

  1. change all rows 'filters=255' to 'filters=3(num_classes + 5)'. It is rows num 143 and 194.
    255 means 3
    (80 + 5). Coco dataset has 80 classes
  2. change all rows 'classes=80' to 'classes=num_classes'. It is rows num 152 and 201.
  3. I also change 'batch=1' to 'batch=16' but I think you can leave it and will not have runtime errors

For full yolo-v3 you have an option to train with pretrain weights - darknet53.conv.74. And if you want smth like this for tiny yolo-v3 you should do the following:

  1. install darknet
    git clone https://github.com/pjreddie/darknet.git
    cd darknet
    make
  2. download pretrain weights for tiny yolo-v3
    from https://pjreddie.com/media/files/yolov3-tiny.weights
    and place it in darknet folder
  3. copy your yolov3-tiny-custom.cfg to cfg folder
  4. run in terminal
    ./darknet partial cfg/yolov3-tiny-custom.cfg yolov3-tiny.weights yolov3-tiny.conv.15 15
  5. move yolov3-tiny.conv.15 to weights folder in PyTorch-YOLOv3 project
  6. in models.py add:
    elif "yolov3-tiny.conv.15" in weights_path: cutoff = 15
    row number - 280
  7. and then run
    python3 train.py --model_def config/yolov3-tiny-custom.cfg --data_config config/custom.data --pretrained_weights weights/yolov3-tiny.conv.15

All 5 comments

Have you solved the problem?Can you tell me the solution,please?

try changing the classes number in cfg

modify yolov3-tiny.cfg total three part in last conv.

[convolutional]
filters=3*(classes+1+4)

try changing the classes number in cfg

Have you solved the problem?Can you tell me the solution,please?

modify yolov3-tiny.cfg total three part in last conv.

[convolutional]
filters=3*(classes+1+4)

First, you need to modify yolov3-tiny.cfg(or better to create another one yolov3-tiny-custom.cfg):

  1. change all rows 'filters=255' to 'filters=3(num_classes + 5)'. It is rows num 143 and 194.
    255 means 3
    (80 + 5). Coco dataset has 80 classes
  2. change all rows 'classes=80' to 'classes=num_classes'. It is rows num 152 and 201.
  3. I also change 'batch=1' to 'batch=16' but I think you can leave it and will not have runtime errors

For full yolo-v3 you have an option to train with pretrain weights - darknet53.conv.74. And if you want smth like this for tiny yolo-v3 you should do the following:

  1. install darknet
    git clone https://github.com/pjreddie/darknet.git
    cd darknet
    make
  2. download pretrain weights for tiny yolo-v3
    from https://pjreddie.com/media/files/yolov3-tiny.weights
    and place it in darknet folder
  3. copy your yolov3-tiny-custom.cfg to cfg folder
  4. run in terminal
    ./darknet partial cfg/yolov3-tiny-custom.cfg yolov3-tiny.weights yolov3-tiny.conv.15 15
  5. move yolov3-tiny.conv.15 to weights folder in PyTorch-YOLOv3 project
  6. in models.py add:
    elif "yolov3-tiny.conv.15" in weights_path: cutoff = 15
    row number - 280
  7. and then run
    python3 train.py --model_def config/yolov3-tiny-custom.cfg --data_config config/custom.data --pretrained_weights weights/yolov3-tiny.conv.15
Was this page helpful?
0 / 5 - 0 ratings

Related issues

codeyogi911 picture codeyogi911  ·  4Comments

qilong-zhang picture qilong-zhang  ·  5Comments

mwharton3 picture mwharton3  ·  3Comments

monteksingh picture monteksingh  ·  3Comments

zhaowt61 picture zhaowt61  ·  4Comments