每个 tfrecord 中的示例数
Number of examples in each tfrecord
运行 Google Cloud Shell 中的 sample.sh 脚本按照花示例的步骤对图像集调用以下预处理。
https://github.com/GoogleCloudPlatform/cloudml-samples/blob/master/flowers/trainer/preprocess.py
在评估集和训练集上都成功进行了预处理。但是生成的 .tfrecord.gz 文件似乎与 eval/train_set.csv.
中的图像编号不匹配
即eval-00000-of-00157.tfrecord.gz 表示有 158 个 tfrecord,而 eval_set.csv 中有 35227 行。每条记录都包含一个有效的image_url(所有记录都上传到存储),每条记录都有有效的标签标记。
想知道在 preproces.py 配置中是否有一种方法可以监视和控制每个 tfrecord 的图像数量。
谢谢
更新,正确完成这项工作:
import tensorflow as tf
import os
from tensorflow.python.lib.io import file_io
options = tf.python_io.TFRecordOptions(
compression_type=tf.python_io.TFRecordCompressionType.GZIP)
sum(1 for f in file_io.get_matching_files(os.path.join(url/path, '*.tfrecord.gz'))
for example in tf.python_io.tf_record_iterator(f, options=options))
文件名eval-00000-of-00157.tfrecord.gz
表示这是158个文件中的第一个文件。应该有157个名称相似的文件。在每个文件中,可以有任意数量的记录。
如果您想手动计算每条记录,请尝试以下方法:
import tensorflow as tf
from tensorflow.python.lib.io import file_io
files = os.path.join('gs://my_bucket/my_dir', 'eval-*.tfrecord.gz')
print(sum(1 for f in tf.python_io.file_io.get_matching_files(files)
for tf.python_io.tf_record_iterator(f)))
请注意,Dataflow 不保证输入文件和输出文件之间的文件数量和记录顺序(文件间和文件内)之间的关系。但是,计数应该是相同的。
运行 Google Cloud Shell 中的 sample.sh 脚本按照花示例的步骤对图像集调用以下预处理。
https://github.com/GoogleCloudPlatform/cloudml-samples/blob/master/flowers/trainer/preprocess.py
在评估集和训练集上都成功进行了预处理。但是生成的 .tfrecord.gz 文件似乎与 eval/train_set.csv.
中的图像编号不匹配即eval-00000-of-00157.tfrecord.gz 表示有 158 个 tfrecord,而 eval_set.csv 中有 35227 行。每条记录都包含一个有效的image_url(所有记录都上传到存储),每条记录都有有效的标签标记。
想知道在 preproces.py 配置中是否有一种方法可以监视和控制每个 tfrecord 的图像数量。
谢谢
更新,正确完成这项工作:
import tensorflow as tf
import os
from tensorflow.python.lib.io import file_io
options = tf.python_io.TFRecordOptions(
compression_type=tf.python_io.TFRecordCompressionType.GZIP)
sum(1 for f in file_io.get_matching_files(os.path.join(url/path, '*.tfrecord.gz'))
for example in tf.python_io.tf_record_iterator(f, options=options))
文件名eval-00000-of-00157.tfrecord.gz
表示这是158个文件中的第一个文件。应该有157个名称相似的文件。在每个文件中,可以有任意数量的记录。
如果您想手动计算每条记录,请尝试以下方法:
import tensorflow as tf
from tensorflow.python.lib.io import file_io
files = os.path.join('gs://my_bucket/my_dir', 'eval-*.tfrecord.gz')
print(sum(1 for f in tf.python_io.file_io.get_matching_files(files)
for tf.python_io.tf_record_iterator(f)))
请注意,Dataflow 不保证输入文件和输出文件之间的文件数量和记录顺序(文件间和文件内)之间的关系。但是,计数应该是相同的。