RuntimeError: size mismatch, m1: [8 x 73728], m2: [2048 x 1000] at C:/w/1/s/windows/pytorch/aten/src\THC/generic/THCTensorMathBlas.cu:290

username: Yaqi_CAI
cooked: <p>I am using resnet-CBAM(add attention mechanism) Here are the network:</p>
<blockquote>
<p>ResNet(<br>
(conv1): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)<br>
(bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(relu): ReLU(inplace=True)<br>
(maxpool): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)<br>
(layer1): Sequential(<br>
(0): Bottleneck(<br>
(conv1): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(relu): ReLU(inplace=True)<br>
(ca): ChannelAttention(<br>
(avg_pool): AdaptiveAvgPool2d(output_size=1)<br>
(max_pool): AdaptiveMaxPool2d(output_size=1)<br>
(fc1): Conv2d(256, 16, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(relu1): ReLU()<br>
(fc2): Conv2d(16, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(sa): SpatialAttention(<br>
(conv1): Conv2d(2, 1, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(downsample): Sequential(<br>
(0): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
)<br>
)<br>
(1): Bottleneck(<br>
(conv1): Conv2d(256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(relu): ReLU(inplace=True)<br>
(ca): ChannelAttention(<br>
(avg_pool): AdaptiveAvgPool2d(output_size=1)<br>
(max_pool): AdaptiveMaxPool2d(output_size=1)<br>
(fc1): Conv2d(256, 16, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(relu1): ReLU()<br>
(fc2): Conv2d(16, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(sa): SpatialAttention(<br>
(conv1): Conv2d(2, 1, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
)<br>
(2): Bottleneck(<br>
(conv1): Conv2d(256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(relu): ReLU(inplace=True)<br>
(ca): ChannelAttention(<br>
(avg_pool): AdaptiveAvgPool2d(output_size=1)<br>
(max_pool): AdaptiveMaxPool2d(output_size=1)<br>
(fc1): Conv2d(256, 16, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(relu1): ReLU()<br>
(fc2): Conv2d(16, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(sa): SpatialAttention(<br>
(conv1): Conv2d(2, 1, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
)<br>
)<br>
(layer2): Sequential(<br>
(0): Bottleneck(<br>
(conv1): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)<br>
(bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(relu): ReLU(inplace=True)<br>
(ca): ChannelAttention(<br>
(avg_pool): AdaptiveAvgPool2d(output_size=1)<br>
(max_pool): AdaptiveMaxPool2d(output_size=1)<br>
(fc1): Conv2d(512, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(relu1): ReLU()<br>
(fc2): Conv2d(32, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(sa): SpatialAttention(<br>
(conv1): Conv2d(2, 1, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(downsample): Sequential(<br>
(0): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False)<br>
(1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
)<br>
)<br>
(1): Bottleneck(<br>
(conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(relu): ReLU(inplace=True)<br>
(ca): ChannelAttention(<br>
(avg_pool): AdaptiveAvgPool2d(output_size=1)<br>
(max_pool): AdaptiveMaxPool2d(output_size=1)<br>
(fc1): Conv2d(512, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(relu1): ReLU()<br>
(fc2): Conv2d(32, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(sa): SpatialAttention(<br>
(conv1): Conv2d(2, 1, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
)<br>
(2): Bottleneck(<br>
(conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(relu): ReLU(inplace=True)<br>
(ca): ChannelAttention(<br>
(avg_pool): AdaptiveAvgPool2d(output_size=1)<br>
(max_pool): AdaptiveMaxPool2d(output_size=1)<br>
(fc1): Conv2d(512, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(relu1): ReLU()<br>
(fc2): Conv2d(32, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(sa): SpatialAttention(<br>
(conv1): Conv2d(2, 1, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
)<br>
(3): Bottleneck(<br>
(conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(relu): ReLU(inplace=True)<br>
(ca): ChannelAttention(<br>
(avg_pool): AdaptiveAvgPool2d(output_size=1)<br>
(max_pool): AdaptiveMaxPool2d(output_size=1)<br>
(fc1): Conv2d(512, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(relu1): ReLU()<br>
(fc2): Conv2d(32, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(sa): SpatialAttention(<br>
(conv1): Conv2d(2, 1, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
)<br>
)<br>
(layer3): Sequential(<br>
(0): Bottleneck(<br>
(conv1): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)<br>
(bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(relu): ReLU(inplace=True)<br>
(ca): ChannelAttention(<br>
(avg_pool): AdaptiveAvgPool2d(output_size=1)<br>
(max_pool): AdaptiveMaxPool2d(output_size=1)<br>
(fc1): Conv2d(1024, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(relu1): ReLU()<br>
(fc2): Conv2d(64, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(sa): SpatialAttention(<br>
(conv1): Conv2d(2, 1, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(downsample): Sequential(<br>
(0): Conv2d(512, 1024, kernel_size=(1, 1), stride=(2, 2), bias=False)<br>
(1): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
)<br>
)<br>
(1): Bottleneck(<br>
(conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(relu): ReLU(inplace=True)<br>
(ca): ChannelAttention(<br>
(avg_pool): AdaptiveAvgPool2d(output_size=1)<br>
(max_pool): AdaptiveMaxPool2d(output_size=1)<br>
(fc1): Conv2d(1024, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(relu1): ReLU()<br>
(fc2): Conv2d(64, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(sa): SpatialAttention(<br>
(conv1): Conv2d(2, 1, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
)<br>
(2): Bottleneck(<br>
(conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(relu): ReLU(inplace=True)<br>
(ca): ChannelAttention(<br>
(avg_pool): AdaptiveAvgPool2d(output_size=1)<br>
(max_pool): AdaptiveMaxPool2d(output_size=1)<br>
(fc1): Conv2d(1024, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(relu1): ReLU()<br>
(fc2): Conv2d(64, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(sa): SpatialAttention(<br>
(conv1): Conv2d(2, 1, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
)<br>
(3): Bottleneck(<br>
(conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(relu): ReLU(inplace=True)<br>
(ca): ChannelAttention(<br>
(avg_pool): AdaptiveAvgPool2d(output_size=1)<br>
(max_pool): AdaptiveMaxPool2d(output_size=1)<br>
(fc1): Conv2d(1024, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(relu1): ReLU()<br>
(fc2): Conv2d(64, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(sa): SpatialAttention(<br>
(conv1): Conv2d(2, 1, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
)<br>
(4): Bottleneck(<br>
(conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(relu): ReLU(inplace=True)<br>
(ca): ChannelAttention(<br>
(avg_pool): AdaptiveAvgPool2d(output_size=1)<br>
(max_pool): AdaptiveMaxPool2d(output_size=1)<br>
(fc1): Conv2d(1024, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(relu1): ReLU()<br>
(fc2): Conv2d(64, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(sa): SpatialAttention(<br>
(conv1): Conv2d(2, 1, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
)<br>
(5): Bottleneck(<br>
(conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(relu): ReLU(inplace=True)<br>
(ca): ChannelAttention(<br>
(avg_pool): AdaptiveAvgPool2d(output_size=1)<br>
(max_pool): AdaptiveMaxPool2d(output_size=1)<br>
(fc1): Conv2d(1024, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(relu1): ReLU()<br>
(fc2): Conv2d(64, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(sa): SpatialAttention(<br>
(conv1): Conv2d(2, 1, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
)<br>
)<br>
(layer4): Sequential(<br>
(0): Bottleneck(<br>
(conv1): Conv2d(1024, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)<br>
(bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv3): Conv2d(512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn3): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(relu): ReLU(inplace=True)<br>
(ca): ChannelAttention(<br>
(avg_pool): AdaptiveAvgPool2d(output_size=1)<br>
(max_pool): AdaptiveMaxPool2d(output_size=1)<br>
(fc1): Conv2d(2048, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(relu1): ReLU()<br>
(fc2): Conv2d(128, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(sa): SpatialAttention(<br>
(conv1): Conv2d(2, 1, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(downsample): Sequential(<br>
(0): Conv2d(1024, 2048, kernel_size=(1, 1), stride=(2, 2), bias=False)<br>
(1): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
)<br>
)<br>
(1): Bottleneck(<br>
(conv1): Conv2d(2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv3): Conv2d(512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn3): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(relu): ReLU(inplace=True)<br>
(ca): ChannelAttention(<br>
(avg_pool): AdaptiveAvgPool2d(output_size=1)<br>
(max_pool): AdaptiveMaxPool2d(output_size=1)<br>
(fc1): Conv2d(2048, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(relu1): ReLU()<br>
(fc2): Conv2d(128, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(sa): SpatialAttention(<br>
(conv1): Conv2d(2, 1, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
)<br>
(2): Bottleneck(<br>
(conv1): Conv2d(2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(conv3): Conv2d(512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(bn3): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(relu): ReLU(inplace=True)<br>
(ca): ChannelAttention(<br>
(avg_pool): AdaptiveAvgPool2d(output_size=1)<br>
(max_pool): AdaptiveMaxPool2d(output_size=1)<br>
(fc1): Conv2d(2048, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(relu1): ReLU()<br>
(fc2): Conv2d(128, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
(sa): SpatialAttention(<br>
(conv1): Conv2d(2, 1, kernel_size=(7, 7), stride=(1, 1), padding=(3, 3), bias=False)<br>
(sigmoid): Sigmoid()<br>
)<br>
)<br>
)<br>
(avgpool): AvgPool2d(kernel_size=7, stride=1, padding=0)<br>
(fc): Linear(in_features=2048, out_features=1000, bias=True)<br>
)<br>
But when I run output = model(img_data) , the size mismatch problem occurs:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/a/0ab890d699e33560fb22dd3ad3e0a5b5b618eb5e.png" data-download-href="https://discuss.pytorch.org/uploads/default/0ab890d699e33560fb22dd3ad3e0a5b5b618eb5e" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/0/a/0ab890d699e33560fb22dd3ad3e0a5b5b618eb5e.png" alt="image" data-base62-sha1="1wQcIdOyXTxP1kikBQWtl81p0T4" width="690" height="473" data-dominant-color="F6F8F7"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1089×748 16.2 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
How to fix the problem?</p>
</blockquote>

username: Yaqi_CAI
cooked: <p>Besides, The model is trained:</p>
<blockquote>
<p>model = resnet_cbam.resnet50_cbam(pretrained=False)</p>
<p>model = model.to(device)</p>
<p>criterion = nn.BCEWithLogitsLoss()<br>
optimizer = torch.optim.Adam(model.parameters())</p>
</blockquote>
<p>And when i was training:</p>
<blockquote>
<p>for img_data, target in tqdm_notebook(train_loader, desc=‘Training’):<br>
img_data, target = img_data.to(device), target.to(device)</p>
<pre><code>    output = model(img_data) 

    loss = criterion(output, target) #Cross entropy loss
    c_loss = loss.data.item()
    ax1.plot(count, c_loss, 'r.')
    loss_val += c_loss
</code></pre>
</blockquote>
<p>The problem occurs as mentioned above.</p>

username: charan_Vjy
cooked: <p>You have declared the fully connected layer  as <code>Linear(in_features=2048, out_features=1000, bias=True)</code>. Do note that the linear layer will now only take inputs of size (batch_size,2048). However, the size of your input is (8,73728). You have one of two options.</p>
<ul>
<li>Modify the linear layer to take an input of 73728 - Linear(in_features=73728, out_features=1000, bias=True)</li>
<li>Modify the input ‘x’ to size (8,2048). This could be done by changing the previous layers to downsample the data. This is the <strong>recommended</strong> solution. In the previous solution, the parameter count of the fc layer would be substantially large.</li>
</ul>

username: Yaqi_CAI
cooked: <p>Hello, I just changed the img_size to (8, 2048) but it came out another problem:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/9/09e92ea1cd71d4dc76deb2e969f953f8c9388a30.png" data-download-href="https://discuss.pytorch.org/uploads/default/09e92ea1cd71d4dc76deb2e969f953f8c9388a30" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/0/9/09e92ea1cd71d4dc76deb2e969f953f8c9388a30_2_262x500.png" alt="image" data-base62-sha1="1pFT2jMq1a2Rqzc2mJ0PMNMzjeU" width="262" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/0/9/09e92ea1cd71d4dc76deb2e969f953f8c9388a30_2_262x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/0/9/09e92ea1cd71d4dc76deb2e969f953f8c9388a30_2_393x750.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/0/9/09e92ea1cd71d4dc76deb2e969f953f8c9388a30_2_524x1000.png 2x" data-dominant-color="F8F8F8"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1027×1954 129 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp:4045: error: (-215:Assertion failed) !ssize.empty() in function ‘cv::resize’</p>

username: charan_Vjy
cooked: <p>I don’t think i was clear. When I say change the input size to (8,2048), I meant the input to the Linear layer. This would mean the output of the Avg Pool layer before the input layer is (8,2048). You would have to make a lot of architectural changes to achieve this (need to downsample using max pool layers). <strong>Note that there is no need to change the input image size</strong>. Try this out ‘Modify the linear layer to take an input of 73728 - Linear(in_features=73728, out_features=1000, bias=True)’ .</p>

username: Yaqi_CAI
cooked: <p>Hello, I have <strong>modified the output of the Avg Pool layer before the input layer</strong> and now the network works, so the first solution is great. Thanks a lot!!!<br>
I also tried the second soulution of changing the input of 73728 - Linear(in_features=73728, out_features=1000, bias=True) , but it was too large and my computer cannot works.</p>

username: charan_Vjy
cooked: <p>Awesome! All the best</p>