Closed RawanRadi closed 2 years ago
changing from list to tuple in model.fit solving the error!
#before
model.fit([x_train, y_train], [y_train, x_train], batch_size=args.batch_size, epochs=args.epochs,
validation_data=[[x_test, y_test], [y_test, x_test]], callbacks=[log, tb, checkpoint, lr_decay])
#after
model.fit([x_train, y_train], [y_train, x_train], batch_size=args.batch_size, epochs=args.epochs,
validation_data=([x_test, y_test], [y_test, x_test]), callbacks=[log, tb, checkpoint, lr_decay])
excuse me , what is the difference between before and after .. i couldn't see changes ?
**ValueError: Layer model expects 2 input(s), but it received 3 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(None, None) dtype=float32>, <tf.Tensor 'IteratorGetNext:1' shape=(None, None) dtype=int32>, <tf.Tensor 'IteratorGetNext:2' shape=(None, None) dtype=float32>]**
I am Getting this Error Everytime. I tried different model and Rnn Networks but still getting this error .
`ile "F:\Major Project\Finsl Offline\Hj88\Trying\Image-Caption-Generator\train_val.py", line 81, in
C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\keras\engine\training.py:830 train_function *
return step_function(self, iterator)
C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\keras\engine\training.py:813 run_step *
outputs = model.train_step(data)
C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\keras\engine\training.py:770 train_step *
y_pred = self(x, training=True)
C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\keras\engine\base_layer.py:989 __call__ *
input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\keras\engine\input_spec.py:197 assert_input_compatibility *
raise ValueError('Layer ' + layer_name + ' expects ' +`
excuse me , what is the difference between before and after .. i couldn't see changes ?
The difference is in "validation_data" type, change it from tuple [[x_test, y_test], [y_test, x_test]], to list ([x_test, y_test], [y_test, x_test]).
model.fit([x_train, y_train], [y_train, x_train], batch_size=args.batch_size, epochs=args.epochs, validation_data=[[x_test, y_test], [y_test, x_test]], callbacks=[log, tb, checkpoint, lr_decay])
model.fit([x_train, y_train], [y_train, x_train], batch_size=args.batch_size, epochs=args.epochs, validation_data=([x_test, y_test], [y_test, x_test]), callbacks=[log, tb, checkpoint, lr_decay])
The syntax for list and tuple are different. For example: list_num = [10, 20, 30, 40] tup_num = (10, 20, 30, 40)
see more here https://www.upgrad.com/blog/list-vs-tuple/
**ValueError: Layer model expects 2 input(s), but it received 3 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(None, None) dtype=float32>, <tf.Tensor 'IteratorGetNext:1' shape=(None, None) dtype=int32>, <tf.Tensor 'IteratorGetNext:2' shape=(None, None) dtype=float32>]**
I am Getting this Error Everytime. I tried different model and Rnn Networks but still getting this error .
`ile "F:\Major Project\Finsl Offline\Hj88\Trying\Image-Caption-Generator\train_val.py", line 81, in model.fit_generator(generator_train, File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\keras\engine\training.py", line 1918, in fit_generator return self.fit( File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\keras\engine\training.py", line 1158, in fit tmp_logs = self.train_function(iterator) File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\eager\def_function.py", line 889, in call result = self._call(*args, kwds) File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\eager\def_function.py", line 933, in _call self._initialize(args, kwds, add_initializers_to=initializers) File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\eager\def_function.py", line 763, in _initialize self._stateful_fn._get_concrete_function_internal_garbage_collected( # pylint: disable=protected-access File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\eager\function.py", line 3050, in _get_concrete_function_internal_garbage_collected graphfunction, = self._maybe_define_function(args, kwargs) File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\eager\function.py", line 3444, in _maybe_define_function graph_function = self._create_graph_function(args, kwargs) File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\eager\function.py", line 3279, in _create_graph_function func_graph_module.func_graph_from_py_func( File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\framework\func_graph.py", line 999, in func_graph_from_py_func func_outputs = python_func(*func_args, func_kwargs) File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\eager\def_function.py", line 672, in wrapped_fn out = weak_wrapped_fn().wrapped*(args, kwds) File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\framework\func_graph.py", line 986, in wrapper raise e.ag_error_metadata.to_exception(e) ValueError: in user code:
C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\keras\engine\training.py:830 train_function * return step_function(self, iterator) C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\keras\engine\training.py:813 run_step * outputs = model.train_step(data) C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\keras\engine\training.py:770 train_step * y_pred = self(x, training=True) C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\keras\engine\base_layer.py:989 __call__ * input_spec.assert_input_compatibility(self.input_spec, inputs, self.name) C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\keras\engine\input_spec.py:197 assert_input_compatibility * raise ValueError('Layer ' + layer_name + ' expects ' +`
Show me your code please
for i in range(epochs): generator = data_generator(train_descriptions , train_features , tokenizer , max_length) model.fit_generator(generator , epochs = 1 , steps_perepoch = steps , verbose = 1) model.save('model'+ str(i+1) + '.h5')
I am facing the error at this step model.fit()
ValueError: Layer model_3 expects 2 input(s), but it received 3 input tensors
@Coder-Vishali i am facing the same issue, but why is this issue closed its not resolved?
Hi Durgance
It works fine in google colab. I faced this issue in a Jupyter notebook. I am not sure why it occurs.
Thank you Vishali
On Sat, Mar 19, 2022 at 11:41 PM Durgance-solytics @.***> wrote:
@Coder-Vishali https://github.com/Coder-Vishali i am facing the same issue, but whu is this issue closed ?
— Reply to this email directly, view it on GitHub https://github.com/XifengGuo/CapsNet-Keras/issues/126#issuecomment-1073056106, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOPK5S4C3DOHG2OBE2WKVCDVAYKGJANCNFSM4ZFP5BJA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you were mentioned.Message ID: @.***>
怎么解决这个问题
changing from list to tuple in model.fit solving the error!
#before model.fit([x_train, y_train], [y_train, x_train], batch_size=args.batch_size, epochs=args.epochs, validation_data=[[x_test, y_test], [y_test, x_test]], callbacks=[log, tb, checkpoint, lr_decay]) #after model.fit([x_train, y_train], [y_train, x_train], batch_size=args.batch_size, epochs=args.epochs, validation_data=([x_test, y_test], [y_test, x_test]), callbacks=[log, tb, checkpoint, lr_decay])
This solved the problem. Thanks
Excuse me, if anyone can help Here's my code:
################################
checkpointer = tf.keras.callbacks.ModelCheckpoint('model.h5', verbose=1, save_best_only=True)
callbacks = [ tf.keras.callbacks.EarlyStopping(patience=2, monitor='val_loss'), tf.keras.callbacks.TensorBoard(log_dir='logs')]
results = model.fit(x_train, y_train, validation_split=0.1, batch_size=16, epochs=25, callbacks=callbacks)
and unfortunately the previous solution didn't work out with me
At the end of the first epoch the following error raised :
ValueError: Layer model expects 2 input(s), but it received 4 input tensors.
The code also raise warnings: