Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
540 views
in Technique[技术] by (71.8m points)

python - How to rescale images from [0,255] to [-1,1] with ImageDataGenerator?

I'm using ImageDataGenerator with flow_from_dataframe to load a dataset.

ImageDataGenerator allows you to specify a rescaling factor like this

datagen = ImageDataGenerator(rescale=1./255)

But what if I want to rescale my images in the range [-1,1]? I should do a subtraction followed by a division

images -= 128.0
images /= 128.0

How can I do these two operations in the rescale of ImageDataGenerator?

question from:https://stackoverflow.com/questions/65928036/how-to-rescale-images-from-0-255-to-1-1-with-imagedatagenerator

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

try using rescale=1/127.5-1 or you can use pre defined processor functions such as

preprocessing_function=tf.keras.applications.mobilenet.preprocess_input

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...