Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

tensorflow - How to handle image size variation in Deep Learning?

I am working on a image classification model which classify images into 5 categories. I have 5000 training images data stored in a folder but all images are of different heigth and width. like this -

'631.jpg': {'width': 81, 'heigth': 25},
'8595.jpg': {'width': 1173, 'heigth': 769},
'284.jpg': {'width': 94, 'heigth': 75},
'5999.jpg': {'width': 4220, 'heigth': 1951}
  

Can anyone tell me about any technique to handle this kind of data ?

question from:https://stackoverflow.com/questions/65871699/how-to-handle-image-size-variation-in-deep-learning

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

1 Answer

0 votes
by (71.8m points)
tf.image.resize_with_crop_or_pad(image, desired_height, desired_width)

Images smaller than desired_height and desired_width will be padded, and those larger will be centrally cropped.

import tensorflow as tf
import matplotlib.pyplot as plt

_, ((first, *rest), _) = tf.keras.datasets.cifar10.load_data()

modified = tf.image.resize_with_crop_or_pad(first[None, ...]/255, 48, 48)

plt.imshow(tf.squeeze(modified))
plt.show()

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...