WongKinYiu / yolor

implementation of paper - You Only Learn One Representation: Unified Network for Multiple Tasks (https://arxiv.org/abs/2105.04206)
GNU General Public License v3.0
1.98k stars 524 forks source link

RuntimeError: shape ‘[1,3,205,20,20]’ is invalid for input of size 102000 #251

Open pink0203 opened 2 years ago

pink0203 commented 2 years ago

How to solve such an error when using the YOLOR model to train your own data set?

image
beratersari commented 2 years ago

did you solve it?

Timmimim commented 1 year ago

In case you haven't solved the issue: This looks like the error I ran into after adjusting my .cfg file to my custom number of classes. In addition to changing classes=<n_classes>, you also need to change the number of filters before and within each YOLO head.

Example taken from my custom yolor_p6.cfg for n=5 classes:

#! Modify #filters to (#classes+5)*3 

# 207
[implicit_mul]
filters=30     <-- ( (<n_classes = 5> + 5) * 3 )

# 208
[implicit_mul]
filters=30

# 209
[implicit_mul]
filters=30

# 210
[implicit_mul]
filters=30

# ============ Head ============ #

# YOLO-3

[route]
layers = 163

[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=silu

[shift_channels]
from=203

[convolutional]
size=1
stride=1
pad=1
filters=30        <-- ( (<n_classes = 5> + 5) * 3 )
activation=linear

[control_channels]
from=207     <-- references the [implicit_mul] # 207, for which we needed to adjust filters

[yolo]
mask = 0,1,2
anchors = 19,27,  44,40,  38,94,  96,68,  86,152,  180,137,  140,301,  303,264,  238,542,  436,615,  739,380,  925,792
classes=5     <-- new number of classes
num=12
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
scale_x_y = 1.05
iou_thresh=0.213
cls_normalizer=1.0
iou_normalizer=0.07
iou_loss=ciou
nms_kind=greedynms
beta_nms=0.6

[...]     <-- Shortened; the other yolo heads need to be adjusted too, following the same schema. They reference [implicit_mul] # 208, 209, 210

# ============ End of Head ============ #

A full edited version of the relevant portions for n=1 classes was shown by @wiekern in https://github.com/WongKinYiu/yolor/issues/16#issuecomment-927455237.