Closed XianyunSun closed 3 months ago
You can check the parameter list by using net.get_parameters()
after running net = mindcv.create_model('convnext_tiny', pretrained=True, num_classes=1)
. Then you will see the parameter adam_v.classification.weight
, adam_v.classification.bais
, adam_m.classification.weight
and adam_m.classification.bais
are not included in the net
.
So even if these four parameters are not removed from the parameter list loaded by ckpt, they will not be loaded int the net
.
Describe the bug/ 问题描述 (Mandatory / 必填) I run into the error when running:
net = mindcv.create_model('convnext_tiny', pretrained=True, num_classes=1)
where the shape of the parameters of the last classification layer do not match, but they should not be loaded when num_class is not 1000, according to the demo. Althoughclassification.weight
andclassification.bais
is popped out when loading parameters, the remainingadam_v.classification.weight
,adam_v.classification.bais
,adam_m.classification.weight
andadam_m.classification.bais
parameters are still loaded, which caused this problem.I solved this problem by changing a few lines in
mindcv/models/helpers.py
:_search_param_name
to return a list containing all parameter names that containclassification.weight
orclassification.bais
:load_pretrained
function to pop out all parameter names returned by_search_param_name
:I'm not sure if these will influence the other parts of the code, but at least they can work for this problem.
Hardware Environment(
Ascend
/GPU
/CPU
) / 硬件环境:Software Environment / 软件环境 (Mandatory / 必填): -- MindSpore version: 2.0.0 -- Python version: 3.9.16
Excute Mode / 执行模式 (Mandatory / 必填)(
PyNative
/Graph
):