首页 > 解决方案 > 用 16 位图像训练 keras ResNet50V2?

问题描述

我有 3 通道 tif 图像(16 位)。现在,我想将它们用作来自 keras 的预训练 ResNet50V2 上的训练图像。我明白,我应该tf.keras.applications.resnet_v2.preprocess_input在使用 ImageDataGenerators 时调用 as 预处理函数。我查阅了函数(preprocess_input)的文档,它至少告诉我它需要 8 位数据。有没有办法将 16 位图像提供给 ImageDataGenerator?

或者我是否必须在将图像输入 ImageDataGenerator 之前将它们转换为 8 位?

我很高兴有任何建议!

标签: pythontensorflowkerastf.kerasresnet

解决方案


我在您链接的文档中没有看到对 8 位数据的引用。

是的,它可以接受 16 位:

import tensorflow as tf
import numpy as np

x = np.random.randint(0, 256, (1, 224, 224, 3), dtype=np.uint16)

tf.keras.applications.resnet_v2.preprocess_input(x)
array([[[[ 0.43529415, -0.24705881, -0.23137254],
         [-0.81960785,  0.3411765 , -0.5921569 ],
         [-0.7882353 ,  0.58431375,  0.0196079 ],
         ...,
         [-0.60784316, -0.4980392 ,  1.        ],
         [-0.654902  ,  0.99215686, -0.38039213],
         [ 0.03529418, -0.7411765 , -0.8901961 ]]]], dtype=float32)

推荐阅读