Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Machine learning Model.fit()ValueError:检查模型目标时出错:预期稠密_21具有形状(无,1),但获得具有形状(1708,66)的数组_Machine Learning_Tensorflow_Neural Network_Keras_Keras Layer - Fatal编程技术网

Machine learning Model.fit()ValueError:检查模型目标时出错:预期稠密_21具有形状(无,1),但获得具有形状(1708,66)的数组

Machine learning Model.fit()ValueError:检查模型目标时出错:预期稠密_21具有形状(无,1),但获得具有形状(1708,66)的数组,machine-learning,tensorflow,neural-network,keras,keras-layer,Machine Learning,Tensorflow,Neural Network,Keras,Keras Layer,这就是我正在研究的代码: from __future__ import print_function from keras.models import Sequential from keras.layers import Dense from sklearn.cross_validation import train_test_split import numpy numpy.random.seed(7) data_pixels=np.genfromtxt("pixels_dataset.c

这就是我正在研究的代码:

from __future__ import print_function
from keras.models import Sequential
from keras.layers import Dense
from sklearn.cross_validation import train_test_split
import numpy
numpy.random.seed(7)

data_pixels=np.genfromtxt("pixels_dataset.csv", delimiter=',')
classes_dataset=np.genfromtxt("labels.csv",dtype=np.str , delimiter='\t')
x_train, x_test, y_train, y_test = train_test_split(data_pixels, classes_dataset, test_size=0.3
x\u列车
的形状为
(17083072)

y\u列车
的形状为
(1708,)

y_列车的特点是:

:,:!èaäAa..Zz 0-9

我在执行以下操作后出错:

model.fit(x_train,y_train, epochs=150, batch_size=10)
错误是

ValueError: could not convert string to float: A
我尝试了以下几种选择: (一)

(二)

但我也犯了同样的错误 然后我尝试了另一种选择

from sklearn.preprocessing import LabelBinarizer
encoder = LabelBinarizer()
y_train = encoder.fit_transform(y_train)
然后我得到一个新的错误

ValueError: Error when checking model target: expected dense_21 to have shape (None, 1) but got array with shape (1708, 66)

更改以下代码行:

model.add(Dense(66, activation='softmax'))
以及:

问题在于你想要预测一个
char
,它被编码为
一个长度为66的热向量。在这种情况下-您将输出设置为所需长度,并使用
categorical\u crossentropy
loss和
softmax
激活

x_train=n.array(x_train)
y_train=n.array(y_train)
 model.fit(x_train,str(y_train), epochs=150, batch_size=10)
from sklearn.preprocessing import LabelBinarizer
encoder = LabelBinarizer()
y_train = encoder.fit_transform(y_train)
ValueError: Error when checking model target: expected dense_21 to have shape (None, 1) but got array with shape (1708, 66)
model.add(Dense(66, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])