Object detection Transfer Learning


#1

Hi,
I’m trying to transfer-learn with yolo3_darknet53_voc
I have a train_plate.rec file with labelled example. Training SSD on SageMaker works fine so there is presumably no problem with the .rec file.
In gluoncv I’m doing the following:

train_data = gluon.data.DataLoader(
        dataset=mx.gluon.data.RecordFileDataset('train_plate.rec'),
        batch_size=32,
        shuffle=True,
        last_batch='rollover',
        num_workers=4)

ctx = [mx.cpu()]

net = gcv.model_zoo.get_model('yolo3_darknet53_voc', pretrained=True)

net.reset_class(classes)

Then calling net.collect_params().reset_ctx(ctx) returns "ValueError: Cannot reset context for Parameter 'yolov30_yolooutputv30_conv0_weight' because it has not been initialized." What is wrong?


#2

using ssd_512_vgg16_atrous_voc instead of yolo3_darknet53_voc produces no error


#3

Hey there,

My guess is that when you run net.reset_class(classes) some of the weights specifically yolov30_yolooutputv30_conv0_weight, yolov30_yolooutputv31_conv0_weight etc become uninitialized.

Taking a look at the reset_class function here: https://gluon-cv.mxnet.io/_modules/gluoncv/model_zoo/yolo/yolo3.html shows that that is indeed the case.

This line

self.prediction = nn.Conv2D(
            all_pred, kernel_size=1, padding=0, strides=1, prefix=self.prediction.prefix)

shows the creation of a new convolution layer in the reset_class function, so you’ll need to initialize the weights for that layer before you can copy to the context you want. You can use something like below to initialize the specific parameters created if you really need the reset_class function.

import mxnet as mx

import gluoncv as gcv

net.reset_class(classes)

net.collect_params('yolov30_yolooutputv.*_conv*').initialize()

net.collect_params().reset_ctx(ctx)