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

Categories

0 votes
399 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...