mdbloice / Augmentor

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

ValueError: image has wrong mode #246

Open xuanzhiliu opened 2 years ago

xuanzhiliu commented 2 years ago

Hi,I faced a problem when I used: p.random_color(probability=0.6,min_factor=50,max_factor=120) p.random_brightness(probability=0.8,min_factor=50,max_factor=255) the error was: image image however,if I deleted these codes and used other functions like rotate90,rotate270 or random_erasing,the codes worked very well My codes are as follow: import Augmentor p=Augmentor.Pipeline("H:\\text\imgs") p.ground_truth("H:\\text\jsons\mask_png") p.rotate(probability=1,max_left_rotation=25,max_right_rotation=25) p.random_color(probability=0.6,min_factor=50,max_factor=120) p.random_brightness(probability=0.8,min_factor=50,max_factor=255) p.random_erasing(probability=1,rectangle_area=0.5) p.sample(50) Thank you !

xuanzhiliu commented 2 years ago

Hi,I have solved this problem,here is my solution: I used this method(random_color and random_brightness) to do data augmentation during the semantic segmentation,at first I try to augment both the original images.png and the mask.png so that this problem occured However, the mask.png shouldn't and unnecessary to be augmented because the objects's location and shape and size isn't changed(except rotate and cutout),so that I deleted the codes: p.ground_truth() then the codes worked pretty After that I got the reason why I can't changed the mask.png,due to the reason that the mode of the mask.png is 'L',which means: mask.mode=='L',you can use the code to check it However,the question is,only the imgs which mode is 'RGB' can be used in the image.py,I don't know why and have no idea to solve it.So,if you faced this problem,here are two ways can be taken into consideration: 1.check your img.mode and make sure they are'RGB' not others,like 'P','L' 2.make sure your imgs are png, this is important.I tryed to use jpg,jpeg in all the methods and all of them have bugs I hope my advice can help you solve your problem good luck!