Sorry to bother you!
I edit the ResNet from from torchvision.models import ResNet
, and have 2 path is the first 3 blocks, which in my code like blow
self.img_feature = nn.Sequential(
nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3,
bias=False),
nn.BatchNorm2d(64),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2, padding=1),
self._make_layer(block, 64, layers[0]),
self._make_layer(block, 128, layers[1], stride=2),
self._make_layer(block, 256, layers[2], stride=2),
)
self.flow_feature = nn.Sequential(
nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3,
bias=False),
nn.BatchNorm2d(64),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2, padding=1),
self._make_layer(block, 64, layers[0]),
self._make_layer(block, 128, layers[1], stride=2),
self._make_layer(block, 256, layers[2], stride=2),
)
and when I foward this model,
def forward(self, img1, img2, flow):
img1_fea = self.img_feature(img1)
img2_fea = self.img_feature(img2)
flow_fea = self.flow_feature(flow)
come out a error like this
RuntimeError: Given groups=1, weight[64, 1024, 1, 1], so expected input[2, 64, 56, 56] to have 1024 channels, but got 64 channels instead
but if change the foward fuction like this:
def forward(self, img1, img2, flow):
img1_fea = self.img_feature(img1)
img2_fea = self.img_feature(img2)
flow_fea = self.img_feature(flow)
and the code going well, but the result is not that I want, I’m confused.
Thank for your reply!
blow is the _make_layer
def _make_layer(self, block, planes, blocks, stride=1):
downsample = None
if stride != 1 or self.inplanes != planes * block.expansion:
downsample = nn.Sequential(
nn.Conv2d(self.inplanes, planes * block.expansion,
kernel_size=1, stride=stride, bias=False),
nn.BatchNorm2d(planes * block.expansion),
)
layers = []
layers.append(block(self.inplanes, planes, stride, downsample))
self.inplanes = planes * block.expansion
for i in range(1, blocks):
layers.append(block(self.inplanes, planes))
return nn.Sequential(*layers)