mdbloice / Augmentor

Image augmentation library in Python for machine learning.
https://augmentor.readthedocs.io/en/stable
MIT License
5.06k stars 865 forks source link

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

Open gnaygnak opened 6 years ago

gnaygnak commented 6 years ago

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.

Evizero commented 6 years ago

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.

gnaygnak commented 6 years ago

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.

mdbloice commented 6 years ago

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...

gnaygnak commented 6 years ago

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.

mdbloice commented 6 years ago

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.

Marwen-Bhj commented 5 years ago

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"

mdbloice commented 5 years ago

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!

Marwen-Bhj commented 5 years ago

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 ?

mdbloice commented 5 years ago

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....

Marwen-Bhj commented 5 years ago

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

mdbloice commented 5 years ago

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

M.