FailedPreconditionError:尝试使用未初始化的值Adam / lr

问题描述 投票:0回答:1

你好,我是机器学习的新手。我正在训练一个VGG16微调模型的过程。在第一个时期之后,程序停止并给出了这个错误:

Screenshot of the error on jupyter notebook

以下是我用于模型的代码:

# create a copy of a mobilenet model
import keras
vgg_model=keras.applications.vgg16.VGG16()

type(vgg_model)

vgg_model.summary()

from keras.models import Sequential
model = Sequential()
for layer in vgg_model.layers[:-1]:
    model.add(layer)

model.summary()

# CREATE THE MODEL ARCHITECTURE
from keras.layers import Dense, Activation, Dropout

model.add(Dropout(0.25))
model.add(Dense(7,activation='softmax'))

model.summary()

#Train the Model
# Define Top2 and Top3 Accuracy

from keras.metrics import categorical_accuracy, top_k_categorical_accuracy

def top_3_accuracy(y_true, y_pred):
    return top_k_categorical_accuracy(y_true, y_pred, k=3)

def top_2_accuracy(y_true, y_pred):
    return top_k_categorical_accuracy(y_true, y_pred, k=2)

from keras.optimizers import Adam
model.compile(Adam(lr=0.01), loss='categorical_crossentropy', 
              metrics=[categorical_accuracy, top_2_accuracy, top_3_accuracy])

# Get the labels that are associated with each index
print(valid_batches.class_indices)

# Add weights to try to make the model more sensitive to melanoma

class_weights={
    0: 1.0, # akiec
    1: 1.0, # bcc
    2: 1.0, # bkl
    3: 1.0, # df
    4: 3.0, # mel # Try to make the model more sensitive to Melanoma.
    5: 1.0, # nv
    6: 1.0, # vasc
}

filepath = "skin.h5"
checkpoint = ModelCheckpoint(filepath, monitor='val_top_3_accuracy', verbose=1, 
                             save_best_only=True, mode='max')

reduce_lr = ReduceLROnPlateau(monitor='val_top_3_accuracy', factor=0.5, patience=2, 
                                   verbose=1, mode='max', min_lr=0.00001)


callbacks_list = [checkpoint, reduce_lr]

history = model.fit_generator(train_batches, steps_per_epoch=train_steps, 
                              class_weight=class_weights,
                    validation_data=valid_batches,
                    validation_steps=val_steps,
                    epochs=40, verbose=1,
                   callbacks=callbacks_list)

我正在尝试学习如何在图像数据集上微调,训练和使用VGG16模型。我跟随这个blog,他使用mobileNet。

我正在关注这个VGG16 tutorial来编写模型的代码。

如果有人可以帮我修复此错误或解释它是如何发生的原因,我将非常感谢您的帮助。

非常感谢。

依赖关系:

  • 张量流1.12.0
  • tensorflow-gpu 1.12.0
  • python 3.6.0
  • 很难2.2.4
tensorflow keras training-data vgg-net finetunning
1个回答
1
投票

当我使用ReduceLROnPlateau回调时,我遇到了同样的错误。除非绝对必要,否则您可以省略其用法。

© www.soinside.com 2019 - 2024. All rights reserved.