Я пытаюсь перезагрузить две предварительно обученные модели и настроить их в соответствии с общей целью.
Я загружаю две предварительно обученные модели:
with tf.Session(graph=graph_shape) as sess_shape:
# restore the latest model
file_list = os.listdir('ShapePrior/model/')
file_list.sort(key=lambda x: x)
loader = tf.train.import_meta_graph('ShapePrior/model/%s/shape.meta' % file_list[-2])
sess_shape.run(tf.group(tf.global_variables_initializer(), tf.local_variables_initializer()))
loader.restore(sess_shape, tf.train.latest_checkpoint('ShapePrior/model/%s' % file_list[-2]))
graph_pose = tf.Graph()
with tf.Session(graph=graph_pose) as sess_pose:
# restore the latest model
file_list = os.listdir('PosePrior/model/')
file_list.sort(key=lambda x: x)
loader = tf.train.import_meta_graph('PosePrior/model/%s/pose.meta' % file_list[-2])
sess_pose.run(tf.group(tf.global_variables_initializer(), tf.local_variables_initializer()))
loader.restore(sess_pose, tf.train.latest_checkpoint('PosePrior/model/%s' % file_list[-2]))
Затем я объединяю их и определяю новую сеть:
graph_prior = tf.get_default_graph()
with tf.Session(graph=graph_prior, config=config) as sess_prior:
with tf.variable_scope(name_or_scope='prior_init'):
training = tf.placeholder(tf.bool, name='training')
shape_input = tf.placeholder(tf.float32, [None, 64, 64, 1], name='shape_input')
pose_input = tf.placeholder(tf.float32, [None, 3, 14], name='pose_input')
beta = tf.placeholder(tf.float32, [None, 10], name='beta')
theta = tf.placeholder(tf.float32, [None, 72], name='theta')
with tf.variable_scope(name_or_scope='prior_network'):
beta_output = tf.import_graph_def(graph_shape.as_graph_def(),
input_map={'shape_prior_init/input:0': shape_input,
'shape_prior_init/training:0': training,
'shape_prior_init/beta:0': beta},
return_elements=['shape_prior_network/beta_output/MatMul:0'],
name='beta_output')
theta_output = tf.import_graph_def(graph_pose.as_graph_def(),
input_map={'pose_prior_init/input:0': pose_input,
'pose_prior_init/training:0': training,
'pose_prior_init/theta:0': theta},
return_elements=['pose_prior_network/theta_output/MatMul:0'],
name='theta_output')
Этот шаг хочет получить выходные данные двух моделей.
Затем я определяю оптимизатор на основе выводов моделей:
with tf.variable_scope(name_or_scope='prior_optimizer'):
beta_gt = tf.placeholder(tf.float32, [self.batch_size, 10])
theta_gt = tf.placeholder(tf.float32, [self.batch_size, 72])
beta_loss = tf.reduce_mean(tf.reduce_sum(tf.square(beta_output - beta_gt), axis=1),
name='theta_loss')
theta_loss = tf.reduce_mean(tf.reduce_sum(tf.square(theta_output - theta_gt), axis=1),
name='theta_loss')
# loss function
total_loss = beta_loss + theta_loss
# optimizer
update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
with tf.control_dependencies(update_ops):
train_ops = tf.train.AdamOptimizer(learning_rate=self.learning_rate).minimize(total_loss)
После этого я начинаю тренироваться:
for i in range(self.iterations):
print(i)
_, _silhouette, _keypoint, _theta, _beta = sess_prior.run(data)
_keypoint = Prior.generate_keypoint(_keypoint)
_, loss = sess_prior.run([train_ops, total_loss],
feed_dict={training: True,
shape_input: _silhouette, beta_gt: _beta,
pose_input: _keypoint, theta_gt: _theta})
но я получаю ошибку: ValueError: Нет переменных для оптимизации.
Я хочу несколько предложений, спасибо ~