Python 微调IM2Text的初始v3时,损失不会减少

Python 微调IM2Text的初始v3时,损失不会减少,python,image,machine-learning,tensorflow,Python,Image,Machine Learning,Tensorflow,我有一个问题,需要对预先训练好的Inception v3模型进行微调。出于某种原因,初始培训并没有大大减少损失,而微调Inception v3并没有减少我的培训数据的任何损失。我正试图找出原因,任何见解都会有所帮助 IM2Text是一个模型,它接收图像的输入并打印出标题列表作为输出。最初,IM2Text将标题打印为连贯的句子,描述图像。为了适应我的项目,我更改了训练数据中的代码和标签,以便它打印出与图像相关的单词列表 例如,我的图像看起来像这样。请注意,图像中的对象比平均Imagenet图像中的

我有一个问题,需要对预先训练好的Inception v3模型进行微调。出于某种原因,初始培训并没有大大减少损失,而微调Inception v3并没有减少我的培训数据的任何损失。我正试图找出原因,任何见解都会有所帮助

IM2Text是一个模型,它接收图像的输入并打印出标题列表作为输出。最初,IM2Text将标题打印为连贯的句子,描述图像。为了适应我的项目,我更改了训练数据中的代码和标签,以便它打印出与图像相关的单词列表

例如,我的图像看起来像这样。请注意,图像中的对象比平均Imagenet图像中的对象多:

我的标签标题如下所示:

 female lady woman clothes shop customer
我总共有400000张图片和相应的标签说明。我进行了130000步的初始训练,并对170000步进行了微调。词汇表中总共有750个单词。初始训练+微调(从步骤130000开始)的损耗曲线如下:

准确率和召回率在0.35~40之间

培训的配置文件如下:

# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

"""Image-to-text model and training configurations."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


class ModelConfig(object):
  """Wrapper class for model hyperparameters."""

  def __init__(self):
    """Sets the default model hyperparameters."""
    # File pattern of sharded TFRecord file containing SequenceExample protos.
    # Must be provided in training and evaluation modes.
    self.input_file_pattern = None

    # Image format ("jpeg" or "png").
    self.image_format = "jpeg"

    # Approximate number of values per input shard. Used to ensure sufficient
    # mixing between shards in training.
    self.values_per_input_shard = 2300
    # Minimum number of shards to keep in the input queue.
    self.input_queue_capacity_factor = 2
    # Number of threads for prefetching SequenceExample protos.
    self.num_input_reader_threads = 1

    # Name of the SequenceExample context feature containing image data.
    self.image_feature_name = "image/data"
    # Name of the SequenceExample feature list containing integer captions.
    self.caption_feature_name = "image/caption_ids"

    # Number of unique words in the vocab (plus 1, for <UNK>).
    # The default value is larger than the expected actual vocab size to allow
    # for differences between tokenizer versions used in preprocessing. There is
    # no harm in using a value greater than the actual vocab size, but using a
    # value less than the actual vocab size will result in an error.
    self.vocab_size = 750

    # Number of threads for image preprocessing. Should be a multiple of 2.
    self.num_preprocess_threads = 4

    # Batch size.
    self.batch_size = 32

    # File containing an Inception v3 checkpoint to initialize the variables
    # of the Inception model. Must be provided when starting training for the
    # first time.
    self.inception_checkpoint_file = None

    # Dimensions of Inception v3 input images.
    self.image_height = 299
    self.image_width = 299

    # Scale used to initialize model variables.
    self.initializer_scale = 0.08

    # LSTM input and output dimensionality, respectively.
    self.embedding_size = 512
    self.num_lstm_units = 512

    # If < 1.0, the dropout keep probability applied to LSTM variables.
    self.lstm_dropout_keep_prob = 0.7


class TrainingConfig(object):
  """Wrapper class for training hyperparameters."""

  def __init__(self):
    """Sets the default training hyperparameters."""
    # Number of examples per epoch of training data.
    self.num_examples_per_epoch = 100000

    # Optimizer for training the model.
    self.optimizer = "SGD"

    # Learning rate for the initial phase of training.
    self.initial_learning_rate = 2.0
    self.learning_rate_decay_factor = 0.5
    self.num_epochs_per_decay = 1.0

    # Learning rate when fine tuning the Inception v3 parameters.
    self.train_inception_learning_rate = 0.005

    # If not None, clip gradients to this value.
    self.clip_gradients = 5.0

    # How many model checkpoints to keep.
    self.max_checkpoints_to_keep = 5
#TensorFlow作者版权所有2016。版权所有。
#
#根据Apache许可证2.0版(以下简称“许可证”)获得许可;
#除非遵守许可证,否则不得使用此文件。
#您可以通过以下方式获得许可证副本:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#除非适用法律要求或书面同意,软件
#根据许可证进行的分发是按“原样”进行分发的,
#无任何明示或暗示的保证或条件。
#请参阅许可证以了解管理权限和权限的特定语言
#许可证下的限制。
# ==============================================================================
“”“图像到文本模型和培训配置。”“”
从未来导入绝对导入
来自未来进口部
来自未来导入打印功能
类ModelConfig(对象):
“”“模型超参数的包装类。”“”
定义初始化(自):
“”“设置默认的模型超参数。”“”
#包含SequenceExample protos的分片TFRecord文件的文件模式。
#必须以培训和评估模式提供。
self.input\u file\u pattern=None
#图像格式(“jpeg”或“png”)。
self.image\u format=“jpeg”
#每个输入碎片的近似值数。用于确保足够的
#在训练中混合碎片。
self.values\u per\u input\u shard=2300
#输入队列中要保留的最小碎片数。
self.input\u queue\u capacity\u factor=2
#预取序列示例protos的线程数。
self.num\u input\u reader\u threads=1
#包含图像数据的SequenceExample上下文功能的名称。
self.image\u feature\u name=“图像/数据”
#包含整数标题的SequenceExample功能列表的名称。
self.caption\u feature\u name=“image/caption\u id”
#词汇表中唯一的单词数(加1表示)。
#默认值大于允许的预期实际vocab大小
#查看预处理中使用的标记器版本之间的差异。有
#使用大于实际vocab大小的值没有害处,但使用
#值小于实际vocab大小将导致错误。
self.vocab_size=750
#用于图像预处理的线程数。应该是2的倍数。
self.num_预处理_线程=4
#批量大小。
self.batch_size=32
#包含初始化变量的初始v3检查点的文件
#对初始模型的分析。必须在开始培训时提供
#第一次。
self.inception\u checkpoint\u file=None
#输入图像的尺寸。
self.image_height=299
self.image_width=299
#用于初始化模型变量的比例。
self.initializer_scale=0.08
#LSTM输入和输出维度分别为。
self.u size=512
self.num\lstm\u单位=512
#如果<1.0,则退出概率适用于LSTM变量。
self.lstm\u辍学\u保持\u概率=0.7
类TrainingConfig(对象):
“”“用于训练超参数的包装类。”“”
定义初始化(自):
“”“设置默认的训练超参数。”“”
#每个历元训练数据的示例数。
self.num\u每个历元的示例数=100000
#用于训练模型的优化器。
self.optimizer=“SGD”
#培训初始阶段的学习率。
自我初始学习率=2.0
自学习率衰减系数=0.5
self.num\u epochs\u per\u decation=1.0
#微调初始v3参数时的学习率。
自我培训开始学习率=0.005
#如果不是“无”,则将渐变剪裁到此值。
self.clip_梯度=5.0
#要保留多少个模型检查点。
self.max\u checkpoints\u to\u keep=5

任何建议、见解或观察都会很好。

请注意,im2text非常强大,因为它可以生成可读的句子。在句子中,一个单词与相邻的单词相关,这就是它起作用的原因。在本例中,您正在更改模型以生成一组顺序不相关的标签。实际上,在IM2Text模型中,“女性”、“女性”和“女士”这三个词基本上是相同的概念,IM2Text可以用这些词造句。例如,在im2text中,“女士穿着漂亮的粉红色裙子”与“女士的裙子是粉红色的”相同,或者应该非常相似。在你的情况下,如果你不提供一些规则的顺序的话,它将混淆很多你的模型,可能无法学习

如果要从图像中获取标签列表,应仅使用具有多标签分类的初始模型(将softmax层更改为sigmoid层,并使用sigmoid交叉熵作为损失函数)。