グラフの反映・リセットとはどういう意味なのでしょうか?
今本を読んでTensorFlowの勉強をしています。
その中で、
同じプロセスで複数回import_graph_defを実行しても2度目からはグラフが反映されません。そのため、tf.reset_default_graph()を実行してグラフをリセットしています。
という文が出てきました。
ここで出てくるグラフの反映・リセットとはどのような意味なのでしょうか?
グラフの反映=グラフの保存なのかなとは思いましたが....。
リセットはグラフが持っているデータの消去ということでしょうか...?
グラフは上記の図のことで、
なのでグラフの反映という意味が余計にわかりません。
コード全体は
# coding: utf-8 from __future__ import absolute_import from __future__ import division from __future__ import print_function import glob import tensorflow as tf from reader import Cifar10Reader import numpy as np FLAGS = tf.app.flags.FLAGS tf.app.flags.DEFINE_string('graph_dir',None,"処理するグラフファイルのあるパス") tf.app.flags.DEFINE_string('test_data','./data/test_batch.bin',"テストデータのパス") def eval(graph_file): tf.reset_default_graph() with tf.gfile.FastGFile(graph_file,'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) _=tf.import_graph_def(graph_def,name='') labels = tf.placeholder(tf.int32,shape=[1],name='label') logits = tf.get_default_graph().get_tensor_by_name('output/logits:0') top_k_op = tf.nn.in_top_k(logits,labels,1) with tf.Session() as sess: image_reader = Cifar10Reader(FLAGS.test_data) true_count = 0 for index in range(0,10000): image = image_reader.read(index) predictions = sess.run( top_k_op, feed_dict={ 'input_image:0':image.image, labels:image.label,} ) true_count +=np.sum(predictions) print('%s,%.2f'%(graph_file,(true_count/10000.0))) image_reader.close() if __name__ == '__main__': file_list = glob.glob(FLAGS.graph_dir+'/*.pb') for file in file_list: eval(file)
で、
疑問に思っている箇所は
with tf.Session() as sess: image_reader = Cifar10Reader(FLAGS.test_data) true_count = 0 for index in range(0,10000): image = image_reader.read(index) predictions = sess.run( top_k_op, feed_dict={ 'input_image:0':image.image, labels:image.label,} ) true_count +=np.sum(predictions) print('%s,%.2f'%(graph_file,(true_count/10000.0))) image_reader.close()
この部分です。
回答1件
あなたの回答
tips
プレビュー