gpt4 book ai didi

python - 对 im2txt 微调 inception v3 时损失并没有减少

转载 作者:行者123 更新时间:2023-11-30 09:50:11 25 4
gpt4 key购买 nike

我在微调 im2txt 的预训练 Inception v3 模型时遇到问题。由于某种原因,初始训练并没有减少太多损失,并且微调 Inception v3 也没有减少我的训练数据的任何损失。我正在尝试找出原因,任何见解都会有所帮助。

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

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

lady shopping clothes

我的标签标题如下所示:

 female lady woman clothes shop customer

我总共有 400,000 张图像和相应的标签说明。我初始训练了13万步,微调了17万步。词汇共有750个单词。初始训练+微调的损失曲线(从步骤 130,000 开始)如下: enter image description here

准确率和召回率约为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

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

最佳答案

请注意,im2txt 的功能非常强大,因为它可以生成可读的句子。在句子中,一个单词与相邻的单词相关,这就是它起作用的原因。在您的情况下,您正在更改模型以生成一组顺序不相关的标签。实际上,在im2txt模型中,单词“female”、“woman”和“lady”基本上是相同的概念,im2txt可以创建滑动这些单词的句子。例如,在im2txt中:“这位女士穿着一条漂亮的粉红色裙子”与“这位女士的裙子是粉红色的”相同,或者应该非常相似。在你的情况下,如果你不提供一些单词顺序规则,它会让你的模型变得很困惑,并且可能无法学习。

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

关于python - 对 im2txt 微调 inception v3 时损失并没有减少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46637864/

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