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;
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
add a comment
|
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
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
add a comment
|
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
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
python keras training-data batchsize
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
add a comment
|
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
add a comment
|
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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