简体   繁体   English

检查目标时出错:预期的activation_1的形状为(1,),但数组的形状为(10,)

[英]Error when checking target: expected activation_1 to have shape (1,) but got array with shape (10,)

I'm having issues with this model, which is trying to forecast stock market 10 days in the future: 我对此模型有疑问,该模型正试图在未来10天预测股市:

model = Sequential()
model.add(LSTM(input_shape=(None, INPUT_DIM), 
          units=UNROLL_LENGTH, return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(128, return_sequences=False))
model.add(Dropout(0.2))
model.add(Dense(10, activation='softmax'))
model.add(Activation('linear'))

start = time.time()
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam')
model.fit(x_train_unroll, y_train_unroll, batch_size=BATCH_SIZE,epochs=EPOCHS, verbose=2, validation_split=0.05)

The error: 错误:

ValueError: Error when checking target: expected activation_1 to have shape (1,) but got array with shape (10,) ValueError:检查目标时出错:预期activation_1的形状为(1,),但数组的形状为(10,)

Shapes of the numpy arrays: numpy数组的形状:

x_train (1968, 50, 3), y_train (1968, 10), x_test (450, 50, 3), y_test (450, 10) x_train(1968,50,3),y_train(1968,10),x_test(450,50,3),y_test(450,10)

*X_TRAIN_UNROLL*

[[[0.12339965 0.1352139  0.11937183]
[0.12231633 0.16698145 0.12354637]
[0.12261178 0.13978988 0.11837789]
 ...
[0.04057514 0.16677908 0.03448961]
[0.03998424 0.16039329 0.03439022]
[0.03407524 0.18277416 0.03906172]]


*Y_TRAIN_UNROLL*

[[0.06529447 0.06007485 0.06165058 ... 0.06342328 0.0627339 0.05465826]
 [0.06007485 0.06165058 0.06204451 ... 0.0627339  0.05465826 0.05515068]
[0.06165058 0.06204451 0.06135513 ... 0.05465826 0.05515068 0.04687808]
...
[0.68505023 0.67096711 0.66988379 ... 0.66525507 0.66289147 0.64171755]
[0.67096711 0.66988379 0.66968682 ... 0.66289147 0.64171755 0.65195982]
[0.66988379 0.66968682 0.67234587 ... 0.64171755 0.65195982 0.64250542]]

Your outputs are not sparsely encoded so you should use categorical_crossentropy as a loss function instead of sparse_categorical_crossentropy . 您的输出未经过稀疏编码,因此应使用categorical_crossentropy作为损失函数,而不是sparse_categorical_crossentropy Also, the Linear activation at the end of your model can be removed, it does nothing here. 此外,可以删除模型末尾的Linear激活,此处不执行任何操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Keras - “ValueError:检查目标时出错:预期activation_1具有形状(无,9)但得到的数组具有形状(9,1) - Keras - "ValueError: Error when checking target: expected activation_1 to have shape (None, 9) but got array with shape (9,1) keras:ValueError:检查模型目标时出错:预期activation_1具有形状(无,60),但数组的形状为(10,100) - keras: ValueError: Error when checking model target: expected activation_1 to have shape (None, 60) but got array with shape (10, 100) ValueError:检查目标时出错:预期activation_1的形状为(158,),但数组的形状为(121,) - ValueError: Error when checking target: expected activation_1 to have shape (158,) but got array with shape (121,) Keras(FIT_GENERATOR)- 检查目标时出错:预期 activation_1 具有 3 个维度,但得到的数组形状为 (32, 416, 608, 3) - Keras(FIT_GENERATOR)- Error, when checking target: expected activation_1 to have 3 dimensions, but got array with shape (32, 416, 608, 3) ValueError:检查目标时出错:预期 activation_10 有 2 个维度,但得到了形状为 (118, 50, 1) 的数组 - ValueError: Error when checking target: expected activation_10 to have 2 dimensions, but got array with shape (118, 50, 1) ValueError:检查目标时出错:预期 activation_9 具有形状 (74, 6) 但得到形状为 (75, 6) 的数组 - ValueError: Error when checking target: expected activation_9 to have shape (74, 6) but got array with shape (75, 6) 检查目标时出错:预期 activation_5 的形状为 (1,) 但得到的数组的形状为 (2,) - Error when checking target: expected activation_5 to have shape (1,) but got array with shape (2,) ValueError:检查目标时出错:预期 activation_6 具有形状(70,)但得到形状为(71,)的数组 - ValueError: Error when checking target: expected activation_6 to have shape (70,) but got array with shape (71,) ValueError:检查目标时出错:预期激活具有形状 (1,) 但得到形状为 (2,) 的数组 - ValueError: Error when checking target: expected activation to have shape (1,) but got array with shape (2,) Keras-检查目标时出错:预期activation_5具有形状(2,),但数组的形状为(1,) - Keras - Error when checking target: expected activation_5 to have shape (2,) but got array with shape (1,)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM