# C1W2, Can't compile the student's code. Error when checking input: expected dense\_Dense1\_input to have 2 dimensions, but got array with shape (None, 28, 28, 1)

**URL:** <https://community.deeplearning.ai/t/c1w2-cant-compile-the-students-code-error-when-checking-input-expected-dense-dense1-input-to-have-2-dimensions-but-got-array-with-shape-none-28-28-1/721251>\
**Category:** Browser-based Models with TensorFlow.js\
**Tags:** week-module-2\
**Created:** [November 11, 2024, 1:46am UTC](https://community.deeplearning.ai/t/c1w2-cant-compile-the-students-code-error-when-checking-input-expected-dense-dense1-input-to-have-2-dimensions-but-got-array-with-shape-none-28-28-1/721251 "2024-11-11T01:46:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aryashidika](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@aryashidika](https://community.deeplearning.ai/u/aryashidika)\
**Post date:** [November 11, 2024, 1:46am UTC](https://community.deeplearning.ai/t/c1w2-cant-compile-the-students-code-error-when-checking-input-expected-dense-dense1-input-to-have-2-dimensions-but-got-array-with-shape-none-28-28-1/721251/1 "2024-11-11T01:46:35Z")

</div>

I get an error message when i submit my submission in week 2. It says that ‘Can’t compile the student’s code. Error when checking input: expected dense\_Dense1\_input to have 2 dimensions, but got array with shape (None, 28, 28, 1)’

My code:  
model.add(tf.layers.conv2d({ inputShape: [28, 28, 1], kernelSize: 3, filters: 8, activation: ‘relu’}));

What is the caused of the error? Can anyone help me to overcome this error?

---

<div class="post-metadata">

**Author:** ![gent.spah](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/gent.spah/32/136423_2.png) [@gent.spah](https://community.deeplearning.ai/u/gent.spah)\
**Post date:** [November 11, 2024, 6:38am UTC](https://community.deeplearning.ai/t/c1w2-cant-compile-the-students-code-error-when-checking-input-expected-dense-dense1-input-to-have-2-dimensions-but-got-array-with-shape-none-28-28-1/721251/2 "2024-11-11T06:38:56Z")

</div>

Try adding a `Flatten` layer after the convolutional layers to convert the 4D output into a 2D shape. This will flatten the spatial dimensions (height and width) into a single dimension.
