tensorlayer / TensorLayer

Deep Learning and Reinforcement Learning Library for Scientists and Engineers
http://tensorlayerx.com
Other
7.34k stars 1.61k forks source link

About the function of tl.prepro.threading_data #1053

Closed lkyee closed 3 years ago

lkyee commented 4 years ago

image

Hi,I want to processing images and masks together,however,the size of different pictures in my dataset is different.Therefore, I can't do that as X, Y --> [batch_size, row, col, channel].The following code is the code I used before modification.

hr_4 = tl.prepro.threading_data(train_hr_imgs,fn=utils.crop_sub_imgs_fn, is_random=True)

def augment(x, hflip=True, rot=True): hflip = hflip and random.random() < 0.5 vflip = rot and random.random() < 0.5 rot90 = rot and random.random() < 0.5

def _augment(img):
    if hflip:
        img = flip_axis(img, axis=1)
    if vflip:
        img = flip_axis(img, axis=0)
    if rot90:
        img = rotation(img, rg=90)
    return img
return _augment(x)

def crop_sub_imgs_fn(x, is_random=True):

x = crop(x, wrg=192, hrg=192, is_random=is_random)

x = crop(x, wrg=72, hrg=72, is_random=is_random)
x = augment(x)
return x

train_hr_imgs is a tuple(16,) ---I set the batch-size=16 namely,It contains 16 pictures of different sizes,and the output is a tuple (16,72,72,3) And now, I have another mask image, called train_mask_imgs.It is also a tuple(16,) like the train_hr_imgs, and their pictures are one-to-one pair. If I used the same code like ------------------------------------------- "mask_4 = tl.prepro.threading_data(train_mask_imgs,fn=utils.crop_sub_imgs_fn, is_random=True)" ------------------------------------------- It can also get the tuple(16,72,72,3), but due to random, the results of two (16,72,72,3) is not one to one pair.  I don't know how to solve it,Thanks for your help!

zsdonghao commented 4 years ago

https://tensorlayer.readthedocs.io/en/latest/modules/prepro.html#python-can-be-fast

this should helps