从Lasagne获取输出(Python深度神经网络框架)
作者:互联网
我从Lasagne的官方github加载了mnist_conv.py示例.
在and,我想预言自己的例子.我看到“ lasagne.layers.get_output()”应该处理官方文档中的numpy数组,但这是行不通的,我不知道该怎么办.
这是我的代码:
if __name__ == '__main__':
output_layer = main() #the output layer from the net
exampleChar = np.zeros((28,28)) #the example I would predict
outputValue = lasagne.layers.get_output(output_layer, exampleChar)
print(outputValue.eval())
但这给了我:
TypeError: ConvOp (make_node) requires input be a 4D tensor; received "TensorConstant{(28, 28) of 0.0}" (2 dims)
我知道它需要一个4D张量,但是我不知道如何校正它.
你能帮助我吗?谢谢
解决方法:
首先,您尝试将单个“图像”传递到您的网络中,因此它的尺寸为(256,256).
但是它需要3维数据列表,即图像,在theano中被实现为4D张量.
我没有看到完整的代码,也没有打算使用lasagne的界面,但是如果您的代码编写正确,那么到目前为止,我认为您应该先将(256,256)数据转换为一个单通道图像,例如(1,256,256),然后通过使用列表中传递的更多(1,256,256)数据创建列表,例如[(1,256,256),(1,256,256),(1,256,256)],或像[(1,256,256)]这样的单个示例列出一个列表.
前者先获得(3,1,256,256),然后再传递(1,1,256,256)4D张量,这将被lasagne接口接受.
标签:python,deep-learning,lasagne 来源: https://codeday.me/bug/20191013/1904627.html