Keras输入调光误差
当我在试验keras和Openai的Gym时,我不断地发现这个错误Keras输入调光误差,keras,openai-gym,Keras,Openai Gym,当我在试验keras和Openai的Gym时,我不断地发现这个错误 ValueError: Error when checking input: expected reshape_1_input to have shape (None, 979, 1) but got array with shape (979, 1, 1) 我收集的数据如下: def getData(): rewardc = 0 rewardo = 0 labels = np.array([])
ValueError: Error when checking input: expected reshape_1_input to have shape (None, 979, 1) but got array with shape (979, 1, 1)
我收集的数据如下:
def getData():
rewardc = 0
rewardo = 0
labels = np.array([])
data = np.array([])
for i in range(11):
print("run",i)
for _ in range (10000):
print("---------------------------------------------------------------------------")
print("action", _)
#env.render()
action = env.action_space.sample()
observation, reward, done, info = env.step(action)
if done:
env.reset()
break
rewardc = rewardo - reward
rewardo = reward
observationo = observation
rewardco = rewardc
ohobservation = np.array(observationo)
ohobservation = np.append(ohobservation, rewardo)
ohobservation = np.append(ohobservation, rewardco)
#print ("whole observation",ohobservation)
#print("data", data)
labelsb = np.array([action])
if labels.size == 0:
labels = labelsb
else:
labels = np.vstack((labels,action))
if data.size == 0:
data = ohobservation
else:
data = np.vstack((data, ohobservation))
return labels, data
我的x阵列将如下所示:
[ [2] [0] [2] [3] [0] [0] .. [2] [3]]
我的Y:
网络代码:
model = Sequential()
model.add(Dense(units= 64, input_dim= 100))
model.add(Activation('relu'))
model.add(Dense(units=10))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy',
optimizer='sgd',
metrics=['accuracy'])
model.fit(X,Y, epochs=5)
但我一点机会都不能在卡拉斯喂它。
如果有人能帮我解决,那就太棒了谢谢 输入 如果您的数据是979个示例,每个示例包含一个元素,请确保其第一个维度是979
print(X.shape) #confirm that the shape is (979,1) or (979,)
如果形状与此不同,则必须重塑阵列的形状,因为Dense
层需要这些形状
X = X.reshape((979,))
现在,确保致密层与该形状兼容:
#using input_dim:
Dense(units=64, input_dim=1) #each example has only one element
#or, using input_shape:
Dense(units=64, input_shape=(1,)) #input_shape must always be a tuple. Again, the number of examples shouldn't be a part of this shape
这将解决输入的问题。您得到的所有错误消息都与输入数据和您为第一层提供的输入形状之间的兼容性有关:
Error when checking input: expected reshape_1_input to have shape (None, 979, 1)
but got array with shape (979, 1, 1)
消息中的第一个形状是传递到图层的输入形状。第二个是实际数据的形状
输出
Y需要相同的兼容性,但现在是最后一层
如果在最后一层中放置units=10
,则表示标签必须是形状(979,10)
如果标签没有该形状,请调整单元格数以匹配该形状 需要查看您的网络代码可能您需要将输入数据重塑为(1979,1)
。可以@Craig.Li,但看起来输入层是一个重塑层,因此很难判断OP在没有代码添加的神经网络代码的情况下做了什么。情况2,我如何才能做到这一点?input\u shape=(1,1)
。或者更好的是,如果您的模型确实从密集层开始,只要input\u shape=(1,)
就可以了,只要x.shape=(979examples,1)
。很抱歉,在处理它时,我出现了一个错误:“ValueError:检查输入时出错:预期密集的\u 1\u输入具有形状(无,10),但得到了具有形状的数组(1234,1)”但我无法修复它。你能帮忙吗?这是在安装时发生的,因为我只能使用1层为什么将input\u shape
更改为10?它应该是(1,)
。数据的形状。我想这是因为我的X有(1),但我的Y是(10),因为一次有多个数据点
Error when checking input: expected reshape_1_input to have shape (None, 979, 1)
but got array with shape (979, 1, 1)