Python Keras:批次大小的类型错误
我使用Keras(与python3.6一起)来预测数组的输出(x_测试),但是我得到了一个TypeError作为回报 以下是我的预测代码:Python Keras:批次大小的类型错误,python,machine-learning,neural-network,deep-learning,keras,Python,Machine Learning,Neural Network,Deep Learning,Keras,我使用Keras(与python3.6一起)来预测数组的输出(x_测试),但是我得到了一个TypeError作为回报 以下是我的预测代码: x_test = [[8],[6],[0],[2],[0],[0],[0],[0],[112.128],[0],[0],[2],[0],[1],[1],[2],[2]] prediction = model.predict(model, x_test, batch_size = 32, verbose = 1) 下面是我得到的错误: TypeError
x_test = [[8],[6],[0],[2],[0],[0],[0],[0],[112.128],[0],[0],[2],[0],[1],[1],[2],[2]]
prediction = model.predict(model, x_test, batch_size = 32, verbose = 1)
下面是我得到的错误:
TypeError Traceback (most recent call last)
<ipython-input-14-286495dc15a7> in <module>()
1 x_test = [[8],[6],[0],[2],[0],[0],[0],[0],[112.128],[0],[0],[2],[0],[1],[1],[2],[2]]
2
----> 3 prediction = model.predict(model, x_test, batch_size =(17,1), verbose = 1)
TypeError: predict() got multiple values for argument 'batch_size'
非常感谢 您不需要在
model.predict
中传递model
参数,因为predict的默认值是predict(self,x,batch_size=32,verbose=0)
哪个模型由self
自动定义
因此,您的代码应该如下所示:
prediction = model.predict(x_test, batch_size = 32, verbose = 1)
根据文档,x
应该是numpy.array
而不是列表
论据:
x:输入数据,作为Numpy数组
批量大小:整数
详细:详细模式,0或1
这意味着x_测试
应改为:
x_test = np.array([[8],[6],[0],[2],[0],[0],[0],[0],[112.128],[0],[0],[2],[0],[1],[1],[2],[2]])
此答案缺少说明为什么您发布的代码是此问题的答案。
x_test = np.array([[8],[6],[0],[2],[0],[0],[0],[0],[112.128],[0],[0],[2],[0],[1],[1],[2],[2]])
prediction = model.predict(x_test, batch_size = 32, verbose = 1)