I have a model that trained on to predict one of the 14 class,
But when I go for prediction for a single image,
imageData = Image.open(pathImageFile).convert('RGB')
imageData = self.transformSequence(imageData)
imageData = imageData.unsqueeze_(0)
input = torch.autograd.Variable(imageData)
self.model.cuda()
output = self.model(input.cuda())
The output shape is [1,1024,7,7].
Very very weird than Keras predict. how can I know the output label???
the output isn’t a prediction, it’s just a feature map of size NCHW
, you need to add MaxPooling/Linear layers to do classification.
After forward passing it should be outputting the class prediction, as it contains,
features = self.features(x)
out = F.relu(features, inplace=True)
out = F.adaptive_avg_pool2d(out, (1, 1)).view(features.size(0), -1)
out = self.classifier(out)
return out
But it returning the same shape.
Code:
import os
import numpy as np
import torch
import torch.nn as nn
import torch.backends.cudnn as cudnn
import torchvision.transforms as transforms
from torch.utils.data import DataLoader
from sklearn.metrics import roc_auc_score
import torchvision
class DenseNet121(nn.Module):
def __init__(self, classCount, isTrained):
super(DenseNet121, self).__init__()
self.densenet121 = torchvision.models.densenet121(pretrained=isTrained)
This file has been truncated. show original