keras-team / keras-io

Keras documentation, hosted live at keras.io
Apache License 2.0
2.78k stars 2.05k forks source link

Timeseries classification from scratch's inference result shape is different from what I expected. #1929

Open pstar0830 opened 2 months ago

pstar0830 commented 2 months ago

Issue Type

Others

Source

source

Keras Version

3.0.5

Custom Code

Yes

OS Platform and Distribution

Ubuntu 22.04.1

Python version

3.10

GPU model and memory

No response

Current Behavior?

I am following the tutorial below.

The tutorial has training and evaluation code, but not inference code, so I wrote an inference code at the end of the code to test individual inference.

res = model.predict(x_test[0])  # x_test[0].shape : (500, 1)
res.shape # is (500, 2)

I can only use single input for the predict() (not batch input), I guess due to make_model(input_shape=x_train.shape[1:]) what I don't understand is that the res.shape is (500, 2), not (2).

model.input_shape is (None, 500, 1) and model.output_shape is (None, 2)

I used (500, 1) shaped input, but why I got (500, 2) shaped output? Could someone tell me what I did wrong here?

Thank you in advance.

Standalone code to reproduce the issue or tutorial link

https://keras.io/examples/timeseries/timeseries_classification_from_scratch/

res = model.predict(x_test[0])  # x_test[0].shape : (500, 1)
res.shape # is (500, 2)

Relevant log output

No response

pstar0830 commented 2 months ago

when I use mode(x_test), it works fine. don't know why predict() doesn't work..