Answers.Body: <p>there was an untraceable mistake in one of my Dense layers, and that was I creating the layer and passed the argument <em>kernel_regularizer=HeNormal()</em>, instead of <em>kernel_initializer=HeNormal()</em>
  wasted 3 days of tweaking everything, while every time I was reading that line of code I just read it as <em>initializer</em> automatically.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-03-22T11:00:05.580Z
Answers.LastActivityDate: 2024-03-22T11:00:05.580Z
Answers.UserDisplayName: Bikay
Body: <p>this is the most simple model I can think of for my data yet I can't use the fit function, it gives an error.</p>
  <p>the desired procedure is to make a simple autoencoder : from 576 nodes to 64 then back to 576</p>
  <p>why this doesn't work ?</p>
  <pre><code>model = Sequential(name = 'sth')
  model.add(Input(shape=(576,)))
  model.add(Dense(576, activation='relu')
  model.add(Dense(64, activation='relu') #bottleneck
  model.add(Dense(576, activation='sigmoid')
  </code></pre>
  <p>model summary gives :</p>
  <pre><code>┌─────────────────────────────────┬────────────────────────┬───────────────┐
  │ Layer (type)                    │ Output Shape           │       Param # │
  ├─────────────────────────────────┼────────────────────────┼───────────────┤
  │ input (Dense)                   │ (None, 576)            │       332,352 │
  ├─────────────────────────────────┼────────────────────────┼───────────────┤
  │ dense_4 (Dense)                 │ (None, 64)             │        36,928 │
  ├─────────────────────────────────┼────────────────────────┼───────────────┤
  │ output (Dense)                  │ (None, 576)            │        37,440 │
  └─────────────────────────────────┴────────────────────────┴───────────────┘
   Total params: 406,720 (1.55 MB)
   Trainable params: 406,720 (1.55 MB)
   Non-trainable params: 0 (0.00 B)
  </code></pre>
  <p>then compile and then fit :</p>
  <pre><code>model.compile(optimizer='adam', loss='mse', metrics=['accuracy'])
  model.fit(x=Xdata, y=Xdata, validation_data=(X_val, X_val),
            batch_size= 32, epochs= 50)
  </code></pre>
  <p>the Xdata and X_val are numpy arrays of shape (900, 576) and (100, 576) respectively</p>
  <p>gives this error :</p>
  <p><strong>ValueError</strong>: slice index 576 of dimension 0 out of bounds. for '{{node strided_slice_576}} = StridedSlice[Index=DT_INT32, T=DT_FLOAT, begin_mask=0, ellipsis_mask=0, end_mask=0, new_axis_mask=0, shrink_axis_mask=1](ReadVariableOp_576, strided_slice_576/stack, strided_slice_576/stack_1, strided_slice_576/stack_2)' with input shapes: [576,64], [1], [1], [1] and with computed input tensors: input[1] = &lt;576&gt;, input[2] = &lt;577&gt;, input[3] = &lt;1&gt;.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-03-19T12:58:16.147Z
Comments.Text: This stack exchange is for the discussion of AI.  This is likely a programming issue and should probably be asked on stack overflow.
Comments.UserDisplayName: foreverska
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-03-21T15:08:28.977Z
Comments.Text: Dense layer expects 1-D inputs. Your data seems to be 2-D.
Comments.UserDisplayName: Robert
Tags: <training><keras><autoencoders>
Title: model.fit fails using keras sequential (slice index ### of dimension 0 out of bounds)
UserDisplayName: Bikay
ThreadText: # model.fit fails using keras sequential (slice index ### of dimension 0 out of bounds)
  
  (Asked by: username_0 on 2024-03-19)
  
  this is the most simple model I can think of for my data yet I can't use the fit function, it gives an error.
  the desired procedure is to make a simple autoencoder : from 576 nodes to 64 then back to 576
  why this doesn't work ?
  model = Sequential(name = 'sth')
  model.add(Input(shape=(576,)))
  model.add(Dense(576, activation='relu')
  model.add(Dense(64, activation='relu') #bottleneck
  model.add(Dense(576, activation='sigmoid')
  
  model summary gives :
  ┌─────────────────────────────────┬────────────────────────┬───────────────┐
  │ Layer (type)                    │ Output Shape           │       Param # │
  ├─────────────────────────────────┼────────────────────────┼───────────────┤
  │ input (Dense)                   │ (None, 576)            │       332,352 │
  ├─────────────────────────────────┼────────────────────────┼───────────────┤
  │ dense_4 (Dense)                 │ (None, 64)             │        36,928 │
  ├─────────────────────────────────┼────────────────────────┼───────────────┤
  │ output (Dense)                  │ (None, 576)            │        37,440 │
  └─────────────────────────────────┴────────────────────────┴───────────────┘
   Total params: 406,720 (1.55 MB)
   Trainable params: 406,720 (1.55 MB)
   Non-trainable params: 0 (0.00 B)
  
  then compile and then fit :
  model.compile(optimizer='adam', loss='mse', metrics=['accuracy'])
  model.fit(x=Xdata, y=Xdata, validation_data=(X_val, X_val),
            batch_size= 32, epochs= 50)
  
  the Xdata and X_val are numpy arrays of shape (900, 576) and (100, 576) respectively
  gives this error :
  ValueError: slice index 576 of dimension 0 out of bounds. for '{{node strided_slice_576}} = StridedSlice[Index=DT_INT32, T=DT_FLOAT, begin_mask=0, ellipsis_mask=0, end_mask=0, new_axis_mask=0, shrink_axis_mask=1](ReadVariableOp_576, strided_slice_576/stack, strided_slice_576/stack_1, strided_slice_576/stack_2)' with input shapes: [576,64], [1], [1], [1] and with computed input tensors: input[1] = <576>, input[2] = <577>, input[3] = <1>.
  
  **Tags:** training, keras, autoencoders
  > **Comments:**
  > **username_1**: This stack exchange is for the discussion of AI.  This is likely a programming issue and should probably be asked on stack overflow.  
  > **username_2**: Dense layer expects 1-D inputs. Your data seems to be 2-D.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2024-03-22. Score: 0 | Accepted answer
  
  there was an untraceable mistake in one of my Dense layers, and that was I creating the layer and passed the argument *kernel\_regularizer=HeNormal()*, instead of *kernel\_initializer=HeNormal()*
  wasted 3 days of tweaking everything, while every time I was reading that line of code I just read it as *initializer* automatically.
  
  
  ---
  
  