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

Training: ValueError: Cannot reshape a tensor #116

Open
jstaerk opened this issue Mar 9, 2024 · 1 comment
Open

Training: ValueError: Cannot reshape a tensor #116

jstaerk opened this issue Mar 9, 2024 · 1 comment

Comments

@jstaerk
Copy link

jstaerk commented Mar 9, 2024

Hi,

With this training data r2.zip
I get the following Exception:

2024-03-09 20:22:16.136873: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE SSE2 SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
Exception in thread Thread-106:
Traceback (most recent call last):
  File "C:\ProgramData\anaconda3\envs\invoicenet\lib\threading.py", line 980, in _bootstrap_inner
    self.run()
  File "C:\ProgramData\anaconda3\envs\invoicenet\lib\threading.py", line 917, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\jstaerk\workspace\InvoiceNet\invoicenet\gui\trainer.py", line 257, in _train
    train_loss = model.train_step(next(train_iter))
  File "C:\ProgramData\anaconda3\envs\invoicenet\lib\site-packages\tensorflow\python\util\traceback_utils.py", line 153, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "C:\Users\jstaerk\AppData\Local\Temp\__autograph_generated_file8m_8dtrb.py", line 12, in tf__train_step
    predictions = ag__.converted_call(ag__.ld(self).model, (ag__.ld(inputs),), dict(training=True), fscope)
  File "C:\ProgramData\anaconda3\envs\invoicenet\lib\site-packages\keras\src\utils\traceback_utils.py", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "C:\Users\jstaerk\AppData\Local\Temp\__autograph_generated_file_10s7djf.py", line 12, in tf__call
    memories = ag__.converted_call(ag__.ld(tf).sparse.reshape, (ag__.ld(memories), (-1, ag__.ld(InvoiceData).im_size[0] * ag__.ld(InvoiceData).im_size[1] * ag__.ld(InvoiceData).n_memories, ag__.ld(InvoiceData).seq_in, ag__.ld(InvoiceData).n_output)), None, fscope)
ValueError: in user code:

    File "C:\Users\jstaerk\workspace\InvoiceNet\invoicenet\acp\acp.py", line 86, in train_step  *
        predictions = self.model(inputs, training=True)
    File "C:\ProgramData\anaconda3\envs\invoicenet\lib\site-packages\keras\src\utils\traceback_utils.py", line 70, in error_handler  **
        raise e.with_traceback(filtered_tb) from None
    File "C:\Users\jstaerk\AppData\Local\Temp\__autograph_generated_file_10s7djf.py", line 12, in tf__call
        memories = ag__.converted_call(ag__.ld(tf).sparse.reshape, (ag__.ld(memories), (-1, ag__.ld(InvoiceData).im_size[0] * ag__.ld(InvoiceData).im_size[1] * ag__.ld(InvoiceData).n_memories, ag__.ld(InvoiceData).seq_in, ag__.ld(InvoiceData).n_output)), None, fscope)

    ValueError: Exception encountered when calling layer 'attend_copy_parse_model' (type AttendCopyParseModel).

    in user code:

        File "C:\Users\jstaerk\workspace\InvoiceNet\invoicenet\acp\model.py", line 168, in call  *
            memories = tf.sparse.reshape(memories,

        ValueError: Cannot reshape a tensor with -838860800 elements to shape [None, 65536, 128, 103] (-864026624 elements).


    Call arguments received by layer 'attend_copy_parse_model' (type AttendCopyParseModel):
      • inputs=('SparseTensor(indices=Tensor("inputs:0", shape=(None, 6), dtype=int64), values=Tensor("inputs_1:0", shape=(None,), dtype=float32), dense_shape=Tensor("inputs_2:0", shape=(6,), dtype=int64))', 'tf.Tensor(shape=(4, 128, 128, 3), dtype=float32)', 'tf.Tensor(shape=(4, 128, 128), dtype=int32)', 'tf.Tensor(shape=(4, 128, 128), dtype=int32)', 'tf.Tensor(shape=(4, 128, 128), dtype=int32)', 'tf.Tensor(shape=(4, 128, 128), dtype=float32)', 'tf.Tensor(shape=(4, 128, 128, 4, 2), dtype=float32)')
      • training=True
      • mask=None
@fatimaAfzaal
Copy link

I am encountering the same issue when running trainer.py with my dataset. Here's the exception I received:

F:\Invoice\.venv\Lib\site-packages\keras\src\layers\layer.py:1383:` UserWarning: Layer 'attend_copy_parse_model' looks like it has unbuilt state, but Keras is not able to trace the layer `call()` in order to build it automatically. Possible causes:
1. The `call()` method of your layer may be crashing. Try to `__call__()` the layer eagerly on some test input first to see if it works. E.g. `x = np.random.random((3, 4)); y = layer(x)`
2. If the `call()` method is correct, then you may need to implement the `def build(self, input_shape)` method on your layer. It should create all variables used by the layer (e.g. by calling `layer.build()` on all its children layers).
Exception encountered: ''Cannot reshape a tensor with -1677721600 elements to shape [None, 65536, 128, 103] (-1728053248 elements).''
warnings.warn(
F:\Invoice\.venv\Lib\site-packages\keras\src\layers\layer.py:391: UserWarning: `build()` was called on layer 'attend_copy_parse_model', however the layer does not have a `build()` method implemented and it looks like it has unbuilt state. This will cause the layer to be marked as built, despite not being actually built, which may cause failures down the line. Make sure to implement a proper `build()` method.
warnings.warn(
Exception in thread Thread-1 (_train):
Traceback (most recent call last):
File "C:\Users\Mootu & Patlu\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 1052, in _bootstrap_inner
 self.run()
File "C:\Users\Mootu & Patlu\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 989, in run
 self._target(*self._args, **self._kwargs)
File "F:\Invoice\invoicenet\gui\trainer.py", line 257, in _train
 train_loss = model.train_step(next(train_iter))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\Invoice\.venv\Lib\site-packages\tensorflow\python\util\traceback_utils.py", line 153, in error_handler
 raise e.with_traceback(filtered_tb) from None
File "C:\Users\MOOTU&~1\AppData\Local\Temp\__autograph_generated_filepi3s0otz.py", line 12, in tf__train_step
 predictions = ag__.converted_call(ag__.ld(self).model, (ag__.ld(inputs),), dict(training=True), fscope)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "F:\Invoice\.venv\Lib\site-packages\keras\src\utils\traceback_utils.py", line 122, in error_handler
 raise e.with_traceback(filtered_tb) from None
     ^^^^^^^^^^^
File "F:\Invoice\invoicenet\acp\model.py", line 168, in call
 memories = tf.sparse.reshape(memories,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: in user code:

 File "F:\Invoice\invoicenet\acp\acp.py", line 86, in train_step  *
     predictions = self.model(inputs, training=True)
 File "F:\Invoice\.venv\Lib\site-packages\keras\src\utils\traceback_utils.py", line 122, in error_handler  **
     raise e.with_traceback(filtered_tb) from None
 File "F:\Invoice\invoicenet\acp\model.py", line 168, in call
     memories = tf.sparse.reshape(memories,

 ValueError: Exception encountered when calling AttendCopyParseModel.call().
 
 Cannot reshape a tensor with -1677721600 elements to shape [None, 65536, 128, 103] (-1728053248 elements).
 
 Arguments received by AttendCopyParseModel.call():
   • inputs=('tf.Tensor(shape=(8, 128, 128, 4, 128, 103), dtype=float32)', 'tf.Tensor(shape=(8, 128, 128, 3), dtype=float32)', 'tf.Tensor(shape=(8, 128, 128), dtype=int32)', 'tf.Tensor(shape=(8, 128, 128), dtype=int32)', 'tf.Tensor(shape=(8, 128, 128), dtype=int32)', 'tf.Tensor(shape=(8, 128, 128), dtype=float32)', 'tf.Tensor(shape=(8, 128, 128, 4, 2), dtype=float32)')
   • training=True
   • mask=('None', 'None', 'None', 'None', 'None', 'None', `'None')

It seems the dataset might not be correctly structured or is missing important files. Could someone assist in providing a proper dataset or clarifying the issue?

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