Why FashionMNIST-trained resnet returns array of 1000 values?

gluon-cv
code-error

#1

Hi, I trained a resnet18_v1 on FashionMNIST
when I submit an inference request on one item of the test dataset, the result is a 1000-value array. It should be ten right? since FashionMNIST has 10 categories…
Can someone tell me what is wrong?
inference code is this:

def transform(data, label):
    return nd.transpose(data.astype(np.float32), (2,0,1))/255, label.astype(np.float32)


testset = gluon.data.vision.FashionMNIST(train=False, transform=transform)

net(testset[0][0].expand_dims(0).as_in_context(ctx))  # this is shape (1,1000). Why?

#2

my bad… I did not change class number… this fixed the pb: net = vision.get_model('resnet18_v1', pretrained=False, classes=10)


#3

Indeed, note that you can’t have a pretrained version and a custom number of classes. If you want to have pre-trained weights for the first part of your network, you need to proceed like this:

net = vision.get_model('resnet18_v1', pretrained=True, ctx=ctx)
with net.name_scope():
    net.output =  gluon.nn.Dense(10)
net.output.initialize(ctx=ctx)