use ImageDataGenerator (python) in dataiku

BenGonGon
BenGonGon Registered Posts: 20 ✭✭✭✭
edited July 16 in Using 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()

Best Answer

Answers

  • Ignacio_Toledo
    Ignacio_Toledo Dataiku DSS Core Designer, Dataiku DSS Core Concepts, Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Frontrunner 2022 Finalist, Frontrunner 2022 Winner, Dataiku Frontrunner Awards 2021 Participant, Frontrunner 2022 Participant, Neuron 2023 Posts: 415 Neuron

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

  • Ignacio_Toledo
    Ignacio_Toledo Dataiku DSS Core Designer, Dataiku DSS Core Concepts, Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Frontrunner 2022 Finalist, Frontrunner 2022 Winner, Dataiku Frontrunner Awards 2021 Participant, Frontrunner 2022 Participant, Neuron 2023 Posts: 415 Neuron

    No worries @BenGonGon
    ! We can all make mistakes!

Setup Info
    Tags
      Help me…