- EDIT: changed the title so maybe it gets attention.
I tried to learn how to make a simple AE using keras.
the tutorials were either for functional API, or used images as their dataset.
my data is from csv file, all loaded and in correct shape and dimensions.
the problem is when I use the following code to make a simple AE, it gives me an error:
# XandY_trn is an numpy array of shape (971, 576)
# XandY_val is an numpy array of shape (324, 576)
model = Sequential(name = 'sth')
model.add(Input(shape=(576, ), name='input'))
model.add(Dense(576)) # bottleneck layer
model.add(Dense(576, activation='sigmoid', name='output'))
print(model.summary())
model.compile(optimizer=Adam, loss='mse', metrics=['accuracy'])
model.fit(x=XandY_trn, y=XandY_trn,
validation_data=(XandY_val, XandY_val),
batch_size= 48, epochs= 50, verbose=1)
model summary:
┌─────────────────────────────────┬────────────────────────┬───────────────┐
│ Layer (type) │ Output Shape │ Param # │
├─────────────────────────────────┼────────────────────────┼───────────────┤
│ dense_26 (Dense) │ (None, 576) │ 332,352 │
├─────────────────────────────────┼────────────────────────┼───────────────┤
│ output (Dense) │ (None, 576) │ 332,352 │
└─────────────────────────────────┴────────────────────────┴───────────────┘
Total params: 664,704 (2.54 MB)
Trainable params: 664,704 (2.54 MB)
Non-trainable params: 0 (0.00 B)
None
compile is done, but fit fails with this error:
…
Epoch 1/50
Traceback (most recent call last):
File ~\miniconda3\envs\py310env\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)
File e:\win-lin\t5_dir_ae.py:133
model.fit(x=XandY_trn, y=XandY_trn,
File ~\miniconda3\envs\py310env\lib\site-packages\keras\src\utils\traceback_utils.py:123 in error_handler
raise e.with_traceback(filtered_tb) from None
File ~\miniconda3\envs\py310env\lib\site-packages\keras\src\backend\common\variables.py:191 in getitem
return self.value.getitem(idx)
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,576], [1], [1], [1] and with computed input tensors: input[1] = <576>, input[2] = <577>, input[3] = <1>.