I want to concatenate a tensor with a number that has multiple decimal places (0.990989 etc.) basically a float.
I extract features from a pretrained network like this:
class DenseNetConv(torch.nn.Module): def __init__(self): super(DenseNetConv,self).__init__() original_model = models.densenet161(pretrained=True) self.features = torch.nn.Sequential(*list(original_model.children())[:-1]) for param in self.parameters(): param.requires_grad = False def forward(self, x): x = self.features(x) x = F.avg_pool2d(x, kernel_size=7).view(x.size(0), -1) return x
where I then define the fully connected layer like:
classifier = nn.Linear(2208 + 1, args.num_classes)
where “2208” is the number of features from the above class and the “1” is the additional score I want to concatenate:
score = score.to(device) x10 = densenet(inputs10x) x_all = torch.cat([x10, score], dim=1)
However, when I concatenate I get an error:
RuntimeError: Expected object of scalar type Float but got scalar type Double for sequence element 1 in sequence argument at position #1 'tensors'
Is the problem with the different dimensions of the score tuple and features tuple?