【问题标题】:Warning: variable is not available in checkpoint警告:变量在检查点中不可用
【发布时间】:2019-03-15 07:33:07
【问题描述】:

我正在为 MobileNetV1 训练 FasterRCNN。

This model zoos 没有针对 MobileNetV1 的 FasterRCNN 的预训练模型。

所以我使用了来自here 的预训练模型。

但我有错误,因为变量在检查点中不可用。 相当多的警告,我展示了其中的一些。 这些是警告,但在没有预训练权重的情况下仍然可以继续训练。

我的问题是为什么我不能使用 FasterRCNN 的这些预训练权重。

在这个tutorial中,中间提到的是"We typically initialize the weights of this feature extractor using those from the Slim Resnet-101 classification checkpoint, and we know that images were preprocessed when training this checkpoint by subtracting a channel mean from each input image. Thus, we implement the preprocess function to replicate the same channel mean subtraction behavior."

为什么我不能使用这些权重?

我在配置文件中加载预训练模型

fine_tune_checkpoint: "object_detection/data/mobilenet_v1_1.0_224/mobilenet_v1_1.0_224.ckpt"
from_detection_checkpoint: true

警告是

WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_0/BatchNorm/beta] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_0/BatchNorm/gamma] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_0/BatchNorm/moving_mean] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_0/BatchNorm/moving_variance] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_0/weights] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_10_depthwise/BatchNorm/beta] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_10_depthwise/BatchNorm/gamma] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_10_depthwise/BatchNorm/moving_mean] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_10_depthwise/BatchNorm/moving_variance] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_10_depthwise/depthwise_weights] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_10_pointwise/BatchNorm/beta] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_10_pointwise/BatchNorm/gamma] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_10_pointwise/BatchNorm/moving_mean] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_10_pointwise/BatchNorm/moving_variance] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_10_pointwise/weights] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_11_depthwise/BatchNorm/beta] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_11_depthwise/BatchNorm/gamma] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_11_depthwise/BatchNorm/moving_mean] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_11_depthwise/BatchNorm/moving_variance] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_11_depthwise/depthwise_weights] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_11_pointwise/BatchNorm/beta] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_11_pointwise/BatchNorm/gamma] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_11_pointwise/BatchNorm/moving_mean] is not available in checkpoint
WARNING:root:Variable [FirstStageFeatureExtractor/MobilenetV1/Conv2d_11_pointwise/BatchNorm/moving_variance] is not available in checkpoint

【问题讨论】:

  • 来自提供链接的 Tensorflow repo 的模型使用 tf.contrib.framework.arg_scope 来定义 batchnorm。你试过用tf.train.list_variables(ckpt)检查检查点文件吗?
  • 如何查看?我是 TensorFlow 的新手。
  • 两个参数被称为--checkpoint_exclude_scopes=InceptionV3/Logits,InceptionV3/AuxLogits和--trainable_scopes=InceptionV3/Logits,InceptionV3/AuxLogits。他们将排除负载重量并仅在这些层上进行训练。那是为了分类。但是对于检测,没有这样的参数输入。这是我们可以找到对象检测参数的链接(github.com/tensorflow/models/blob/master/research/…)
  • tf.train.list_variables 返回检查点中所有变量的列表。它不需要在会话中运行。然后您可以决定要加载哪些变量。看看kwotsin.github.io/tech/2017/02/11/transfer-learning.html

标签: python tensorflow object-detection-api


【解决方案1】:

是的,可以使用来自here 的预训练模型。可以从 variable_names_map 检查初始化需要哪些变量以及加载的检查点可以使用哪些变量。从那里,选择变量并初始化以进一步微调。

需要对 Tensorflow 的代码进行一些修改,主要在 utils/variables_helper.py 文件中。

FasterRCNN 的 FirstStage 和 SecondStage 中的内容由 faster_rcnn_mobilenet_v1_feature_extractor.py 决定

【讨论】:

    猜你喜欢
    • 2020-05-31
    • 2022-01-22
    • 2017-07-12
    • 2022-07-26
    • 1970-01-01
    • 2022-12-09
    • 2011-10-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多