Keras 序列模型没有维度不匹配吗?
我使用 Keras 创建了一个顺序神经网络,其输入为 4,输出为 8。我意识到我所做的事情是不正确的,但我不确定为什么代码不会抛出错误。
print(X.shape) # Prints (64, 4)
print(y.shape) # Prints (64, 64, 8)
self.model.fit(X, y, batch_size=MINIBATCH_SIZE, verbose=0, shuffle=False)
那么为什么 Keras 接受数组的数组呢?它不应该只接受数组的数组吗?
编辑: 这就是我的模型的创建方式
model = Sequential()
model.add(tf.keras.layers.InputLayer(input_shape=(4,)))
model.add(Dense(64))
model.add(Dense(Env.ACTION_SPACE, activation='linear')) # Env.ACTION_SPACE = 8
model.compile(loss="mse", optimizer='adam', metrics=['accuracy'])
I created a sequential neural network with Keras that has an input of 4 and an output of 8. I realize what I did was incorrect but I'm not sure as to why the code does not throw an error.
print(X.shape) # Prints (64, 4)
print(y.shape) # Prints (64, 64, 8)
self.model.fit(X, y, batch_size=MINIBATCH_SIZE, verbose=0, shuffle=False)
So why does Keras accept an array of array of arrays? Shouldn't it only accept an array of arrays?
EDIT:
This is how my model was created
model = Sequential()
model.add(tf.keras.layers.InputLayer(input_shape=(4,)))
model.add(Dense(64))
model.add(Dense(Env.ACTION_SPACE, activation='linear')) # Env.ACTION_SPACE = 8
model.compile(loss="mse", optimizer='adam', metrics=['accuracy'])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们主要是 mariz 计算,然后通过函数扩展或减少维度,但最后一层,你可以 falttern、softmax 或总结成你想要的形状。
您可以从训练批次或预测中看到,它返回一组输出,您可以在其中选择批号大于 1 的位置,或者预测打印以查看输出结果,其中它们是您从 np.max 或 softwax 或附加网络搜索的答案堆栈的倍数。
我从这个例子中看到了你的评论
或者你也可以这样做
示例输出:
目标移动预测 ( 1 )
目标运动预测( 2)
They are mostly mariz computation then the dimension is expand or reduce by the function but the last layer, you can falttern, softmax or conclude into shape you want.
You can see from traing batch or prediction that it return set of output where you seelct batch number more than 1 or prediction print to see the output result where they are multipl of answers stacks you search from np.max or softwax or attached networks.
I saw your remarks that from this example
Or you also can do
Sample output:
Target movement prediction ( 1 )
Target movement prediction ( 2 )