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

Is "ValueError: Dimensions must be equal" normal? #4

Open
minhnbvnu opened this issue Jan 28, 2024 · 1 comment
Open

Is "ValueError: Dimensions must be equal" normal? #4

minhnbvnu opened this issue Jan 28, 2024 · 1 comment

Comments

@minhnbvnu
Copy link

minhnbvnu commented Jan 28, 2024

Thank you for the awesome project!

I was trying to run this project on my own and ran into an issue, can you please check it out:

Epoch 1/20
in user code:

    File "/Users/nguyenbinhminh/miniconda3/envs/deepsmells/lib/python3.9/site-packages/keras/engine/training.py", line 1284, in train_function  *
        return step_function(self, iterator)
    File "/Users/nguyenbinhminh/miniconda3/envs/deepsmells/lib/python3.9/site-packages/keras/engine/training.py", line 1268, in step_function  **
        outputs = model.distribute_strategy.run(run_step, args=(data,))
    File "/Users/nguyenbinhminh/miniconda3/envs/deepsmells/lib/python3.9/site-packages/keras/engine/training.py", line 1249, in run_step  **
        outputs = model.train_step(data)
    File "/Users/nguyenbinhminh/miniconda3/envs/deepsmells/lib/python3.9/site-packages/keras/engine/training.py", line 1051, in train_step
        loss = self.compute_loss(x, y, y_pred, sample_weight)
    File "/Users/nguyenbinhminh/miniconda3/envs/deepsmells/lib/python3.9/site-packages/keras/engine/training.py", line 1109, in compute_loss
        return self.compiled_loss(
    File "/Users/nguyenbinhminh/miniconda3/envs/deepsmells/lib/python3.9/site-packages/keras/engine/compile_utils.py", line 265, in __call__
        loss_value = loss_obj(y_t, y_p, sample_weight=sw)
    File "/Users/nguyenbinhminh/miniconda3/envs/deepsmells/lib/python3.9/site-packages/keras/losses.py", line 142, in __call__
        losses = call_fn(y_true, y_pred)
    File "/Users/nguyenbinhminh/miniconda3/envs/deepsmells/lib/python3.9/site-packages/keras/losses.py", line 268, in call  **
        return ag_fn(y_true, y_pred, **self._fn_kwargs)
    File "/Users/nguyenbinhminh/miniconda3/envs/deepsmells/lib/python3.9/site-packages/keras/losses.py", line 1470, in mean_squared_error
        return backend.mean(tf.math.squared_difference(y_pred, y_true), axis=-1)

    ValueError: Dimensions must be equal, but are 700 and 714 for '{{node mean_squared_error/SquaredDifference}} = SquaredDifference[T=DT_FLOAT](model_107/dense_131/Relu, IteratorGetNext:1)' with input shapes: [?,700,1], [?,714,1].

Here are the steps:

  • I don't have a super strong computer so I created a very small subset of your ComplexMethod data ComplexMethod.zip
  • I modified autoencoder.py to run only ComplexMethod smell
  • I ran python3 autoencoder.py from program/dl_models folder

Sorry for my poor English, if you need more information please ask!

@minhnbvnu
Copy link
Author

It turns out the error comes from autoencoder_cnn
Fixed this by applying zero padding after UpSampling1D, thanks to ChatGPT
But will this affect the model?

    upsampling_factor = data.max_input_length // prev_layer.shape[1]
    # Adjust the upsampling factor and padding
    prev_layer = UpSampling1D(size=upsampling_factor)(prev_layer)
    padding = data.max_input_length - prev_layer.shape[1]
    prev_layer = ZeroPadding1D(padding=(0,padding))(prev_layer)

    prev_layer = Conv1D(1, config.kernel, activation='relu', padding='same')(prev_layer)

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

1 participant