gpt4 book ai didi

python - 如何解决 "Variable is available in checkpoint, but has an incompatible shape with model variable"?

转载 作者:行者123 更新时间:2023-12-01 08:28:04 28 4
gpt4 key购买 nike

我正在尝试通过对象检测 API 重新训练现有的预训练网络。它是 ssd_mobilenet_v2。在 COCO 数据集上进行预训练。我根据固定到 obj-detection-API 的教程重现步骤。

模型无论如何都会开始训练,但 % mAP 很低。我对 CNN 完全陌生,因此非常感谢任何帮助。

当我开始训练时,会出现此警告,但我找不到修复方法。

我正在使用此命令在谷歌协作笔记本中运行它

# Training
!python object_detection/model_main.py \
--pipeline_config_path=${PIPELINE_CONFIG_PATH} \
--model_dir=${MODEL_DIR} \
--num_train_steps=${NUM_TRAIN_STEPS} \
--sample_1_of_n_eval_examples=$SAMPLE_1_OF_N_EVAL_EXAMPLES \
--alsologtostderrps

这是我收到的警告:

WARNING:root:Variable [FeatureExtractor/MobilenetV2/layer_19_2_Conv2d_2_3x3_s2_512/weights] is     available in checkpoint, but has an incompatible shape with model variable. Checkpoint shape: [[1, 1, 256, 512]], model variable shape: [[3, 3, 256, 512]]. This variable will not be initialized from the checkpoint.
WARNING:root:Variable [FeatureExtractor/MobilenetV2/layer_19_2_Conv2d_3_3x3_s2_256/weights] is available in checkpoint, but has an incompatible shape with model variable. Checkpoint shape: [[1, 1, 128, 256]], model variable shape: [[3, 3, 128, 256]]. This variable will not be initialized from the checkpoint.
WARNING:root:Variable [FeatureExtractor/MobilenetV2/layer_19_2_Conv2d_4_3x3_s2_256/weights] is available in checkpoint, but has an incompatible shape with model variable. Checkpoint shape: [[1, 1, 128, 256]], model variable shape: [[3, 3, 128, 256]]. This variable will not be initialized from the checkpoint.
WARNING:root:Variable [FeatureExtractor/MobilenetV2/layer_19_2_Conv2d_5_3x3_s2_128/weights] is available in checkpoint, but has an incompatible shape with model variable. Checkpoint shape: [[1, 1, 64, 128]], model variable shape: [[3, 3, 64, 128]]. This variable will not be initialized from the checkpoint.

运行大约 10 分钟后,它会打印出以下内容:

Accumulating evaluation results...
DONE (t=1.73s).
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.000
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.002
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.000
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.000
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.000
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.006
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.040
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.002
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.026
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.050

我没有更改 *.ckpt 文件,只是下载了 ssd_mobilenet_v2_coco_2018_03_29 的原始预训练版本并使用它们并将它们链接到 .config 文件中。

我花了一天多时间试图弄清楚。谢谢您的帮助。

最佳答案

您的错误消息显示(取第一行,它们都很相似):

layer_19_2_Conv2d_2_3x3_s2_512/weights is available in checkpoint, but has an incompatible shape with model variable. Checkpoint shape: [[1, 1, 256, 512]], model variable shape: [[3, 3, 256, 512]].

检查点中的形状,按照 this question & answer 进行解释,是 1x1 卷积(形状开头的 1,1)。您模型中的形状正确地是 3x3 卷积的形状。现在,这很奇怪,因为检查点中的图层名称​​具有“3x3”,尽管考虑到权重形状,这是错误的。

那么,您似乎正在使用一个检查点,该检查点对您遇到问题的层使用 1x1 卷积,尽管这些层的名称暗示是 3x3 卷积。作为使用现有检查点的解决方法,您可以尝试修改模型,修改构建模型的函数以使用 1x1 卷积(尽管我不能确定那会在哪里)。

由于 %mAP 较低,这当然是由于模型的一部分重新初始化且未正确加载。

关于python - 如何解决 "Variable is available in checkpoint, but has an incompatible shape with model variable"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54094981/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com