Keras: DataFrameIterator - how to get next batch (TypeError: 'float' object is not callable)












0















I am using flow_from_dataframe to construct a DataFrameIterator:



datagen=ImageDataGenerator()
train_generator=datagen.flow_from_dataframe(...)

print(train_generator)
>> <keras_preprocessing.image.DataFrameIterator object at 0x00000262F5D93F60>


Now I am trying to get a single batch from this generator. Usually using next(train_generator) works on flow_from_directory generators, however this approach



x,y = next(train_generator)


and



x,y = train_generator.next


results in:



---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-48-6be8f38d3987> in <module>
----> 1 next(train_generator)

~AppDataLocalContinuumanaconda3envstensorflow-gpulibsite-packageskeras_preprocessingimage.py in __next__(self, *args, **kwargs)
1524
1525 def __next__(self, *args, **kwargs):
-> 1526 return self.next(*args, **kwargs)
1527
1528 def _get_batches_of_transformed_samples(self, index_array):

~AppDataLocalContinuumanaconda3envstensorflow-gpulibsite-packageskeras_preprocessingimage.py in next(self)
2201 # The transformation of images is not under thread lock
2202 # so it can be done in parallel
-> 2203 return self._get_batches_of_transformed_samples(index_array)

~AppDataLocalContinuumanaconda3envstensorflow-gpulibsite-packageskeras_preprocessingimage.py in _get_batches_of_transformed_samples(self, index_array)
2160 params = self.image_data_generator.get_random_transform(x.shape)
2161 x = self.image_data_generator.apply_transform(x, params)
-> 2162 x = self.image_data_generator.standardize(x)
2163 batch_x[i] = x
2164 # optionally save augmented images to disk for debugging purposes

~AppDataLocalContinuumanaconda3envstensorflow-gpulibsite-packageskeras_preprocessingimage.py in standardize(self, x)
1117 """
1118 if self.preprocessing_function:
-> 1119 x = self.preprocessing_function(x)
1120 if self.rescale:
1121 x *= self.rescale

TypeError: 'float' object is not callable


How can I access a single batch (i.e. next batch)?



EDIT:
As pointed out by @today in the comments, using next(train_generator) should work just fine. In my case I was using the preprocess_input parameter in the ImageDataGenerator whereas I should have used the rescale parameter. Now the issue is solved!










share|improve this question

























  • Could you please provide the full stack trace?

    – today
    Jan 3 at 16:06











  • @today I added the entire error message

    – AaronDT
    Jan 3 at 16:09











  • Could you please format it as code block and not block quote? Just copy the stack trace, paste it here and then select it and press "code sample" button in the toolbar.

    – today
    Jan 3 at 16:13











  • @today sure thing :)

    – AaronDT
    Jan 3 at 16:16






  • 1





    Thanks. It seems there is something wrong with the preprocessing_function argument you may have set when creating the ImageDataGenerator. Could you please provide the full code for that part as well?

    – today
    Jan 3 at 16:17
















0















I am using flow_from_dataframe to construct a DataFrameIterator:



datagen=ImageDataGenerator()
train_generator=datagen.flow_from_dataframe(...)

print(train_generator)
>> <keras_preprocessing.image.DataFrameIterator object at 0x00000262F5D93F60>


Now I am trying to get a single batch from this generator. Usually using next(train_generator) works on flow_from_directory generators, however this approach



x,y = next(train_generator)


and



x,y = train_generator.next


results in:



---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-48-6be8f38d3987> in <module>
----> 1 next(train_generator)

~AppDataLocalContinuumanaconda3envstensorflow-gpulibsite-packageskeras_preprocessingimage.py in __next__(self, *args, **kwargs)
1524
1525 def __next__(self, *args, **kwargs):
-> 1526 return self.next(*args, **kwargs)
1527
1528 def _get_batches_of_transformed_samples(self, index_array):

~AppDataLocalContinuumanaconda3envstensorflow-gpulibsite-packageskeras_preprocessingimage.py in next(self)
2201 # The transformation of images is not under thread lock
2202 # so it can be done in parallel
-> 2203 return self._get_batches_of_transformed_samples(index_array)

~AppDataLocalContinuumanaconda3envstensorflow-gpulibsite-packageskeras_preprocessingimage.py in _get_batches_of_transformed_samples(self, index_array)
2160 params = self.image_data_generator.get_random_transform(x.shape)
2161 x = self.image_data_generator.apply_transform(x, params)
-> 2162 x = self.image_data_generator.standardize(x)
2163 batch_x[i] = x
2164 # optionally save augmented images to disk for debugging purposes

~AppDataLocalContinuumanaconda3envstensorflow-gpulibsite-packageskeras_preprocessingimage.py in standardize(self, x)
1117 """
1118 if self.preprocessing_function:
-> 1119 x = self.preprocessing_function(x)
1120 if self.rescale:
1121 x *= self.rescale

TypeError: 'float' object is not callable


How can I access a single batch (i.e. next batch)?



EDIT:
As pointed out by @today in the comments, using next(train_generator) should work just fine. In my case I was using the preprocess_input parameter in the ImageDataGenerator whereas I should have used the rescale parameter. Now the issue is solved!










share|improve this question

























  • Could you please provide the full stack trace?

    – today
    Jan 3 at 16:06











  • @today I added the entire error message

    – AaronDT
    Jan 3 at 16:09











  • Could you please format it as code block and not block quote? Just copy the stack trace, paste it here and then select it and press "code sample" button in the toolbar.

    – today
    Jan 3 at 16:13











  • @today sure thing :)

    – AaronDT
    Jan 3 at 16:16






  • 1





    Thanks. It seems there is something wrong with the preprocessing_function argument you may have set when creating the ImageDataGenerator. Could you please provide the full code for that part as well?

    – today
    Jan 3 at 16:17














0












0








0








I am using flow_from_dataframe to construct a DataFrameIterator:



datagen=ImageDataGenerator()
train_generator=datagen.flow_from_dataframe(...)

print(train_generator)
>> <keras_preprocessing.image.DataFrameIterator object at 0x00000262F5D93F60>


Now I am trying to get a single batch from this generator. Usually using next(train_generator) works on flow_from_directory generators, however this approach



x,y = next(train_generator)


and



x,y = train_generator.next


results in:



---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-48-6be8f38d3987> in <module>
----> 1 next(train_generator)

~AppDataLocalContinuumanaconda3envstensorflow-gpulibsite-packageskeras_preprocessingimage.py in __next__(self, *args, **kwargs)
1524
1525 def __next__(self, *args, **kwargs):
-> 1526 return self.next(*args, **kwargs)
1527
1528 def _get_batches_of_transformed_samples(self, index_array):

~AppDataLocalContinuumanaconda3envstensorflow-gpulibsite-packageskeras_preprocessingimage.py in next(self)
2201 # The transformation of images is not under thread lock
2202 # so it can be done in parallel
-> 2203 return self._get_batches_of_transformed_samples(index_array)

~AppDataLocalContinuumanaconda3envstensorflow-gpulibsite-packageskeras_preprocessingimage.py in _get_batches_of_transformed_samples(self, index_array)
2160 params = self.image_data_generator.get_random_transform(x.shape)
2161 x = self.image_data_generator.apply_transform(x, params)
-> 2162 x = self.image_data_generator.standardize(x)
2163 batch_x[i] = x
2164 # optionally save augmented images to disk for debugging purposes

~AppDataLocalContinuumanaconda3envstensorflow-gpulibsite-packageskeras_preprocessingimage.py in standardize(self, x)
1117 """
1118 if self.preprocessing_function:
-> 1119 x = self.preprocessing_function(x)
1120 if self.rescale:
1121 x *= self.rescale

TypeError: 'float' object is not callable


How can I access a single batch (i.e. next batch)?



EDIT:
As pointed out by @today in the comments, using next(train_generator) should work just fine. In my case I was using the preprocess_input parameter in the ImageDataGenerator whereas I should have used the rescale parameter. Now the issue is solved!










share|improve this question
















I am using flow_from_dataframe to construct a DataFrameIterator:



datagen=ImageDataGenerator()
train_generator=datagen.flow_from_dataframe(...)

print(train_generator)
>> <keras_preprocessing.image.DataFrameIterator object at 0x00000262F5D93F60>


Now I am trying to get a single batch from this generator. Usually using next(train_generator) works on flow_from_directory generators, however this approach



x,y = next(train_generator)


and



x,y = train_generator.next


results in:



---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-48-6be8f38d3987> in <module>
----> 1 next(train_generator)

~AppDataLocalContinuumanaconda3envstensorflow-gpulibsite-packageskeras_preprocessingimage.py in __next__(self, *args, **kwargs)
1524
1525 def __next__(self, *args, **kwargs):
-> 1526 return self.next(*args, **kwargs)
1527
1528 def _get_batches_of_transformed_samples(self, index_array):

~AppDataLocalContinuumanaconda3envstensorflow-gpulibsite-packageskeras_preprocessingimage.py in next(self)
2201 # The transformation of images is not under thread lock
2202 # so it can be done in parallel
-> 2203 return self._get_batches_of_transformed_samples(index_array)

~AppDataLocalContinuumanaconda3envstensorflow-gpulibsite-packageskeras_preprocessingimage.py in _get_batches_of_transformed_samples(self, index_array)
2160 params = self.image_data_generator.get_random_transform(x.shape)
2161 x = self.image_data_generator.apply_transform(x, params)
-> 2162 x = self.image_data_generator.standardize(x)
2163 batch_x[i] = x
2164 # optionally save augmented images to disk for debugging purposes

~AppDataLocalContinuumanaconda3envstensorflow-gpulibsite-packageskeras_preprocessingimage.py in standardize(self, x)
1117 """
1118 if self.preprocessing_function:
-> 1119 x = self.preprocessing_function(x)
1120 if self.rescale:
1121 x *= self.rescale

TypeError: 'float' object is not callable


How can I access a single batch (i.e. next batch)?



EDIT:
As pointed out by @today in the comments, using next(train_generator) should work just fine. In my case I was using the preprocess_input parameter in the ImageDataGenerator whereas I should have used the rescale parameter. Now the issue is solved!







python keras






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 16:27







AaronDT

















asked Jan 3 at 16:01









AaronDTAaronDT

9672827




9672827













  • Could you please provide the full stack trace?

    – today
    Jan 3 at 16:06











  • @today I added the entire error message

    – AaronDT
    Jan 3 at 16:09











  • Could you please format it as code block and not block quote? Just copy the stack trace, paste it here and then select it and press "code sample" button in the toolbar.

    – today
    Jan 3 at 16:13











  • @today sure thing :)

    – AaronDT
    Jan 3 at 16:16






  • 1





    Thanks. It seems there is something wrong with the preprocessing_function argument you may have set when creating the ImageDataGenerator. Could you please provide the full code for that part as well?

    – today
    Jan 3 at 16:17



















  • Could you please provide the full stack trace?

    – today
    Jan 3 at 16:06











  • @today I added the entire error message

    – AaronDT
    Jan 3 at 16:09











  • Could you please format it as code block and not block quote? Just copy the stack trace, paste it here and then select it and press "code sample" button in the toolbar.

    – today
    Jan 3 at 16:13











  • @today sure thing :)

    – AaronDT
    Jan 3 at 16:16






  • 1





    Thanks. It seems there is something wrong with the preprocessing_function argument you may have set when creating the ImageDataGenerator. Could you please provide the full code for that part as well?

    – today
    Jan 3 at 16:17

















Could you please provide the full stack trace?

– today
Jan 3 at 16:06





Could you please provide the full stack trace?

– today
Jan 3 at 16:06













@today I added the entire error message

– AaronDT
Jan 3 at 16:09





@today I added the entire error message

– AaronDT
Jan 3 at 16:09













Could you please format it as code block and not block quote? Just copy the stack trace, paste it here and then select it and press "code sample" button in the toolbar.

– today
Jan 3 at 16:13





Could you please format it as code block and not block quote? Just copy the stack trace, paste it here and then select it and press "code sample" button in the toolbar.

– today
Jan 3 at 16:13













@today sure thing :)

– AaronDT
Jan 3 at 16:16





@today sure thing :)

– AaronDT
Jan 3 at 16:16




1




1





Thanks. It seems there is something wrong with the preprocessing_function argument you may have set when creating the ImageDataGenerator. Could you please provide the full code for that part as well?

– today
Jan 3 at 16:17





Thanks. It seems there is something wrong with the preprocessing_function argument you may have set when creating the ImageDataGenerator. Could you please provide the full code for that part as well?

– today
Jan 3 at 16:17












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%2f54025811%2fkeras-dataframeiterator-how-to-get-next-batch-typeerror-float-object-is-n%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%2f54025811%2fkeras-dataframeiterator-how-to-get-next-batch-typeerror-float-object-is-n%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

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas