我想要一个简单的单层神经网络,它将一个 300 个数字的向量转换为另一个 300 个数字的向量。
所以有:
print(np.array(train_in).shape)
print(np.array(train_t).shape)
返回:
(943, 300)
(943, 300)
我尝试以下操作:
model = keras.Sequential()
model.add(Dense(300, input_shape=(300,)))
model.compile(optimizer=tf.train.AdamOptimizer(),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(np.array(train_in), np.array(train_t), epochs=5)
我越来越:
ValueError: Error when checking target: expected dense_37 to have shape (1,) but got array with shape (300,)
为什么预期目标有形状(1,)?一个有 300 个单位的层应该在输出上产生一个包含 300 个数字的向量,对吗?
编辑:
根据要求,这就是我的数据的样子:
print(np.array(train_in))
print(np.array(train_t))
给出:
[[-0.13841234 0.22157902 0.12244826 ... -0.10154381 -0.01824803
-0.08607237]
[ 0.02228635 0.3353927 0.05389142 ... -0.23218463 -0.06550601
0.03365546]
[ 0.22719774 0.25478157 -0.02882686 ... -0.36675575 -0.14722016
-0.22856475]
...
[ 0.07122967 0.07579704 0.2376182 ... -0.5245226 -0.38911286
-0.5513026 ]
[-0.05494669 -0.3587228 0.13438214 ... -0.6134821 -0.06194036
-0.46365416]
[-0.16560836 -0.15729778 0.00067104 ... -0.01925305 -0.3984945
0.12297624]]
[[-0.20293862 0.27669927 0.19337481 ... -0.14366734 0.06025359
-0.1156549 ]
[-0.02273261 0.20943424 0.26937988 ... -0.20701817 -0.03191033
0.03741883]
[ 0.16326293 0.19438037 0.12544776 ... -0.37406632 -0.1527986
-0.29249507]
...
[ 0.05573128 0.26873755 0.40287578 ... -0.65253705 -0.30244952
-0.68772614]
[-0.02555208 -0.0485841 0.19109009 ... -0.2797842 -0.01007691
-0.53623134]
[-0.30828896 0.04836991 -0.108813 ... -0.20583114 -0.40019956
0.11540392]]
慕后森
相关分类