本文整理汇总了Python中tensorflow.Records方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.Records方法的具体用法?Python tensorflow.Records怎么用?Python tensorflow.Records使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.Records方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_input_tensors
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Records [as 别名]
def get_input_tensors(batch_size, tf_records, num_repeats=None,
shuffle_records=True, shuffle_examples=True,
shuffle_buffer_size=None,
filter_amount=0.05):
'''Read tf.Records and prepare them for ingestion by dual_net. See
`read_tf_records` for parameter documentation.
Returns a dict of tensors (see return value of batch_parse_tf_example)
'''
if shuffle_buffer_size is None:
shuffle_buffer_size = SHUFFLE_BUFFER_SIZE
dataset = read_tf_records(batch_size, tf_records, num_repeats=num_repeats,
shuffle_records=shuffle_records,
shuffle_examples=shuffle_examples,
shuffle_buffer_size=shuffle_buffer_size,
filter_amount=filter_amount)
dataset = dataset.filter(lambda t: tf.equal(tf.shape(t)[0], batch_size))
dataset = dataset.map(functools.partial(
batch_parse_tf_example, batch_size))
return dataset.make_one_shot_iterator().get_next()
# End-to-end utility functions
示例2: check_data
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Records [as 别名]
def check_data(self, tfrecords_filename):
"""Checks a specified tf.Records file for coreect dataformat.
Check if the data format in the example files is correct. Prints the shape of the data
stored in a tf.Records file.
Args
tfrecords_filename: `str`, the path to the `tf.records` file to check.
"""
record_iterator = tf.python_io.tf_record_iterator(path=tfrecords_filename)
for string_record in record_iterator:
# Parse the next example
example = tf.train.Example()
example.ParseFromString(string_record)
# Get the features you stored (change to match your tfrecord writing code)
seq = (example.features.feature['seq_raw']
.bytes_list
.value[0])
label = (example.features.feature['label_raw']
.bytes_list
.value[0])
# Convert to a numpy array (change dtype to the datatype you stored)
seq_array = np.fromstring(seq, dtype=np.float64)
label_array = np.fromstring(label, dtype=np.float64)
# Print the image shape; does it match your expectations?
print(seq_array.shape)
print(label_array.shape)
示例3: get_input_tensors
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Records [as 别名]
def get_input_tensors(batch_size, feature_layout, tf_records, num_repeats=1,
shuffle_records=True, shuffle_examples=True,
shuffle_buffer_size=None,
filter_amount=0.05, random_rotation=True):
"""Read tf.Records and prepare them for ingestion by dual_net.
See `read_tf_records` for parameter documentation.
Returns a dict of tensors (see return value of batch_parse_tf_example)
"""
print("Reading tf_records from {} inputs".format(len(tf_records)))
dataset = read_tf_records(
batch_size,
tf_records,
num_repeats=num_repeats,
shuffle_records=shuffle_records,
shuffle_examples=shuffle_examples,
shuffle_buffer_size=shuffle_buffer_size,
filter_amount=filter_amount,
interleave=False)
dataset = dataset.filter(lambda t: tf.equal(tf.shape(t)[0], batch_size))
dataset = dataset.map(
functools.partial(batch_parse_tf_example, batch_size, feature_layout))
if random_rotation:
# Unbatch the dataset so we can rotate it
dataset = dataset.apply(tf.data.experimental.unbatch())
dataset = dataset.apply(tf.data.experimental.map_and_batch(
functools.partial(_random_rotation, feature_layout),
batch_size))
return dataset.make_one_shot_iterator().get_next()