How to use Keras Image Preprocessing .flow(x, y)

267 views
Skip to first unread message

hendri...@googlemail.com

unread,
Dec 2, 2019, 9:05:04 AM12/2/19
to Keras-users
Hi !

I am using Keras data augmentation for both my x_train and my y_train images for an image segmentation task.


For this I am using following code:


data_gen_args = dict(width_shift_range = 0.05)
aug = kp.image.ImageDataGenerator(**data_gen_args)

history = model.fit_generator(aug.flow(x_train, y_train, save_to_dir = augment_save_dir),
steps_per_epoch = len(x_train) / 32, validation_data=(x_val, y_val), epochs=epochs, verbose=1)



I would like to be sure that the data augmentation operations are applied to both the images and their labels. For this I would like to save the augmented images, but with my code only the augmented images and not their augmented masks are saved to 'save_to_dir'


How can I save both the images and their labels to visualise them?


I have already tried the example on the Keras Image preprocessing page 'Example of transforming images and masks together' : https://keras.io/preprocessing/image/ without success.
I get the error AttributeError: 'zip' object has no attribute 'shape'.

The code:

P.S. I have already posted a question on stackoverflow: https://stackoverflow.com/questions/59074240/keras-image-preprocessing-flowx-y-save-to-dir-only-saves-the-augmented-x-im but did not get any help yet :(


My full network training code can be found under: https://github.com/Jimmy2027/MLEBE/tree/trying_successive_learning


Lance Norskog

unread,
Dec 2, 2019, 7:27:30 PM12/2/19
to hendri...@googlemail.com, Keras-users
You can run the image augmenter and fetch the images and labels back directly, see method ImageDataGenerator.apply_transform()


N.B. I have not used this class
> --
> You received this message because you are subscribed to the Google Groups "Keras-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/a065ba8a-2c04-4342-a769-4a40613b3362%40googlegroups.com.



--
Lance Norskog
lance....@gmail.com
Redwood City, CA

hendri...@googlemail.com

unread,
Dec 3, 2019, 9:28:55 AM12/3/19
to Keras-users
hmm but how do I feed them into my fit_generator method after runing the image augmenter ?

I really don't understand why the example from https://keras.io/preprocessing/image/ doesn't work :( I sthis an issue with tensorflow 2.0 ?


Am Dienstag, 3. Dezember 2019 01:27:30 UTC+1 schrieb Lance Norskog:
You can run the image augmenter and fetch the images and labels back directly, see method ImageDataGenerator.apply_transform()


N.B. I have not used this class

On Mon, Dec 2, 2019 at 6:05 AM hendrik.klug via Keras-users <keras...@googlegroups.com> wrote:
>
> Hi !
>
> I am using Keras data augmentation for both my x_train and my y_train images for an image segmentation task.
>
>
> For this I am using following code:
>
>
> data_gen_args = dict(width_shift_range = 0.05)
> aug = kp.image.ImageDataGenerator(**data_gen_args)
>
> history = model.fit_generator(aug.flow(x_train, y_train, save_to_dir = augment_save_dir),
> steps_per_epoch = len(x_train) / 32, validation_data=(x_val, y_val), epochs=epochs, verbose=1)
>
>
>
> I would like to be sure that the data augmentation operations are applied to both the images and their labels. For this I would like to save the augmented images, but with my code only the augmented images and not their augmented masks are saved to 'save_to_dir'
>
>
> How can I save both the images and their labels to visualise them?
>
>
> I have already tried the example on the Keras Image preprocessing page 'Example of transforming images and masks together' : https://keras.io/preprocessing/image/ without success.
> I get the error AttributeError: 'zip' object has no attribute 'shape'.
>
> The code:
>
> P.S. I have already posted a question on stackoverflow: https://stackoverflow.com/questions/59074240/keras-image-preprocessing-flowx-y-save-to-dir-only-saves-the-augmented-x-im but did not get any help yet :(
>
>
> My full network training code can be found under: https://github.com/Jimmy2027/MLEBE/tree/trying_successive_learning
>
>
> --
> You received this message because you are subscribed to the Google Groups "Keras-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to keras...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages