【发布时间】:2021-11-21 20:57:14
【问题描述】:
我查看了 CIFAR-100 内置数据集的源代码,并决定为 FairFace 数据集创建一个兼容版本,以便在我将 FairFace 转换为结构后,无需在任何地方进行大量修改即可利用其他内置函数与 CIFAR-100 非常相似。
我进行了搜索,但无法找到 CIFAR-100 SQLite 数据库是如何创建的 - 特别是图像如何转换为 BLOB 进行存储。经过一番反复试验,我尝试这样做:
sample = getDatabyIndex(train_labels, index)
example = tf.train.Example(features=tf.train.Features(feature={
'image' : bytes_feature(sample[0].tobytes()),
'label' : int64_feature(sample[1])
}))
example = example.SerializeToString()
cur.execute("insert into examples('split_name','client_id','serialized_example_proto') values(?,?,?)", ('train', i, sqlite3.Binary(example)))
对训练数据中的每个样本执行此操作,对测试数据执行类似操作。我可以使用这种解码方法来加载它:
def parse_proto(tensor_proto):
parse_spec = {
'image': tf.io.FixedLenFeature(shape=(), dtype=tf.string),
'label': tf.io.FixedLenFeature(shape=(), dtype=tf.int64),
}
decoded_example = tf.io.parse_example(tensor_proto, parse_spec)
return collections.OrderedDict(
image=tf.reshape(tf.io.decode_raw(decoded_example['image'], tf.uint8), (224,224,3)),
label=decoded_example['label'])
然而,我注意到,最终的 sqlite.lzma 压缩存档大小为 6.4 GB,而数据集的源存档大小为 555 MB。我猜测由于我存储图像的方式,如果它们以更兼容的方式存储,压缩效果不会很好。我从 CIFAR-100 代码中看到,图像直接加载为形状为 (32,32,3) 的 FixedLenFeatures,这意味着它们是按原样存储的,但我一直无法找到这样存储我的图像的方法。唯一对我有用的方法是 bytes_feature 路由。
最好/推荐的方法是什么?
【问题讨论】:
-
我是否正确地回答了这个问题:SQLite 数据库压缩前 的大小为 555 MiB,压缩后为 6.5 GiB(压缩后的文件 much i> 更大)?能否将问题扩展为包括如何将 LZMA 压缩应用于 SQLite 数据库文件?
标签: tensorflow image-classification tensorflow-federated federated-learning