I get and error when training the model with the error:
LabelSmoothLoss requires output and target to be same shape, but got output.shape: torch.Size([32, 9]) and target.shape: torch.Size([32, 1000])
I cant find the reason why the target.shape being [32, 1000] because the data only has 9 classes. Does anybody has the fix/answer? thankyou
# Load the base config file
from mmcv import Config
from mmcls.utils import auto_select_device
cfg = Config.fromfile('/content/mmclassification/configs/swin_transformer/swin-base_16xb64_in1k.py')
cfg.device = auto_select_device()
# Modify the number of classes in the head.
cfg.model.head.num_classes = 9
cfg.model.head.topk = (1, )
# Load the pre-trained model's checkpoint.
cfg.model.backbone.init_cfg = dict(type='Pretrained',
checkpoint='https://download.openmmlab.com/mmclassification/v0/swin-transformer/convert/swin_small_patch4_window7_224-cc7a01c9.pth',
prefix='backbone')
cfg.model.backbone.frozen_stages = 2
# Specify sample size and number of workers.
cfg.data.samples_per_gpu = 32
cfg.data.workers_per_gpu = 2
# Specify the path and meta files of training dataset
dataset_type = 'CustomDataset'
cfg.data.train.data_prefix = 'output/fishdataset/train'
cfg.data.train.ann_file = None
cfg.data.train.type = dataset_type
# Specify the path and meta files of validation dataset
cfg.data.val.data_prefix = 'output/fishdataset/val'
cfg.data.val.ann_file = None
cfg.data.val.type = dataset_type
# Specify the path and meta files of test dataset
cfg.data.test.data_prefix = 'output/fishdataset/test'
cfg.data.test.ann_file = None
cfg.data.test.type = dataset_type
# Specify the normalization parameters in data pipeline
normalize_cfg = dict(type='Normalize', mean=[124.508, 116.050, 106.438], std=[58.577, 57.310, 57.437], to_rgb=True)
cfg.data.train.pipeline[3] = normalize_cfg
cfg.data.val.pipeline[3] = normalize_cfg
cfg.data.test.pipeline[3] = normalize_cfg
# Modify the evaluation metric
cfg.evaluation['metric_options']={'topk': (1, )}
# Specify the optimizer
cfg.optimizer = dict(type='SGD', lr=0.005, momentum=0.9, weight_decay=0.0001)
cfg.optimizer_config = dict(grad_clip=None)
# Specify the learning rate scheduler
cfg.lr_config = dict(policy='step', step=1, gamma=0.1)
cfg.runner = dict(type='EpochBasedRunner', max_epochs=2)
# Specify the work directory
cfg.work_dir = './work_dirs/fish'
# Output logs for every 10 iterations
cfg.log_config.interval = 10
# Set the random seed and enable the deterministic option of cuDNN
# to keep the results' reproducible.
from mmcls.apis import set_random_seed
cfg.seed = 0
set_random_seed(0, deterministic=True)
cfg.gpu_ids = range(1)