Python 带延迟的tensorflow初始化局部变量
我的数据库是一个嵌套的图像文件夹。我正在使用os.walk和slice input producer创建一个文件名队列,该队列将提供给整个文件读取器 代码在我的数据库的一小部分上运行良好(当爬行速度很快时)。但在整个过程中抛出“超出范围””错误。对于较大的数据库,可以通过将历元计数器设置为“无”来解决此问题 有没有方法初始化具有延迟/依赖关系的变量 下面是最简单的代码示例:Python 带延迟的tensorflow初始化局部变量,python,tensorflow,Python,Tensorflow,我的数据库是一个嵌套的图像文件夹。我正在使用os.walk和slice input producer创建一个文件名队列,该队列将提供给整个文件读取器 代码在我的数据库的一小部分上运行良好(当爬行速度很快时)。但在整个过程中抛出“超出范围””错误。对于较大的数据库,可以通过将历元计数器设置为“无”来解决此问题 有没有方法初始化具有延迟/依赖关系的变量 下面是最简单的代码示例: ligand_file_list,receptor_file_list = index_the_database(data
ligand_file_list,receptor_file_list = index_the_database(database_path)
ligand_files = tf.convert_to_tensor(ligand_file_list,dtype=tf.string)
receptor_files = tf.convert_to_tensor(receptor_file_list,dtype=tf.string)
filename_queue = tf.train.slice_input_producer([ligand_files,receptor_files],num_epochs=10,shuffle=True)
serialized_ligand = tf.read_file(filename_queue[0])
serialized_receptor = tf.read_file(filename_queue[1])
init_two = tf.initialize_all_variables()
init_one = tf.initialize_local_variables()
sess = tf.Session()
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess,coord=coord)
sess.run([init_one])
sess.run([init_two])
while True:
print sess.run([serialized_ligand,serialized_receptor])
您可以使用
time.sleep()
。您的tf.convert\u to\u tensor
调用将生成一个固定列表,因此在调用该列表之前,您需要确保您的文件列表是完整的function@YaroslavBulatov-感谢您提出的解决方案。我用tf.shape(ligand_文件)检查了文件名张量的动态形状。清单每次都是完整的。我得到的错误不同:失败的前提条件:尝试使用未初始化的值变量。。。class=[“loc:@Variable”]。如果我将tf.train.batch与多线程一起使用,问题往往会变得更糟(90%)。如果您将一个完全可复制的示例作为单独的问题发布,您可能会得到答案