我已经生成了不同的Tfrecords文件。我试图读取它们,并把它们放在一个共同的文件与扩展名tfrecord。
我尝试生成的代码如下:
import tensorflow as tf
files_dir = '/C:/Users/RAQUEL/Dropbox/code/code/tf_records'
output_file='/C:/Users/RAQUEL/Dropbox/code/code/tf_examples.tfrecord'
content = os.listdir(files_dir)
writer=tf.python_io.TFRecordWriter(output_file)
writer_index=0
for tf_record in content:
#Read file
filename_queue = tf.train.string_input_producer(
[tf_record], shuffle=True)
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
#Write output file
writer[writer_index].write(serialized_example)
writer_index = (writer_index + 1)
writer.close()
回溯:
Traceback (most recent call last):
File "/content/gdrive/MyDrive/colabnotebooks/Bert_COpenMed/Juntar_tf.py", line 26, in <module>
writer[writer_index].write(serialized_example)
TypeError: 'TFRecordWriter' object is not subscriptable
'TFRecordWriter'
对象不可下标。所以writer[writer_index]
不工作
我猜你需要使用writer.write(serialized_example)
之类的东西。