【发布时间】:2021-04-30 06:52:31
【问题描述】:
我有一个数据集通过
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
data_dir,
validation_split=validation_split,
subset="training",
seed=seed,
image_size=(img_height, img_width),
batch_size=batch_size)
(基于来自 https://www.tensorflow.org/tutorials/load_data/images 的代码,对配置进行了非常小的更改)
我正在将最终模型转换为 TFLite 模型,该模型正在运行,但我认为该模型对于终端设备来说太大了,所以我试图通过提供 representative_dataset (如 @987654322)来运行训练后量化@)
但是我不知道如何将 image_dataset_from_directory 生成的数据集转换为 representative_dataset 期望的格式
提供的例子有
def representative_dataset():
for data in tf.data.Dataset.from_tensor_slices((images)).batch(1).take(100):
yield [data.astype(tf.float32)]
我尝试过类似的东西
def representative_dataset():
for data in train_ds.batch(1).take(100):
yield [data.astype(tf.float32)]
但事实并非如此
【问题讨论】:
-
运行代码时是否打印了一些错误信息?
-
很多像
'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'astype'这样的东西表明我没有以正确的方式做representative_dataset
标签: tensorflow keras tensorflow-datasets tensorflow-lite