加载带有keras imagedatagenerator的TIFF图像
我正在尝试在Python 3.7的Keras/Tensorflow中使用U-NET进行多级培训。我只有在Grayscale(1个通道)中使用.jpg图像(在范围[0,255]中具有值的图像)进行二进制训练的经验,我加载了Imagedatagenerator类。
在这种情况下,我需要加载1通道.tif图像,值范围从-1000到7000 。据我所知,Imagedatagenerator在[0,255]中加载图像,这使我丢失了很多信息。有什么方法可以使用Imagedatagenerator加载这些图像的原始值?我知道枕头库可以正确加载它们,但是我有很多数据,需要有效地加载它。
前提我用来加载图像的代码,蒙版如下:
from keras_preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator()
train_image_generator = train_datagen.flow_from_directory(
"/full/path/to/my/dir",
classes="images",
batch_size=16,
color_mode="grayscale",
target_size=(400, 400),
class_mode=None,
seed=100,
shuffle=True,
)
train_mask_generator = train_datagen.flow_from_directory(
"/full/path/to/my/dir",
classes="masks",
batch_size=16,
color_mode="grayscale",
target_size=(400, 400),
class_mode=None,
seed=100,
shuffle=True,
)
谢谢。
I'm trying to launch a multi-class training with U-Net in Keras/Tensorflow in Python 3.7. I only have experience performing binary training with .jpg images (images with values in the ranges [0,255]) in grayscale (1 channel), which I loaded with the ImageDataGenerator class.
In this case, I need to load 1-channel .tif images with values ranging from -1000 to 7000. As far as I can tell, ImageDataGenerator loads the images in [0,255], which causes me to lose a lot of information. Is there any way to load those images with the original values using ImageDataGenerator? I know the Pillow library loads them properly, but I have a lot of data and I needed to load that efficiently.
Assuming I have the images in /full/path/to/my/dir/images
and the masks in /full/path/to/my/dir/masks
, the code I'm using to load the images and the masks are as follows:
from keras_preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator()
train_image_generator = train_datagen.flow_from_directory(
"/full/path/to/my/dir",
classes="images",
batch_size=16,
color_mode="grayscale",
target_size=(400, 400),
class_mode=None,
seed=100,
shuffle=True,
)
train_mask_generator = train_datagen.flow_from_directory(
"/full/path/to/my/dir",
classes="masks",
batch_size=16,
color_mode="grayscale",
target_size=(400, 400),
class_mode=None,
seed=100,
shuffle=True,
)
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在Imagedatagenerator中,您可以定义一个预处理器函数。它处理每个图像并返回结果。注意处理的图像必须具有与输入图像相同的形状,但是您可以操纵像素值
In the ImageDataGenerator there is a preprocessor function that you can define. It processes each image and returns the result. Note the processed image must have the same shape as the input image but you can manipulate the pixel values