Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua 馈送图像时torch7大小不匹配_Lua_Neural Network_Conv Neural Network_Torch_Torchnet - Fatal编程技术网

Lua 馈送图像时torch7大小不匹配

Lua 馈送图像时torch7大小不匹配,lua,neural-network,conv-neural-network,torch,torchnet,Lua,Neural Network,Conv Neural Network,Torch,Torchnet,我正在尝试用torch7中的神经网络做一些事情。但是,当我运行代码时,我得到了错误/home/thijser/torch/install/share/lua/5.1/nn/Linear.lua:57:tutorch-scm-1-6477/cutorch/lib/THC/generic/THCTensorMathBlas.cu:52处的大小不匹配 下面是代码(或者至少是出现问题的最小示例) 以及完整的错误日志 /home/thijser/torch/install/bin/luajit: /hom

我正在尝试用torch7中的神经网络做一些事情。但是,当我运行代码时,我得到了错误
/home/thijser/torch/install/share/lua/5.1/nn/Linear.lua:57:tutorch-scm-1-6477/cutorch/lib/THC/generic/THCTensorMathBlas.cu:52处的大小不匹配

下面是代码(或者至少是出现问题的最小示例)

以及完整的错误日志

/home/thijser/torch/install/bin/luajit: /home/thijser/torch/install/share/lua/5.1/nn/Container.lua:67: 
In 39 module of nn.Sequential:
/home/thijser/torch/install/share/lua/5.1/nn/Linear.lua:57: size mismatch at /tmp/luarocks_cutorch-scm-1-6477/cutorch/lib/THC/generic/THCTensorMathBlas.cu:52
stack traceback:
    [C]: in function 'addmv'
    /home/thijser/torch/install/share/lua/5.1/nn/Linear.lua:57: in function </home/thijser/torch/install/share/lua/5.1/nn/Linear.lua:53>
    [C]: in function 'xpcall'
    /home/thijser/torch/install/share/lua/5.1/nn/Container.lua:63: in function 'rethrowErrors'
    /home/thijser/torch/install/share/lua/5.1/nn/Sequential.lua:44: in function 'forward'
    temp.lua:24: in function 'main'
    temp.lua:37: in main chunk
    [C]: in function 'dofile'
    ...jser/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
    [C]: at 0x5599d0cfa470

WARNING: If you see a stack trace below, it doesn't point to the place where this error occurred. Please use only the one above.
stack traceback:
    [C]: in function 'error'
    /home/thijser/torch/install/share/lua/5.1/nn/Container.lua:67: in function 'rethrowErrors'
    /home/thijser/torch/install/share/lua/5.1/nn/Sequential.lua:44: in function 'forward'
    temp.lua:24: in function 'main'
    temp.lua:37: in main chunk
    [C]: in function 'dofile'
    ...jser/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
    [C]: at 0x5599d0cfa470
print(cnn)
给出

nn.Sequential {
  [input -> (1) -> (2) -> (3) -> (4) -> (5) -> (6) -> (7) -> (8) -> (9) -> (10) -> (11) -> (12) -> (13) -> (14) -> (15) -> (16) -> (17) -> (18) -> (19) -> (20) -> (21) -> (22) -> (23) -> (24) -> (25) -> (26) -> (27) -> (28) -> (29) -> (30) -> (31) -> (32) -> (33) -> (34) -> (35) -> (36) -> (37) -> (38) -> (39) -> (40) -> (41) -> (42) -> (43) -> (44) -> (45) -> (46) -> output]
  (1): nn.SpatialConvolution(3 -> 64, 3x3, 1,1, 1,1)
  (2): nn.ReLU
  (3): nn.SpatialConvolution(64 -> 64, 3x3, 1,1, 1,1)
  (4): nn.ReLU
  (5): nn.SpatialMaxPooling(2x2, 2,2)
  (6): nn.SpatialConvolution(64 -> 128, 3x3, 1,1, 1,1)
  (7): nn.ReLU
  (8): nn.SpatialConvolution(128 -> 128, 3x3, 1,1, 1,1)
  (9): nn.ReLU
  (10): nn.SpatialMaxPooling(2x2, 2,2)
  (11): nn.SpatialConvolution(128 -> 256, 3x3, 1,1, 1,1)
  (12): nn.ReLU
  (13): nn.SpatialConvolution(256 -> 256, 3x3, 1,1, 1,1)
  (14): nn.ReLU
  (15): nn.SpatialConvolution(256 -> 256, 3x3, 1,1, 1,1)
  (16): nn.ReLU
  (17): nn.SpatialConvolution(256 -> 256, 3x3, 1,1, 1,1)
  (18): nn.ReLU
  (19): nn.SpatialMaxPooling(2x2, 2,2)
  (20): nn.SpatialConvolution(256 -> 512, 3x3, 1,1, 1,1)
  (21): nn.ReLU
  (22): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
  (23): nn.ReLU
  (24): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
  (25): nn.ReLU
  (26): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
  (27): nn.ReLU
  (28): nn.SpatialMaxPooling(2x2, 2,2)
  (29): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
  (30): nn.ReLU
  (31): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
  (32): nn.ReLU
  (33): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
  (34): nn.ReLU
  (35): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
  (36): nn.ReLU
  (37): nn.SpatialMaxPooling(2x2, 2,2)
  (38): nn.View(-1)
  (39): nn.Linear(25088 -> 4096)
  (40): nn.ReLU
  (41): nn.Dropout(0.500000)
  (42): nn.Linear(4096 -> 4096)
  (43): nn.ReLU
  (44): nn.Dropout(0.500000)
  (45): nn.Linear(4096 -> 1000)
  (46): nn.SoftMax
}
打印(targetImage\u caffe:size())
给我

    3
  660
 1045
[torch.LongStorage of size 3]

有人知道怎么解决这个问题或者我做错了什么吗

问题在于,您使用的VGG19的设计目的是提供
224x224
图像。由于您使用的是
660 x 1045
图像(这通常很奇怪,因为大多数convnet使用的是平方图像),因此模块39出现错误(您可以在堆栈跟踪中看到),因为您希望将具有25088个输入维的线性模块应用到张量,而张量现在大约有327680个值(每个池层粗略地将图像的大小除以4,就有512个特征贴图)


因此,解决方案是使用
224x224
图像。因此,在5个池层之后,您将有一个尺寸为(224/2^5)x(224/2^5)x 512=25088的图像。

您能给我们
print(cnn)
print(targetImage\u caffe:size())
的输出吗?@fonx我已经添加了信息。
nn.Sequential {
  [input -> (1) -> (2) -> (3) -> (4) -> (5) -> (6) -> (7) -> (8) -> (9) -> (10) -> (11) -> (12) -> (13) -> (14) -> (15) -> (16) -> (17) -> (18) -> (19) -> (20) -> (21) -> (22) -> (23) -> (24) -> (25) -> (26) -> (27) -> (28) -> (29) -> (30) -> (31) -> (32) -> (33) -> (34) -> (35) -> (36) -> (37) -> (38) -> (39) -> (40) -> (41) -> (42) -> (43) -> (44) -> (45) -> (46) -> output]
  (1): nn.SpatialConvolution(3 -> 64, 3x3, 1,1, 1,1)
  (2): nn.ReLU
  (3): nn.SpatialConvolution(64 -> 64, 3x3, 1,1, 1,1)
  (4): nn.ReLU
  (5): nn.SpatialMaxPooling(2x2, 2,2)
  (6): nn.SpatialConvolution(64 -> 128, 3x3, 1,1, 1,1)
  (7): nn.ReLU
  (8): nn.SpatialConvolution(128 -> 128, 3x3, 1,1, 1,1)
  (9): nn.ReLU
  (10): nn.SpatialMaxPooling(2x2, 2,2)
  (11): nn.SpatialConvolution(128 -> 256, 3x3, 1,1, 1,1)
  (12): nn.ReLU
  (13): nn.SpatialConvolution(256 -> 256, 3x3, 1,1, 1,1)
  (14): nn.ReLU
  (15): nn.SpatialConvolution(256 -> 256, 3x3, 1,1, 1,1)
  (16): nn.ReLU
  (17): nn.SpatialConvolution(256 -> 256, 3x3, 1,1, 1,1)
  (18): nn.ReLU
  (19): nn.SpatialMaxPooling(2x2, 2,2)
  (20): nn.SpatialConvolution(256 -> 512, 3x3, 1,1, 1,1)
  (21): nn.ReLU
  (22): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
  (23): nn.ReLU
  (24): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
  (25): nn.ReLU
  (26): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
  (27): nn.ReLU
  (28): nn.SpatialMaxPooling(2x2, 2,2)
  (29): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
  (30): nn.ReLU
  (31): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
  (32): nn.ReLU
  (33): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
  (34): nn.ReLU
  (35): nn.SpatialConvolution(512 -> 512, 3x3, 1,1, 1,1)
  (36): nn.ReLU
  (37): nn.SpatialMaxPooling(2x2, 2,2)
  (38): nn.View(-1)
  (39): nn.Linear(25088 -> 4096)
  (40): nn.ReLU
  (41): nn.Dropout(0.500000)
  (42): nn.Linear(4096 -> 4096)
  (43): nn.ReLU
  (44): nn.Dropout(0.500000)
  (45): nn.Linear(4096 -> 1000)
  (46): nn.SoftMax
}
    3
  660
 1045
[torch.LongStorage of size 3]