use ImageDataGenerator (python) in dataiku

Solved!
BenGonGon
Level 3
use ImageDataGenerator (python) in dataiku

Hello,

I want reproduce the tricks in chapter "Data pre-processing and data augmentation" from this website https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html

And I have problem to execute python script with ImageDataGenerator.

# -*- coding: utf-8 -*-
import dataiku
import pandas as pd, numpy as np
from dataiku import pandasutils as pdu
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img

# Read recipe inputs
train_apple = dataiku.Folder("l8PGPsC0")
train_apple_info = train_apple.get_info()

datagen = ImageDataGenerator(
rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest')

# img = load_img('data/train/cats/cat.0.jpg') # this is a PIL image
img = dataiku.Folder("l8PGPsC0") # this is a PIL image
x = img_to_array(img) # this is a Numpy array with shape (3, 150, 150)
x = x.reshape((1,) + x.shape) # this is a Numpy array with shape (1, 3, 150, 150)

# the .flow() command below generates batches of randomly transformed images
# and saves the results to the `preview/` directory
i = 0
for batch in datagen.flow(x, batch_size=1,
save_to_dir=dataiku.Folder("n6fptvg8"), save_prefix='cat', save_format='jpeg'):
i += 1
if i > 2: #nb picture generated
break # otherwise the generator would loop indefinitely

# Write recipe outputs
train_apple_mod = dataiku.Folder("n6fptvg8")
train_apple_mod_info = train_apple_mod.get_info()
0 Kudos
1 Solution
BenGonGon
Level 3
Author

Hi @Ignacio_Toledo ,
I have posted like a noob, shame on me.
This script is for use ImageDataGenerator.
But I can do that by this way untitled.png
Perhaps I do ask to a moderator to delete this post.

View solution in original post

3 Replies
Ignacio_Toledo

Hi @BenGonGon. What is exactly the problem you have? Any error messages? Or you don't know where to run this code?

0 Kudos
BenGonGon
Level 3
Author

Hi @Ignacio_Toledo ,
I have posted like a noob, shame on me.
This script is for use ImageDataGenerator.
But I can do that by this way untitled.png
Perhaps I do ask to a moderator to delete this post.

Ignacio_Toledo

No worries @BenGonGon! We can all make mistakes!