Hi all, I’m working on implementing NTS-Net into fast-ai at the moment. They provide the code so I’m working off of that. When I try to train, I run into an error on the forward methods. Here is the code up to where it fails:
class attention_net(nn.Module): def __init__(self, topN=4): super(attention_net, self).__init__() self.pretrained_model = resnet.resnet50(pretrained=True) self.pretrained_model.avgpool = nn.AdaptiveAvgPool2d(1) # self.pretrained_model.fc = nn.Linear(512 * 4, 200) self.pretrained_model.fc = nn.Linear(512 * 4, FC_NUMS) self.proposal_net = ProposalNet() self.topN = topN # self.concat_net = nn.Linear(2048 * (CAT_NUM + 1), 200) self.concat_net = nn.Linear(2048 * (CAT_NUM + 1), FC_NUMS) # self.partcls_net = nn.Linear(512 * 4, 200) self.partcls_net = nn.Linear(512 * 4, FC_NUMS) _, edge_anchors, _ = generate_default_anchor_maps() self.pad_side = 224 self.edge_anchors = (edge_anchors + 224).astype(np.int) def forward(self, x): resnet_out, rpn_feature, feature = self.pretrained_model(x) x_pad = F.pad(x, (self.pad_side, self.pad_side, self.pad_side, self.pad_side), mode='constant', value=0) batch = x.size(0) # we will reshape rpn to shape: batch * nb_anchor rpn_score = self.proposal_net(rpn_feature.detach()) all_cdds = [ np.concatenate((x.reshape(-1, 1), self.edge_anchors.copy(), np.arange(0, len(x)).reshape(-1, 1)), axis=1) for x in rpn_score.data.cpu().numpy()]
The error traces back to that for statement, with
all the input array dimensions except for the concatenation axis must match exactly
When I implemented this in pure pytorch first it was training without issues so I don’t quite know what changed in fastai or what needs to be changed
Please let me know also the best practices for debugging models like this? Or lead me in that right direction if possible?
Edit: here is the source code I am using:
Again I did get this working in pytorch after some edits, I’m just trying to get it into fastai now