-2

我是深度学习库 Keras 的新手,需要您的帮助。模型构建没有错误,但在调用 model.fit(X, y) 时出现以下问题:

TypeError: ('Bad input argument to theano function with name "~/machine_learning2/lib/python2.7/site-packages/keras/backend/theano_backend.py:380"  
at index 0(0-based)', 'Wrong number of dimensions: expected 3, got 2 with shape (16, 40).')

这类似于https://github.com/fchollet/keras/issues/815 我的 y 训练矩阵是一个多行一列的矩阵。

提到的一种解决方案是使用二进制 one-hot 编码将 y 转换为 3d 张量。有这样的例子吗?

4

2 回答 2

2

您可以使用:

from keras.utils import np_utils
np_utils.to_categorical(y_train, n_classes)

对于一种热编码,其中 y_train 是训练类向量,n_classes - 类的总数,

但是,基于错误描述提到 (16, 40) 而不是 (Nx1),我怀疑您的 X 也可能有问题。

于 2016-02-24T10:01:28.697 回答
0

你在寻找这样的东西吗?

>b=np.arange(640)
>b.reshape(16,40).shape
 (16, 40)
>c=b.reshape(1,16,40)
>c.shape
 (1, 16, 40)
于 2016-02-18T09:14:16.490 回答