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

Incompatible Input Shape for Model Training in Deep_Learning_HAR.ipynb #1

Open
MakaremHind opened this issue Nov 14, 2024 · 0 comments

Comments

@MakaremHind
Copy link

Incompatible Input Shape for Model Training in Deep_Learning_HAR.ipynb

Description

In the Deep_Learning_HAR.ipynb notebook, the input data shape does not match the expected input shape of the model, which can lead to an error during training. Specifically, if the model is expecting a 3D input tensor (e.g., (batch_size, time_steps, features)) but receives a 2D tensor, an error will occur during model fitting.

Symptoms

When running the notebook, the following error may be encountered during model training:

ValueError: Error when checking input: expected input_1 to have 3 dimensions, but got array with shape (batch_size, features)

Cause

This issue is likely due to:

  • Incorrect reshaping of input data during preprocessing, resulting in a shape mismatch.
  • A model architecture that requires a specific input shape that the provided data does not meet.

Suggested Solution

Check the Data Shape Before Model Training:

  • Insert a print(X_train.shape) statement right before model training to confirm the data shape.

Ensure Correct Data Reshaping:

  • Use np.reshape or another reshaping method to convert the data into the expected 3D shape, e.g., (batch_size, time_steps, features).

Adjust the Model's Input Layer (if applicable):

  • Modify the input layer of the model to match the actual data shape, if possible.

Example Fix

Assuming the model expects an input shape of (batch_size, time_steps, features), the following code snippet can help reshape the data appropriately:

# Assuming the model expects input shape (batch_size, time_steps, features)
X_train = X_train.reshape((X_train.shape[0], time_steps, features))
X_test = X_test.reshape((X_test.shape[0], time_steps, features))

Verification Steps

Run the Notebook:

  • Execute all cells in sequence to check if any errors occur during execution.

Inspect Error Logs:

  • If an error is encountered, examine the traceback to identify the exact source of the problem.

Conclusion

If this input shape mismatch is indeed the issue, applying the suggested fix should resolve it. Please try running the code with this fix and verify if the problem is resolved. Further modifications may be needed if the issue persists.

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