mmdetection2.3.0训练报错:RuntimeError: The size of tensor a (8) must match the size of tensor b (81)

欢迎大家关注笔者,你的关注是我持续更博的最大动力


原创文章,转载告知,盗版必究


mmdetection2.3.0训练报错:RuntimeError: The size of tensor a (8) must match the size of tensor b (81) at non-singleton dimension 1

文章目录:


1 错误原因分析

1、使用SAC-Cascade模型训练,模型位置:

./configs/detectors/cascade_rcnn_r50_sac_1x_coco.py

2、修改类别数num_classes,在如下的配置文件中修改

./configs/base/models/cascade_rcnn_r50_fpn.py

3、使用多GPU训练命令

./tools/dist_train.sh ./configs/detectors/cascade_rcnn_r50_sac_1x_coco.py 3 --work-dir 23_work_dirs_sac_cascade_hat_hair_beard

然后运行包如下错误,即使使用单GPU依然会报如下错误:
在这里插入图片描述

这个错误原因是由于num_classes没有完全修改导致,

2 解决方式

修改如下配置文件中:num_classes的类别为自己的类别

./configs/base/models/cascade_rcnn_r50_fpn.py

注意:

这个文件中一共有三处 num_classes=80,把这个num_classes全部修改为自己的类别即可


在这里插入图片描述




在这里插入图片描述
♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠

已标记关键词 清除标记
相关推荐
<div><p>When I use the following script trains the transformer model on CNN-DM<a href="url">http://opennmt.net/OpenNMT-py/Summarization.html</a> <code>onmt_train -data data/cnndm/CNNDM \ -save_model models/cnndm \ -layers 4 \ -rnn_size 512 \ -word_vec_size 512 \ -max_grad_norm 0 \ -optim adam \ -encoder_type transformer \ -decoder_type transformer \ -position_encoding \ -dropout 0\.2 \ -param_init 0 \ -warmup_steps 8000 \ -learning_rate 2 \ -decay_method noam \ -label_smoothing 0.1 \ -adam_beta2 0.998 \ -batch_size 4096 \ -batch_type tokens \ -normalization tokens \ -max_generator_batches 2 \ -train_steps 200000 \ -accum_count 4 \ -share_embeddings \ -copy_attn \ -param_init_glorot \ -world_size 2 \ -gpu_ranks 0 1</code> I meet the following error: Traceback (most recent call last): File "train.py", line 438, in main() File "train.py", line 430, in main train_model(model, fields, optim, data_type, model_opt) File "train.py", line 252, in train_model train_stats = trainer.train(train_iter, epoch, report_func) File "/home/cai/yym/ddl/final/OpenNMT-py-copy_constraint/onmt/Trainer.py", line 178, in train report_stats, normalization) File "/home/cai/yym/ddl/final/OpenNMT-py-copy_constraint/onmt/Trainer.py", line 311, in _gradient_accumulation trunc_size, self.shard_size, normalization) File "/home/cai/yym/ddl/final/OpenNMT-py-copy_constraint/onmt/Loss.py", line 123, in sharded_compute_loss loss, stats = self._compute_loss(batch, <strong>shard) File "/home/cai/yym/ddl/final/OpenNMT-py-copy_constraint/onmt/modules/CopyGenerator.py", line 201, in _compute_loss batch.src_map) File "/home/cai/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in <strong>call</strong> result = self.forward(*input, </strong>kwargs) File "/home/cai/yym/ddl/final/OpenNMT-py-copy_constraint/onmt/modules/CopyGenerator.py", line 99, in forward mul_attn = torch.mul(attn, tags) * 2 RuntimeError: The size of tensor a (400) must match the size of tensor b (0) at non-singleton dimension 1</p><p>该提问来源于开源项目:sebastianGehrmann/bottom-up-summary</p></div>
©️2020 CSDN 皮肤主题: 猿与汪的秘密 设计师:白松林 返回首页