gpt4 book ai didi

python - keras 预训练模型提供新的输入占位符

转载 作者:行者123 更新时间:2023-12-01 00:26:35 25 4
gpt4 key购买 nike

我有一个经过训练的模型。像这样

model_inceptionv3_conv = InceptionV3(weights='imagenet', include_top=False)
for layer in model_inceptionv3_conv.layers:
layer.trainable = False
x = model_inceptionv3_conv.output
x = GlobalAveragePooling2D()(x)
predictions = Dense(NB_CLASSES, activation='sigmoid', name='predictions')(x)
my_model = Model(inputs=model_inceptionv3_conv.input, outputs=predictions)
my_model.fit(...)

现在我不想为该模型提供占位符,但发生了某些值未初始化的情况。这段代码 preds = model(x) 会生成一个新图吗?

x = tf.placeholder(tf.float32, shape=(None, 299, 299,
3))
preds = model(x)
sess.run(preds, feed_dict={x: x_val})

错误FailedPreconditionError:尝试使用未初始化的值batch_normalization_86/moving_mean......

最佳答案

您的错误在这里:

preds = my_model(x)

应该是:

preds = my_model.predict(x)

这是一个工作示例:

NB_CLASSES = 2
model_inceptionv3_conv = InceptionV3(weights='imagenet', include_top=False)
for layer in model_inceptionv3_conv.layers:
layer.trainable = False
x = model_inceptionv3_conv.output
x = GlobalAveragePooling2D()(x)
predictions = Dense(NB_CLASSES, activation='softmax', name='predictions')(x)
my_model = Model(inputs=model_inceptionv3_conv.input, outputs=predictions)
test_img = np.random.rand(1,299,299,3)
preds = my_model.predict(test_img)

玩得开心!

关于python - keras 预训练模型提供新的输入占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58544272/

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