Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'tuple' object has no attribute 'shape' when trying to run #2

Open
elapt1c opened this issue Jul 20, 2022 · 2 comments

Comments

@elapt1c
Copy link

elapt1c commented Jul 20, 2022

it wont work no matter how many times i try i still get the same error: AttributeError: 'tuple' object has no attribute 'shape'

@elapt1c
Copy link
Author

elapt1c commented Jul 20, 2022

full output:

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\keras\utils\traceback_utils.py:67, in filter_traceback..error_handler(*args, **kwargs)
65 except Exception as e: # pylint: disable=broad-except
66 filtered_tb = _process_traceback_frames(e.traceback)
---> 67 raise e.with_traceback(filtered_tb) from None
68 finally:
69 del filtered_tb

File ~\AppData\Local\Temp_autograph_generated_file3lnwlhct.py:15, in outer_factory..inner_factory..tf__train_function(iterator)
13 try:
14 do_return = True
---> 15 retval
= ag__.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope)
16 except:
17 do_return = False

AttributeError: in user code:

File "C:\Users\Owner\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\keras\engine\training.py", line 1051, in train_function  *
    return step_function(self, iterator)
File "C:\Users\Owner\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\keras\engine\training.py", line 1040, in step_function  **
    outputs = model.distribute_strategy.run(run_step, args=(data,))
File "C:\Users\Owner\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\keras\engine\training.py", line 1030, in run_step  **
    outputs = model.train_step(data)
File "C:\Users\Owner\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\keras\engine\training.py", line 894, in train_step
    return self.compute_metrics(x, y, y_pred, sample_weight)
File "C:\Users\Owner\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\keras\engine\training.py", line 987, in compute_metrics
    self.compiled_metrics.update_state(y, y_pred, sample_weight)
File "C:\Users\Owner\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\keras\engine\compile_utils.py", line 480, in update_state
    self.build(y_pred, y_true)
File "C:\Users\Owner\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\keras\engine\compile_utils.py", line 393, in build
    self._metrics = tf.__internal__.nest.map_structure_up_to(
File "C:\Users\Owner\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\keras\engine\compile_utils.py", line 526, in _get_metric_objects
    return [self._get_metric_object(m, y_t, y_p) for m in metrics]
File "C:\Users\Owner\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\keras\engine\compile_utils.py", line 526, in <listcomp>
    return [self._get_metric_object(m, y_t, y_p) for m in metrics]
File "C:\Users\Owner\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\keras\engine\compile_utils.py", line 547, in _get_metric_object
    y_t_rank = len(y_t.shape.as_list())

AttributeError: 'tuple' object has no attribute 'shape'

@mithunparab
Copy link

I resolve this issue by modifying the lstm_model.fit()
From: 👎🏻 ❌

lstm_model.fit(x=[training_encoder_input, training_decoder_input], y=[training_decoder_output],
    validation_data=([validation_encoder_input, validation_decoder_input], [validation_decoder_output]),
          batch_size=64, epochs=100)

To: 👍🏻 ✅

lstm_model.fit(x=[training_encoder_input, training_decoder_input], y=training_decoder_output,
    validation_data=([validation_encoder_input, validation_decoder_input], validation_decoder_output),
          batch_size=64, epochs=100)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants