Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Keras Target Problem
#1
The train data: 897 ndarrays (5,1980 - float64) between 0-1. The labels are binary, 0 or 1.
trainX.shape
Out[4]: (897, 5, 1980)
trainY.shape
Out[5]: (897, 1)
Model: (original code here)

model = Sequential()
model.add(Dense(1024, input_shape=(5,1980), activation="sigmoid"))
model.add(Dense(512, activation="sigmoid"))
model.add(Dense(2, activation="softmax"))

INIT_LR = 0.01
EPOCHS = 75
 
opt = SGD(lr=INIT_LR)
model.compile(loss="binary_crossentropy", optimizer=opt,
	metrics=["accuracy"])

H = model.fit(trainX, trainY, validation_data=(testX, testY),
	epochs=EPOCHS, batch_size=64)
model.summary()
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense_1 (Dense)              (None, 5, 1024)           2028544   
_________________________________________________________________
dense_2 (Dense)              (None, 5, 512)            524800    
_________________________________________________________________
dense_3 (Dense)              (None, 5, 2)              1026      
=================================================================
Total params: 2,554,370
Trainable params: 2,554,370
Non-trainable params: 0
_________________________________________________________________
Error:
Error when checking target: expected dense_3 to have 3 dimensions, but got array with shape (897, 1)
Can sby help me?

regards
inco
Quote
#2
It is definitely something wrong with the model. As far as I understood, you have binary classification problem. If you don't need
to extract specific features that accounting neighbor values (e.g. neighbor pixel colors), as it does in case of image segmentation/classification problems (when using, e.g. CNN), you likely don't need to create 2d input layer: input_shape=(5,1980); just replace this with input_shape=(5*1980, ); Further, reshape TrainX (and TestX): TrainX = TrainX.reshape(897, -1); Finally, output of the last layer has dim (len(TrainY), 2), so you need to apply keras.utils.to_categorical to TrainY, e.g. TrainY = to_categorical(TrainY) (or you can leave TrainY as is, but change dense_3 layer to Dense(1, activation="softmax").
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Error when import Keras Azadfalah 1 275 Apr-29-2020, 04:45 AM
Last Post: buran
  Keras.Predict into Dataframe Finpyth 12 618 Mar-15-2020, 06:22 PM
Last Post: Finpyth
  Keras + Matplotlib causing crash spearced 3 986 Feb-06-2020, 04:54 PM
Last Post: zljt3216
  Keras Dense layer with wrong input d1r4c 0 259 Jan-02-2020, 02:35 PM
Last Post: d1r4c
  Keras: Time series classification midarq 0 451 Sep-25-2019, 09:03 AM
Last Post: midarq
  Keras. ModuleNotFoundError: No module named 'error' agatte 1 3,271 Sep-18-2019, 12:27 PM
Last Post: shivani
  keras tensor mainpulation output to next input JohnyBeGood 0 653 Nov-21-2018, 03:30 PM
Last Post: JohnyBeGood
  Keras: tweets classicifcation kiton 0 785 Nov-14-2018, 03:19 PM
Last Post: kiton

Forum Jump:


Users browsing this thread: 1 Guest(s)