0

I have images with different width and height

I want to reshape generated images so that width and height are same

So I used following function that check and change shape of images

But there was an error that shape was None type when "size = h if h >= w else w"

How can I check and change shape of Images?

def preprocessing(image, label):
    # add padding
    h, w = image.shape[0], image.shape[1]
    # h, w, _ = tf.shape(image)
    size = h if h >= w else w
    dst = tf.image.pad_to_bounding_box(image, int((size-h)/2), int((size-w)/2), size, size)
    dst = tf.image.resize(dst, size=(2048, 2048))

    # image augmentation
    dst = tf.image.random_crop(dst, size=(1843, 1843, 3))
    dst = tf.image.resize(dst, size=(2048, 2048))
    dst = tf.image.random_flip_left_right(dst)        
    dst = tf.cast(dst, tf.float32)
    dst = (dst / 127.5) - 1
    
    return dst, label

dt = dataset_train.map(preprocessing, num_parallel_calls=tf.data.experimental.AUTOTUNE)
dt = dt.batch(32).prefetch(3)
dv = dv.batch(32).prefetch(3)

enter image description here

yeon
  • 5
  • 2

0 Answers0