gpt4 book ai didi

python - 使用 imagenet 权重从头开始进行 Keras tensorflow 训练

转载 作者:太空宇宙 更新时间:2023-11-03 14:09:37 25 4
gpt4 key购买 nike

我正在尝试使用inception_resnet_v2来训练我自己的人体姿势估计模型。这是一个回归问题,我需要在顶部有一个完全连接的层而不需要激活函数,因此标准 API 不适合我的情况。

下面的代码工作正常,但我担心 session.run(init) 会将权重重置为随机,而不是使用 imagenet

还有出路吗?如果我删除 session 初始化,它会引发错误。

def inception_resnet_v2():

model = InceptionResNetV2(include_top=False,
weights='imagenet',
input_shape=(FLAGS.resize_input_image,
FLAGS.resize_input_image, 3))
x = model.output
x = Flatten()(x)
x = Dense(28, activation=None, name='predictions')(x)
model = Model(input=model.input, output=x)

print(model.summary())

return model

model = inception_resnet_v2()
network = model(images)

_, mean_loss = regression_loss.loss_func(joints_gt, is_valid_joint, network)
train_op = optimizer.rms_prop(mean_loss=mean_loss, global_step=global_step)

init = tf.group(tf.global_variables_initializer(),
tf.local_variables_initializer())

with tf.Session(config=config) as sess:

# Initialize variables
sess.run(init)

最佳答案

答案很简单,保存模型并在初始化变量后重新加载它。

    def inception_resnet_v2():

model = InceptionResNetV2(include_top=False,
weights='imagenet',
input_shape=(FLAGS.resize_input_image,
FLAGS.resize_input_image, 3))
x = model.output
x = Flatten()(x)
x = Dense(28, activation=None, name='predictions')(x)
model = Model(input=model.input, output=x)

print(model.summary())

return model

model = inception_resnet_v2()
**model.save('mymodel.h5')**
network = model(images)

_, mean_loss = regression_loss.loss_func(joints_gt, is_valid_joint, network)
train_op = optimizer.rms_prop(mean_loss=mean_loss, global_step=global_step)

init = tf.group(tf.global_variables_initializer(),
tf.local_variables_initializer())

with tf.Session(config=config) as sess:

# Initialize variables
sess.run(init)
**model.load('mymodel.h5')**

关于python - 使用 imagenet 权重从头开始进行 Keras tensorflow 训练,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48598402/

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