Augmentor icon indicating copy to clipboard operation
Augmentor copied to clipboard

Something wrong occured when applying function ' ground_truth() function'

Open gnaygnak opened this issue 6 years ago • 11 comments

When I was using your demo code to augment original and mask images identically, I found I got different number of augmented mask and images! I can't figure out why this happened. This meant the mask and image were NOT AUGMENTED IDENTICALLY, were they? Could you please help me to deal with this question, thanks.

gnaygnak avatar Mar 08 '18 17:03 gnaygnak

Thanks for reporting the issue. However, this is not a lot of information to go on. can you provide some more details? for example the version you are using and some code with some comments at the places where you observed which inconsistency.

Evizero avatar Mar 08 '18 17:03 Evizero

Ok, sure. and Thank you for your timely reply. Here I'll give your some version informal, the code I'm running and the result I got. NAME VERSION Augmentor 0.2.0 numpy 1.14.1 p = Augmentor.Pipeline("train") #Point to a directory containing ground truth data. #Images with the same file names will be added as ground truth data # and augmented in parallel to the original data. p.ground_truth("mask") # Add operations to the pipeline as normal: p.rotate(probability=1, max_left_rotation=5, max_right_rotation=5) p.flip_left_right(probability=1) p.zoom_random(probability=1, percentage_area=0.8) p.flip_top_bottom(probability=1) p.sample(6)

Finally, I got 10 pictures, they were 4 transformed masks and 4 corresponding transformed image and 2 image without corresponding transformed masks. Normally, I should have gotten 5 transformed masks and image correspondingly, but not! I don't know why. I hope I have express clearly. Thank you.

gnaygnak avatar Mar 08 '18 17:03 gnaygnak

Hi @gnaygnak, how many images are in train and mask directories? Are there any sub folders in either directory? I am having some issues with the new ground truth functionality, and trying to get to the bottom of it. In my tests things seem to work fine, but users are having some strange problems...

mdbloice avatar Mar 09 '18 08:03 mdbloice

Hi @mdbloice , I have known the reason. When you are applying the ground_truth() function, you must make sure that there is just single data in train and mask directories, right? Thank you for replying.

gnaygnak avatar Mar 10 '18 15:03 gnaygnak

Hi @gnaygnak, no it should work with any number of images. As long as the file names match between the two directories you can use any number of images. M.

mdbloice avatar Mar 22 '18 09:03 mdbloice

Hi @mdbloice is there a way to have ground_truth() working even if the file names do not match ? in my case the ground truth file names are followed by "_mask"

Marwen-Bhj avatar May 16 '19 11:05 Marwen-Bhj

Hi @Marwen-Bhj, no not at the moment, however you can use DataPipeline for such situations:

p = Augmentor.DataPipeline(images, y)

Where images contains any number of images/masks in array format (rather than reading from the disk). See this notebook for details on how to prepare the images data structure here:

Multiple-Mask-Augmentation.ipynb

Hope this helps!

mdbloice avatar May 17 '19 07:05 mdbloice

Hi @mdbloice thank you , it did help doing the task needed , yet as I saw in documentation ,this doesn't save the files anywhere , I tried using : sample_with_array(augmented_images[i][j], save_to_disk=True) in a for loop

where augmented_images.shape outputs (3, 2, 384, 768, 3) (3x2 samples , 348x768 and 3 channels ) if we transform it to an array using numpy .

I need those generated samples and augmented images saved in a certain directory how can I do this ?

Marwen-Bhj avatar May 17 '19 09:05 Marwen-Bhj

Hi @Marwen-Bhj, you could try using PIL/Pillow to create images from array data, so something like

from PIL import Image

im = Image.fromarray(augmented_images[...])
im.save('/path/image.png') 

and do that in a loop, where augmented_images[...] will have to be sliced accordingly to get the images you want out....

mdbloice avatar May 17 '19 10:05 mdbloice

@mdbloice yes that's what I did eventually , just had to do some workaround with naming . thank you again.

Marwen-Bhj avatar May 17 '19 10:05 Marwen-Bhj

@Marwen-Bhj ok sure, glad you got it to work out :-)

M.

mdbloice avatar May 17 '19 10:05 mdbloice