Arguments in Keras for image preprocessing












0















On the keras image preprocessing page it is not explained and I can't figure out what I am doing wrong. There is one comment here on stackoverflow about it but to me it still makes no sense. For the following code:



# we create two instances with the same arguments
data_gen_args = dict(featurewise_center=True,
featurewise_std_normalization=True,
rotation_range=90,
width_shift_range=0.1,
height_shift_range=0.1,
zoom_range=0.2)
image_datagen = ImageDataGenerator(**data_gen_args)
mask_datagen = ImageDataGenerator(**data_gen_args)

# Provide the same seed and keyword arguments to the fit and flow methods
seed = 1
image_datagen.fit(images, augment=True, seed=seed)
mask_datagen.fit(masks, augment=True, seed=seed)

image_generator = image_datagen.flow_from_directory(
'...data/train_images',
class_mode=None,
seed=seed)

mask_generator = mask_datagen.flow_from_directory(
'...data/train_labels',
class_mode=None,
seed=seed)

# combine generators into one which yields image and masks
train_generator = zip(image_generator, mask_generator)

Model.fit_generator(
train_generator,
steps_per_epoch=20,
epochs=1)


I can not figure out what the purpose is of the line image_datagen.fit(images, augment=True, seed=seed) and what the 'images' argument entails. Is it supposed to be a matrix of all images? How should it be formatted? Same goes for the masks argument below that line. I cannot grasp the purpose of those lines and arguments.



I have my images in a numpy array of dtype uint8 and shape (625, 256, 256, 4), and the labels as dtype uint8 and shape (625, 256,256). Furthermore they are stored as 625 seperate images and masks in the directory given in the code.



I constantly get a ValueError: Input to.fit()should have rank 4. Got array with shape: (625, 256, 256). I understand I have to add another dimension. When I reshape it to (625, 256, 256, 1) (of which I'm not certain it is correct or affects the model) I get the following error:



TypeError: fit_generator() missing 1 required positional argument: 'generator'.


Is there anyone who can explain the concepts of these arguments and perhaps even tell me how to format/shape my code for this to work properly?



Thanks in advance










share|improve this question























  • below link might be of use. stackoverflow.com/questions/51656000/…

    – teng
    Nov 19 '18 at 23:26
















0















On the keras image preprocessing page it is not explained and I can't figure out what I am doing wrong. There is one comment here on stackoverflow about it but to me it still makes no sense. For the following code:



# we create two instances with the same arguments
data_gen_args = dict(featurewise_center=True,
featurewise_std_normalization=True,
rotation_range=90,
width_shift_range=0.1,
height_shift_range=0.1,
zoom_range=0.2)
image_datagen = ImageDataGenerator(**data_gen_args)
mask_datagen = ImageDataGenerator(**data_gen_args)

# Provide the same seed and keyword arguments to the fit and flow methods
seed = 1
image_datagen.fit(images, augment=True, seed=seed)
mask_datagen.fit(masks, augment=True, seed=seed)

image_generator = image_datagen.flow_from_directory(
'...data/train_images',
class_mode=None,
seed=seed)

mask_generator = mask_datagen.flow_from_directory(
'...data/train_labels',
class_mode=None,
seed=seed)

# combine generators into one which yields image and masks
train_generator = zip(image_generator, mask_generator)

Model.fit_generator(
train_generator,
steps_per_epoch=20,
epochs=1)


I can not figure out what the purpose is of the line image_datagen.fit(images, augment=True, seed=seed) and what the 'images' argument entails. Is it supposed to be a matrix of all images? How should it be formatted? Same goes for the masks argument below that line. I cannot grasp the purpose of those lines and arguments.



I have my images in a numpy array of dtype uint8 and shape (625, 256, 256, 4), and the labels as dtype uint8 and shape (625, 256,256). Furthermore they are stored as 625 seperate images and masks in the directory given in the code.



I constantly get a ValueError: Input to.fit()should have rank 4. Got array with shape: (625, 256, 256). I understand I have to add another dimension. When I reshape it to (625, 256, 256, 1) (of which I'm not certain it is correct or affects the model) I get the following error:



TypeError: fit_generator() missing 1 required positional argument: 'generator'.


Is there anyone who can explain the concepts of these arguments and perhaps even tell me how to format/shape my code for this to work properly?



Thanks in advance










share|improve this question























  • below link might be of use. stackoverflow.com/questions/51656000/…

    – teng
    Nov 19 '18 at 23:26














0












0








0








On the keras image preprocessing page it is not explained and I can't figure out what I am doing wrong. There is one comment here on stackoverflow about it but to me it still makes no sense. For the following code:



# we create two instances with the same arguments
data_gen_args = dict(featurewise_center=True,
featurewise_std_normalization=True,
rotation_range=90,
width_shift_range=0.1,
height_shift_range=0.1,
zoom_range=0.2)
image_datagen = ImageDataGenerator(**data_gen_args)
mask_datagen = ImageDataGenerator(**data_gen_args)

# Provide the same seed and keyword arguments to the fit and flow methods
seed = 1
image_datagen.fit(images, augment=True, seed=seed)
mask_datagen.fit(masks, augment=True, seed=seed)

image_generator = image_datagen.flow_from_directory(
'...data/train_images',
class_mode=None,
seed=seed)

mask_generator = mask_datagen.flow_from_directory(
'...data/train_labels',
class_mode=None,
seed=seed)

# combine generators into one which yields image and masks
train_generator = zip(image_generator, mask_generator)

Model.fit_generator(
train_generator,
steps_per_epoch=20,
epochs=1)


I can not figure out what the purpose is of the line image_datagen.fit(images, augment=True, seed=seed) and what the 'images' argument entails. Is it supposed to be a matrix of all images? How should it be formatted? Same goes for the masks argument below that line. I cannot grasp the purpose of those lines and arguments.



I have my images in a numpy array of dtype uint8 and shape (625, 256, 256, 4), and the labels as dtype uint8 and shape (625, 256,256). Furthermore they are stored as 625 seperate images and masks in the directory given in the code.



I constantly get a ValueError: Input to.fit()should have rank 4. Got array with shape: (625, 256, 256). I understand I have to add another dimension. When I reshape it to (625, 256, 256, 1) (of which I'm not certain it is correct or affects the model) I get the following error:



TypeError: fit_generator() missing 1 required positional argument: 'generator'.


Is there anyone who can explain the concepts of these arguments and perhaps even tell me how to format/shape my code for this to work properly?



Thanks in advance










share|improve this question














On the keras image preprocessing page it is not explained and I can't figure out what I am doing wrong. There is one comment here on stackoverflow about it but to me it still makes no sense. For the following code:



# we create two instances with the same arguments
data_gen_args = dict(featurewise_center=True,
featurewise_std_normalization=True,
rotation_range=90,
width_shift_range=0.1,
height_shift_range=0.1,
zoom_range=0.2)
image_datagen = ImageDataGenerator(**data_gen_args)
mask_datagen = ImageDataGenerator(**data_gen_args)

# Provide the same seed and keyword arguments to the fit and flow methods
seed = 1
image_datagen.fit(images, augment=True, seed=seed)
mask_datagen.fit(masks, augment=True, seed=seed)

image_generator = image_datagen.flow_from_directory(
'...data/train_images',
class_mode=None,
seed=seed)

mask_generator = mask_datagen.flow_from_directory(
'...data/train_labels',
class_mode=None,
seed=seed)

# combine generators into one which yields image and masks
train_generator = zip(image_generator, mask_generator)

Model.fit_generator(
train_generator,
steps_per_epoch=20,
epochs=1)


I can not figure out what the purpose is of the line image_datagen.fit(images, augment=True, seed=seed) and what the 'images' argument entails. Is it supposed to be a matrix of all images? How should it be formatted? Same goes for the masks argument below that line. I cannot grasp the purpose of those lines and arguments.



I have my images in a numpy array of dtype uint8 and shape (625, 256, 256, 4), and the labels as dtype uint8 and shape (625, 256,256). Furthermore they are stored as 625 seperate images and masks in the directory given in the code.



I constantly get a ValueError: Input to.fit()should have rank 4. Got array with shape: (625, 256, 256). I understand I have to add another dimension. When I reshape it to (625, 256, 256, 1) (of which I'm not certain it is correct or affects the model) I get the following error:



TypeError: fit_generator() missing 1 required positional argument: 'generator'.


Is there anyone who can explain the concepts of these arguments and perhaps even tell me how to format/shape my code for this to work properly?



Thanks in advance







python image-processing keras semantic-segmentation






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 22:48









Eeuwigestudent1Eeuwigestudent1

417




417













  • below link might be of use. stackoverflow.com/questions/51656000/…

    – teng
    Nov 19 '18 at 23:26



















  • below link might be of use. stackoverflow.com/questions/51656000/…

    – teng
    Nov 19 '18 at 23:26

















below link might be of use. stackoverflow.com/questions/51656000/…

– teng
Nov 19 '18 at 23:26





below link might be of use. stackoverflow.com/questions/51656000/…

– teng
Nov 19 '18 at 23:26












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383762%2farguments-in-keras-for-image-preprocessing%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383762%2farguments-in-keras-for-image-preprocessing%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to send String Array data to Server using php in android

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Is anime1.com a legal site for watching anime?