Get output from Lasagne (python deep neural network framework)

后端 未结 2 762
伪装坚强ぢ
伪装坚强ぢ 2021-01-24 05:23

I loaded the mnist_conv.py example from official github of Lasagne.

At the and, I would like to predict my own example. I saw that \"lasagne.layers.get_output()\" should

2条回答
  •  礼貌的吻别
    2021-01-24 05:50

    As written in your error message, the input is expected to be a 4D tensor, of shape (n_samples, n_channel, width, height). In the MNIST case, n_channels is 1, and width and height are 28.

    But you are inputting a 2D tensor, of shape (28, 28). You need to add new axes, which you can do with exampleChar = exampleChar[None, None, :, :]

    exampleChar = np.zeros(28, 28)
    print exampleChar.shape 
    exampleChar = exampleChar[None, None, :, :]
    print exampleChar.shape
    

    outputs

    (28, 28)
    (1, 1, 28, 28)
    

    Note: I think you can use np.newaxis instead of None to add an axis. And exampleChar = exampleChar[None, None] should work too.

提交回复
热议问题