假设我有一个32*32*3图像类型的数据集作为源数据:
<DatasetV1Adapter shapes: {coarse_label: (), image: (32, 32, 3), label: ()}, types: {coarse_label: tf.int64, image: tf.uint8, label: tf.int64}>
在序列化我得到的数据之后:
<MapDataset shapes: {depth: (), height: (), image_raw: (), label: (), width: ()}, types: {depth: tf.int64, height: tf.int64, image_raw: tf.string, label: tf.int64, width: tf.int64}>我可以使用下面这段代码访问每个元素:
for i in parsed_image_dataset.take(1):
j=i['image_raw']
array_shape = e1['image'].numpy().shape
print(np.frombuffer(j.numpy(), dtype = 'uint8').reshape(array_shape))在原始dataset.So中使用get_next生成e1的情况下,print会打印出与序列化前的图像相同的图像。但是,我可以通过某种方式将序列化的数据集立即转换为原始的uint8数据集吗?
发布于 2020-05-09 23:16:06
您可以通过以下步骤在uint8中获取镜像。
创建序列化数据。
list_ds = tf.data.Dataset.list_files("img_dir_path/*")创建一个函数,该函数将file_path作为参数并返回uint8格式的图像。
def process_img(file_path):
img = tf.io.read_file(file_path)
img = tf.image.decode_jpeg(img, channels=3)
return img使用map函数将上述函数应用于list_ds对象中的所有项。
processed_images = list_ds.map(process_img)processed_images将包含给定图像目录的uint8格式的图像。
https://stackoverflow.com/questions/60711659
复制相似问题