vaidation_data should be a tuple in keras fit_generatorKeras. ValueError: I/O operation on closed fileKeras AttributeError: 'list' object has no attribute 'ndim'LSTM with Keras: Input 'ref' of 'Assign' Op requires l-value inputError while doing reshapeInvalidArgumentError when running model.fit()IOError: [Errno 2] No such file or directory when training Keras modelfor training considering network from last layer in kerasNeural Network classificationAttributeError: 'Sequential' object has no attribute '_feed_input_names' in Keras Theano'Tensor' object has no attribute 'ndim'

Meaning of 'ran' in German?

Can the U.S. president make military decisions without consulting anyone?

Writing a letter of recommendation for a mediocre student

What's the story to "WotC gave up on fixing Polymorph"?

How is the problem, G has no triangle in Logspace?

Worms crawling under skin

Is it impolite to ask for an in-flight catalogue with no intention of buying?

What is the meaning of word 'crack' in chapter 33 of A Game of Thrones?

How can I repair this gas leak on my new range? Teflon tape isn't working

To what extent is it worthwhile to report check fraud / refund scams?

How do pilots align the HUD with their eyeballs?

How use custom order in folder on Windows 7 and 10

Is there any reason nowadays to use a neon indicator lamp instead of an LED?

What is the need of methods like GET and POST in the HTTP protocol?

Designing a time thief proof safe

What is the lowest voltage that a microcontroller can successfully read on the analog pin?

Can a broken/split chain be reassembled?

Is the mass of paint relevant in rocket design?

The 100 soldier problem

How do you use the interjection for snorting?

Type_traits *_v variable template utility order fails to compile

How can an attacker use robots.txt?

Going to France with limited French for a day

Late 1970's and 6502 chip facilities for operating systems



vaidation_data should be a tuple in keras fit_generator


Keras. ValueError: I/O operation on closed fileKeras AttributeError: 'list' object has no attribute 'ndim'LSTM with Keras: Input 'ref' of 'Assign' Op requires l-value inputError while doing reshapeInvalidArgumentError when running model.fit()IOError: [Errno 2] No such file or directory when training Keras modelfor training considering network from last layer in kerasNeural Network classificationAttributeError: 'Sequential' object has no attribute '_feed_input_names' in Keras Theano'Tensor' object has no attribute 'ndim'






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I am trying to override the keras.util.Sequence with my class SequenceGenerator(Sequence) and pass it to the fit_generator, but the fit_generator raised an error ValueError



Here is my custom class



import os
import numpy as np
from keras.utils import Sequence
from batchGenerator import BatchGenerator



from settings import batch_size, train_folder, test_folder



class SequenceGenerator(Sequence):
def __init__(self, batches_folder):
self.batch_generator = BatchGenerator(folder_name=batches_folder)
self.names = [f for f in os.listdir(batches_folder) if f.lower().endswith('.jpg')]

def __len__(self):
return int(np.ceil(len(self.names) / float(batch_size)))

def __getitem__(self, idx):
print('Getting a bacth0'.format(idx))
[X_batch, Y_batch] = self.batch_generator.load_batch_from_disk(idx)
return X_batch, Y_batch


def train_seq_genenrator():
return SequenceGenerator(train_folder)


def test_seq_generator():
return SequenceGenerator(test_folder)


and in jupyter notebook, I imported the following



from sequenceGenerator import train_seq_genenrator, test_seq_generator


finally here you are the fit_generator call



history = new_model.fit_generator(train_seq_genenrator()
, steps_per_epoch=num_train_samples // batch_size
, validation_data=test_seq_generator()
, validation_steps=num_test_samples // batch_size
, epochs=epochs
, shuffle=True)


I got the following error:



---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-63-347bef86c8c0> in <module>()
4 , validation_steps=num_test_samples // batch_size
5 , epochs=epochs
----> 6 , shuffle=True)

~Anaconda3envstensorflowlibsite-packagestensorflowpythonkerasenginetraining.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
1759 use_multiprocessing=use_multiprocessing,
1760 shuffle=shuffle,
-> 1761 initial_epoch=initial_epoch)
1762
1763 def evaluate_generator(self,

~Anaconda3envstensorflowlibsite-packagestensorflowpythonkerasenginetraining_generator.py in fit_generator(model, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
121 '`validation_data` should be a tuple '
122 '`(val_x, val_y, val_sample_weight)` '
--> 123 'or `(val_x, val_y)`. Found: ' + str(validation_data))
124 val_x, val_y, val_sample_weights = model._standardize_user_data(
125 val_x, val_y, val_sample_weight)

ValueError: `validation_data` should be a tuple `(val_x, val_y, val_sample_weight)` or `(val_x, val_y)`. Found: <sequenceGenerator.SequenceGenerator object at 0x000001DCB58259B0>


I don't know why this happens, however this found in https://keras.io/models/sequential/



validation_data: This can be either



  • a generator or a Sequence object for the validation data

  • tuple (x_val, y_val)

  • tuple (x_val, y_val, val_sample_weights)









share|improve this question
























  • What is your keras version?

    – Abhimanyu
    Mar 28 at 21:56











  • I would also try instantiating a sequence generator object when passing it to fit_generator(); rather than call it as a function that returns a sequence generator

    – Abhimanyu
    Mar 28 at 21:59












  • keras version is 2.2.0 I tried to instantiate a Sequence generator while calling fit_generator, it raised the same error.

    – N0rA
    Mar 28 at 22:07

















2















I am trying to override the keras.util.Sequence with my class SequenceGenerator(Sequence) and pass it to the fit_generator, but the fit_generator raised an error ValueError



Here is my custom class



import os
import numpy as np
from keras.utils import Sequence
from batchGenerator import BatchGenerator



from settings import batch_size, train_folder, test_folder



class SequenceGenerator(Sequence):
def __init__(self, batches_folder):
self.batch_generator = BatchGenerator(folder_name=batches_folder)
self.names = [f for f in os.listdir(batches_folder) if f.lower().endswith('.jpg')]

def __len__(self):
return int(np.ceil(len(self.names) / float(batch_size)))

def __getitem__(self, idx):
print('Getting a bacth0'.format(idx))
[X_batch, Y_batch] = self.batch_generator.load_batch_from_disk(idx)
return X_batch, Y_batch


def train_seq_genenrator():
return SequenceGenerator(train_folder)


def test_seq_generator():
return SequenceGenerator(test_folder)


and in jupyter notebook, I imported the following



from sequenceGenerator import train_seq_genenrator, test_seq_generator


finally here you are the fit_generator call



history = new_model.fit_generator(train_seq_genenrator()
, steps_per_epoch=num_train_samples // batch_size
, validation_data=test_seq_generator()
, validation_steps=num_test_samples // batch_size
, epochs=epochs
, shuffle=True)


I got the following error:



---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-63-347bef86c8c0> in <module>()
4 , validation_steps=num_test_samples // batch_size
5 , epochs=epochs
----> 6 , shuffle=True)

~Anaconda3envstensorflowlibsite-packagestensorflowpythonkerasenginetraining.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
1759 use_multiprocessing=use_multiprocessing,
1760 shuffle=shuffle,
-> 1761 initial_epoch=initial_epoch)
1762
1763 def evaluate_generator(self,

~Anaconda3envstensorflowlibsite-packagestensorflowpythonkerasenginetraining_generator.py in fit_generator(model, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
121 '`validation_data` should be a tuple '
122 '`(val_x, val_y, val_sample_weight)` '
--> 123 'or `(val_x, val_y)`. Found: ' + str(validation_data))
124 val_x, val_y, val_sample_weights = model._standardize_user_data(
125 val_x, val_y, val_sample_weight)

ValueError: `validation_data` should be a tuple `(val_x, val_y, val_sample_weight)` or `(val_x, val_y)`. Found: <sequenceGenerator.SequenceGenerator object at 0x000001DCB58259B0>


I don't know why this happens, however this found in https://keras.io/models/sequential/



validation_data: This can be either



  • a generator or a Sequence object for the validation data

  • tuple (x_val, y_val)

  • tuple (x_val, y_val, val_sample_weights)









share|improve this question
























  • What is your keras version?

    – Abhimanyu
    Mar 28 at 21:56











  • I would also try instantiating a sequence generator object when passing it to fit_generator(); rather than call it as a function that returns a sequence generator

    – Abhimanyu
    Mar 28 at 21:59












  • keras version is 2.2.0 I tried to instantiate a Sequence generator while calling fit_generator, it raised the same error.

    – N0rA
    Mar 28 at 22:07













2












2








2








I am trying to override the keras.util.Sequence with my class SequenceGenerator(Sequence) and pass it to the fit_generator, but the fit_generator raised an error ValueError



Here is my custom class



import os
import numpy as np
from keras.utils import Sequence
from batchGenerator import BatchGenerator



from settings import batch_size, train_folder, test_folder



class SequenceGenerator(Sequence):
def __init__(self, batches_folder):
self.batch_generator = BatchGenerator(folder_name=batches_folder)
self.names = [f for f in os.listdir(batches_folder) if f.lower().endswith('.jpg')]

def __len__(self):
return int(np.ceil(len(self.names) / float(batch_size)))

def __getitem__(self, idx):
print('Getting a bacth0'.format(idx))
[X_batch, Y_batch] = self.batch_generator.load_batch_from_disk(idx)
return X_batch, Y_batch


def train_seq_genenrator():
return SequenceGenerator(train_folder)


def test_seq_generator():
return SequenceGenerator(test_folder)


and in jupyter notebook, I imported the following



from sequenceGenerator import train_seq_genenrator, test_seq_generator


finally here you are the fit_generator call



history = new_model.fit_generator(train_seq_genenrator()
, steps_per_epoch=num_train_samples // batch_size
, validation_data=test_seq_generator()
, validation_steps=num_test_samples // batch_size
, epochs=epochs
, shuffle=True)


I got the following error:



---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-63-347bef86c8c0> in <module>()
4 , validation_steps=num_test_samples // batch_size
5 , epochs=epochs
----> 6 , shuffle=True)

~Anaconda3envstensorflowlibsite-packagestensorflowpythonkerasenginetraining.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
1759 use_multiprocessing=use_multiprocessing,
1760 shuffle=shuffle,
-> 1761 initial_epoch=initial_epoch)
1762
1763 def evaluate_generator(self,

~Anaconda3envstensorflowlibsite-packagestensorflowpythonkerasenginetraining_generator.py in fit_generator(model, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
121 '`validation_data` should be a tuple '
122 '`(val_x, val_y, val_sample_weight)` '
--> 123 'or `(val_x, val_y)`. Found: ' + str(validation_data))
124 val_x, val_y, val_sample_weights = model._standardize_user_data(
125 val_x, val_y, val_sample_weight)

ValueError: `validation_data` should be a tuple `(val_x, val_y, val_sample_weight)` or `(val_x, val_y)`. Found: <sequenceGenerator.SequenceGenerator object at 0x000001DCB58259B0>


I don't know why this happens, however this found in https://keras.io/models/sequential/



validation_data: This can be either



  • a generator or a Sequence object for the validation data

  • tuple (x_val, y_val)

  • tuple (x_val, y_val, val_sample_weights)









share|improve this question














I am trying to override the keras.util.Sequence with my class SequenceGenerator(Sequence) and pass it to the fit_generator, but the fit_generator raised an error ValueError



Here is my custom class



import os
import numpy as np
from keras.utils import Sequence
from batchGenerator import BatchGenerator



from settings import batch_size, train_folder, test_folder



class SequenceGenerator(Sequence):
def __init__(self, batches_folder):
self.batch_generator = BatchGenerator(folder_name=batches_folder)
self.names = [f for f in os.listdir(batches_folder) if f.lower().endswith('.jpg')]

def __len__(self):
return int(np.ceil(len(self.names) / float(batch_size)))

def __getitem__(self, idx):
print('Getting a bacth0'.format(idx))
[X_batch, Y_batch] = self.batch_generator.load_batch_from_disk(idx)
return X_batch, Y_batch


def train_seq_genenrator():
return SequenceGenerator(train_folder)


def test_seq_generator():
return SequenceGenerator(test_folder)


and in jupyter notebook, I imported the following



from sequenceGenerator import train_seq_genenrator, test_seq_generator


finally here you are the fit_generator call



history = new_model.fit_generator(train_seq_genenrator()
, steps_per_epoch=num_train_samples // batch_size
, validation_data=test_seq_generator()
, validation_steps=num_test_samples // batch_size
, epochs=epochs
, shuffle=True)


I got the following error:



---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-63-347bef86c8c0> in <module>()
4 , validation_steps=num_test_samples // batch_size
5 , epochs=epochs
----> 6 , shuffle=True)

~Anaconda3envstensorflowlibsite-packagestensorflowpythonkerasenginetraining.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
1759 use_multiprocessing=use_multiprocessing,
1760 shuffle=shuffle,
-> 1761 initial_epoch=initial_epoch)
1762
1763 def evaluate_generator(self,

~Anaconda3envstensorflowlibsite-packagestensorflowpythonkerasenginetraining_generator.py in fit_generator(model, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
121 '`validation_data` should be a tuple '
122 '`(val_x, val_y, val_sample_weight)` '
--> 123 'or `(val_x, val_y)`. Found: ' + str(validation_data))
124 val_x, val_y, val_sample_weights = model._standardize_user_data(
125 val_x, val_y, val_sample_weight)

ValueError: `validation_data` should be a tuple `(val_x, val_y, val_sample_weight)` or `(val_x, val_y)`. Found: <sequenceGenerator.SequenceGenerator object at 0x000001DCB58259B0>


I don't know why this happens, however this found in https://keras.io/models/sequential/



validation_data: This can be either



  • a generator or a Sequence object for the validation data

  • tuple (x_val, y_val)

  • tuple (x_val, y_val, val_sample_weights)






python keras training-data batchsize






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 16:42









N0rAN0rA

3321 gold badge4 silver badges22 bronze badges




3321 gold badge4 silver badges22 bronze badges















  • What is your keras version?

    – Abhimanyu
    Mar 28 at 21:56











  • I would also try instantiating a sequence generator object when passing it to fit_generator(); rather than call it as a function that returns a sequence generator

    – Abhimanyu
    Mar 28 at 21:59












  • keras version is 2.2.0 I tried to instantiate a Sequence generator while calling fit_generator, it raised the same error.

    – N0rA
    Mar 28 at 22:07

















  • What is your keras version?

    – Abhimanyu
    Mar 28 at 21:56











  • I would also try instantiating a sequence generator object when passing it to fit_generator(); rather than call it as a function that returns a sequence generator

    – Abhimanyu
    Mar 28 at 21:59












  • keras version is 2.2.0 I tried to instantiate a Sequence generator while calling fit_generator, it raised the same error.

    – N0rA
    Mar 28 at 22:07
















What is your keras version?

– Abhimanyu
Mar 28 at 21:56





What is your keras version?

– Abhimanyu
Mar 28 at 21:56













I would also try instantiating a sequence generator object when passing it to fit_generator(); rather than call it as a function that returns a sequence generator

– Abhimanyu
Mar 28 at 21:59






I would also try instantiating a sequence generator object when passing it to fit_generator(); rather than call it as a function that returns a sequence generator

– Abhimanyu
Mar 28 at 21:59














keras version is 2.2.0 I tried to instantiate a Sequence generator while calling fit_generator, it raised the same error.

– N0rA
Mar 28 at 22:07





keras version is 2.2.0 I tried to instantiate a Sequence generator while calling fit_generator, it raised the same error.

– N0rA
Mar 28 at 22:07












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/4.0/"u003ecc by-sa 4.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%2f55402856%2fvaidation-data-should-be-a-tuple-in-keras-fit-generator%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%2f55402856%2fvaidation-data-should-be-a-tuple-in-keras-fit-generator%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

Obelisk of Theodosius Contents History Description Notes Bibliography Further reading External links Navigation menuAge of spirituality : late antique and early Christian art, third to seventh centuryOver 60 picturesObelisks of the World41°00′21.24″N 28°58′31.43″E / 41.0059000°N 28.9753972°E / 41.0059000; 28.97539727724550-7235741376235741376

밀양 대씨 역사 각주 함께 보기 둘러보기 메뉴밀양 대씨

1973년 목차 사건 문화 탄생 사망 노벨상 달력 둘러보기 메뉴