Examples of transfer learning from Gluon CV Image Segmentation

I may have found a partial solution. To transfer learn on a segmentation model with a pretrained backbone, call the model directly, where one can specify the number of classes, namely (using DeepLabV3 as an example):

model = gluoncv.model_zoo.DeepLabV3(nclass=1,backbone=‘resnet101’,
pretrained_base=True, ctx=ctx)

So here the backbone is resnet101 pretrained. We call the model directly, instead of using ‘get_model()’ due to this discussion here, as we can directly state the number of classes we want.

Unfortunately, we cannot take advantage of the pretrained decoder section of the network if it was subsequently trained on say the COCO dataset.

From here you can train the model as usual. Although, I find there is trouble hybridizing the network for efficiency, so maybe leave that out if your training is resulting in a lot of errors.

One final thing, you may get a user warning about the Gradient of Parameter. Simply set

optimizer.step(batchsize, ignore_stale_grad=True)

where optimizer is an instantiation of your Trainer object.

1 Like