Python TensorFlow:创建图的近似副本作为原始图的扩展来测试验证数据集会消耗大量内存吗?
意思是说,如果我最初在图表中有以下用于培训目的的操作:Python TensorFlow:创建图的近似副本作为原始图的扩展来测试验证数据集会消耗大量内存吗?,python,machine-learning,tensorflow,computer-vision,deep-learning,Python,Machine Learning,Tensorflow,Computer Vision,Deep Learning,意思是说,如果我最初在图表中有以下用于培训目的的操作: with tf.Graph.as_default() as g: images, labels = load_batch(...) with slim.argscope(...): logits, end_points = inceptionResnetV2(images, num_classes..., is_training = True) loss = slim.losses.softmax_cross_entr
with tf.Graph.as_default() as g:
images, labels = load_batch(...)
with slim.argscope(...):
logits, end_points = inceptionResnetV2(images, num_classes..., is_training = True)
loss = slim.losses.softmax_cross_entropy(logits, labels)
optimizer = tf.train.AdamOptimizer(learning_rate = 0.002)
train_op = slim.learning.create_train_op(loss, optimizer)
sv = tf.train.Supervisor(...)
with sv.managed_session() as sess:
#perform your regular training loop here with sess.run(train_op)
这使我可以很好地训练我的模型,但我想在我的sess
中每隔一段时间运行一个小的验证数据集来评估我的模型,在同一个图中消耗一个几乎完全相同的副本会不会占用太多内存,如:
images_val, labels_val = load_batch(...)
with slim.argscope(...):
logits_val, end_points_val = inceptionResnetV2(images, num_classes..., is_training = False)
predictions = end_points_val['Predictions']
acc, acc_updates = tf.contrib.metrics.streaming_accuracy(predictions, labels_val)
#and then following this, we can run acc_updates in a session to update the accuracy, which we can then print to monitor
我担心的是,为了评估我的验证数据集,我需要将is\u training
参数设置为False
,以便禁用退出。但是,仅仅为了在同一个图中进行验证而从头开始创建一个完整的inception-resnet-v2模型会消耗太多内存吗?或者我应该创建一个全新的文件,自己运行验证
理想情况下,我希望有3种数据集——一个培训数据集、一个在培训期间测试的小型验证数据集和一个最终评估数据集。这个小的验证数据集将帮助我查看我的模型是否与训练数据过度拟合。但是,如果我提出的想法消耗了太多内存,是否就相当于偶尔监视训练数据分数?有没有更好的办法在培训时测试验证集?TensorFlow的开发人员考虑过这一点,并准备好共享变量。 你可以看到 正确使用作用域可以重用某些变量。 一个很好的例子是(上下文是语言模型,但没关系) 这种方法的全局伪代码类似于:
class Model:
def __init__(self, train=True, params):
""" Build the model """
tf.placeholder( ... )
tf.get_variable( ...)
def main(_):
with tf.Graph.as_default() as g:
with tf.name_scope("Train"):
with tf.variable_scope("Model", reuse=None):
train = Model(train=True, params )
with tf.name_scope("Valid"):
# Now reuse variables = no memory cost
with tf.variable_scope("Model", reuse=True):
# But you can set different parameters
valid = Model(train=False, params)
session = tf.Session
...
因此,您可以共享一些变量,而无需使用完全相同的模型,因为参数可能会更改模型本身
希望这有帮助pltrdy
这个问题解决了吗?