-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using this library with Keras #66
Comments
I do not have a example yet, but you should use the fit_generator from keras. The keras documentation have a example showing how to use it. |
I will try to make this work and post if I succeed. Or did you try it, @deepakanandece? How did it go? |
Any updates on this? I would like to use this with Keras datagenerator as well. |
I decided to go with Keras ImageDataGenerator instead. It has all the basic augmentations covered. |
Was able to get this to play well with Keras. `
then just call fit_generator on your model like this:
The augment() function is what is actually doing the imgaug work here. It just takes in X and y and calls |
NUM_KEYPOINTS is simply the number of keypoints you are performing the augmentation on. So if you are doing simple eye tracking with a network and are using 2 keypoints (one for each eye) then NUM_KEYPOINTS would be 2. It’s multiplied by 2 in the code to account for both the X and Y coordinates of each point.
… On Apr 13, 2018, at 3:51 AM, Johan Bender ***@***.***> wrote:
@jessestauffer Thanks for sharing! Could you help explain what the variable NUM_KEYPOINTS is referring to?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Thanks for explaining @jessestauffer . In my case, I'm trying to predict between 5 different category classes, so I've made a change in order to save the one-hot encoded vectors for the y labels. However, when I run the code, even though training works properly, I get much worse results with the fit_generator both with and without the augmenter. Actually, the network only performs at random accuracy (20%), while without the fit_generato the X_train and Y_train performs above 60% accuracy. Do you have any idea of what I'm doing wrong?
I've tried both with the augmenter turned on and off and the results seem to be the same for me :-( ... |
@titanbender Nothing stands out to me in the generator code. Could you share the code you were using to fit the model both with and without the generator? |
@titanbender Made a quick example of getting this to work with categories for you. https://github.com/jessestauffer/MNIST-CNN-Keras/blob/master/mnist.py |
Yes, here's the code with - and without the generator. I apologize for asking for your advice. It seems to me that I've switched out X_test, Y_test with X_valid and Y_valid. That being said, it shouldn't greatly decrease the accuracy of the training data which also is just about 20% with the generator. With Generator
Without Generator
Below is the print out from my 10 epochs. Epoch 1/10 |
@jessestauffer thanks for putting together a sample for me. I really appreciate it! Will try to see if it helps in terms the medical images I work with. Have a great weekend! |
@titanbender no problem! Your fit and fit_generator code looks correct. Go through the sample and see if anything jumps out at you and let me know if you have any other questions. |
Thanks. Cheers! |
Hi -- thanks for the code! With respect to the original question, I was able to get this to play well with keras DataGenerator by using the preprocessing_function option. It has some limitations with respect to which Augmentations can be used, but it worked fo the cases I was trying.
This additional function can be passed to keras data generator as a pre-processing function.
One caveat to note is the following from Keras documentation regarding preprocessing_function:
So, this approach may not work for all the augmentations. |
@tavildar I tried your code and get this error in
|
@azmathmoosa that seems like issue relating to your image being float -- I think imgaug requires data being uint8. See for example the following comment in the Readme
|
@titanbender . Hi, in your generator function you are really not augmenting your images but just randomizing the position of the images. To actually augment you should cal the augment code as specified by @jessestauffer |
I have a nice example with keras, ImageDataGenerator and flow_from_dataframe, below fragment of code: seq = iaa.Sequential([ def augment(img):
train_generator = image.ImageDataGenerator(preprocessing_function=augment) train_flow = train_generator.flow_from_dataframe( |
Thanks to @nieszkodzi and @tavildar for the excellent solutions. I've been trying to implement imgaug to work with Keras's ImageDataGenerator (and have found the thread where this is discussed), but am running into an Assertion Error with no explanation during the fit command
This yields the error:
` I think this has to do with my images not being in the correct format I believe, but I'm not fully sure about this? |
I found a much neater way to do this, I wrote a custom import deeply.img.augmenters as dia
import imgaug.augmenters as iaa
import imgaug as ia
image = ia.data.quokka() Then, augmentor = iaa.Sequential([
dia.Combination([
iaa.Fliplr(1.0),
iaa.Flipud(1.0),
iaa.Affine(scale = 1.3),
iaa.Affine(scale = 0.7),
iaa.Rotate(rotate = (-45, 45)),
iaa.ShearX((-20, 20)),
iaa.ShearY((-20, 20)),
iaa.Translate(percent = (-0.1, 0.1)),
iaa.Translate(percent = (-0.1, 0.1))
]),
iaa.Resize({ "width": 250, "height": 250 })
])
images = augmenter(images = [image])
|
Can anyone give an example for using this library with image datagenerator flow from directory method of keras?
The text was updated successfully, but these errors were encountered: