我目前将超参数保存为集合中的tf.constant
:s,但要阅读它们,我必须对它们进行评估(例如sess.run
)。是否有更好的方法可以将固定超参数包含在TensorFlow模型中,与TensorFlow服务,Google Cloud等兼容?
这就是我现在用图表保存超参数的方法:
hyperparameters = {'foo': foo,
'bar': bar}
for k, v in hyperparameters.items():
tf.add_to_collection('CONSTANTS', tf.constant(value=v, name=k))
后来当我想从保存的图表中读取超参数时:
sess.run(tf.global_variables_initializer())
hyperparameters = {}
for c in tf.get_collection('CONSTANTS'):
hyperparameters[c.op.name] = c.eval()