我有一个从 tfrecords 读取的三联图像数据集,我已使用以下代码将其转换为数据集
def parse_dataset(record):
def convert_raw_to_image_tensor(raw):
raw = tf.io.decode_base64(raw)
image_shape = tf.stack([299, 299, 3])
decoded = tf.io.decode_image(raw, channels=3,
dtype=tf.uint8, expand_animations=False)
decoded = tf.cast(decoded, tf.float32)
decoded = tf.reshape(decoded, image_shape)
decoded = tf.math.divide(decoded, 255.)
return decoded
features = {
'n': tf.io.FixedLenFeature([], tf.string),
'p': tf.io.FixedLenFeature([], tf.string),
'q': tf.io.FixedLenFeature([], tf.string)
}
sample = tf.io.parse_single_example(record, features)
neg_image = sample['n']
pos_image = sample['p']
query_image = sample['q']
neg_decoded = convert_raw_to_image_tensor(neg_image)
pos_decoded = convert_raw_to_image_tensor(pos_image)
query_decoded = convert_raw_to_image_tensor(query_image)
return (neg_decoded, pos_decoded, query_decoded)
record_dataset = tf.data.TFRecordDataset(filenames=path_dataset, num_parallel_reads=4)
record_dataset = …Run Code Online (Sandbox Code Playgroud) 我希望能够获得给出昵称的人的名字(所有昵称都是唯一的).一个人可以有多个昵称.我正在考虑使用如下字典
nicknames = {
'lebron james': ['king james', 'lbj'],
'dwayne johnson': ['rocky', 'the rock', 'brahma bull']
}
Run Code Online (Sandbox Code Playgroud)
所以例如,给定一个字符串'rocky',我希望能够返回'dwayne johnson'.这种数据结构是存储名称=>昵称配对的最佳方式吗?或者是否有更好的方法来存储数据以提高搜索效率?