在保持张量流会话打开的同时,实时更新文件列表的正确方法是什么?
我知道tf.train.match_filenames_once()
函数名称中的import tensorflow as tf
pattern = '/tmp/test_file_*'
filenames = tf.train.match_filenames_once(pattern)
# Create some files
for i in range(3):
with open(f'/tmp/test_file_old_{i}', 'w'):
pass
# Open session and initialize vars
init_op = tf.local_variables_initializer()
sess = tf.Session()
sess.run(init_op)
# Read filenames list before adding new files
filenames_result_1 = sess.run(filenames)
print('First filenames list:')
print(filenames_result_1)
# Create some new files
for i in range(3):
with open(f'/tmp/test_file_new_{i}', 'w'):
pass
# Read filenames list after adding new files
filenames_result_2 = sess.run(filenames)
print('Second filenames list:')
print(filenames_result_2)
# Trying to reinitialize the contents
sess.run(init_op)
filenames_result_3 = sess.run(filenames)
print('Third filenames list:')
print(filenames_result_3)
一词,但找不到其他选项。这是一个片段,展示了我要做的事情:
First filenames list:
[b'/tmp/test_file_old_1' b'/tmp/test_file_old_0' b'/tmp/test_file_old_2']
Second filenames list:
[b'/tmp/test_file_old_1' b'/tmp/test_file_old_0' b'/tmp/test_file_old_2']
Third filenames list:
[b'/tmp/test_file_old_1' b'/tmp/test_file_old_0' b'/tmp/test_file_old_2']
输出:
dial tcp: lookup databaseserverdomain.com on 0.0.0.0:53: server misbehaving
我本来希望获取最新的文件列表。