Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用16位图像训练keras ResNet50V2?_Python_Tensorflow_Keras_Tf.keras_Resnet - Fatal编程技术网

Python 使用16位图像训练keras ResNet50V2?

Python 使用16位图像训练keras ResNet50V2?,python,tensorflow,keras,tf.keras,resnet,Python,Tensorflow,Keras,Tf.keras,Resnet,我有3通道tif图像(16位)。 现在,我想将它们用作来自keras的预训练ResNet50V2上的训练图像。我知道,在使用ImageDataGenerator时,我应该调用tf.keras.applications.resnet\u v2.preprocess\u input作为预处理函数。我查阅了函数()的文档,它告诉我至少需要8位数据。 有没有办法将16位图像提供给ImageDataGenerator 或者,在将图像输入ImageDataGenerator之前,我必须将图像转换为8位吗 我

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

或者,在将图像输入ImageDataGenerator之前,我必须将图像转换为8位吗


我很乐意接受任何建议

我看不到您链接的文件中有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)

根据站点指南,我编辑了您的问题,因此它只关注一个问题。文档中说明了参数“x”:浮点numpy.array或tf.Tensor,3D或4D,具有3个颜色通道,值范围为[0,255]。如果数据类型兼容,预处理的数据将写入输入数据。为了避免这种行为,可以使用numpy.copy(x)。我想,我应该提到,我的图像具有完整的16位范围(065535)的值除以65535?但它们仍然没有使用[0255]的范围。我根本不知道,这个预处理函数应该做什么——从-1重缩放到1?如果是这样的话,我必须在之前将图像重新缩放到[0255]。但这在哪一点是可能的?除以65535,然后乘以255
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)