{"id":13627455,"url":"https://github.com/leocvml/DSOD-gluon-mxnet","last_synced_at":"2025-04-16T23:33:09.810Z","repository":{"id":217074045,"uuid":"142545990","full_name":"leocvml/DSOD-gluon-mxnet","owner":"leocvml","description":" this repo attemps to reproduce DSOD: Learning Deeply Supervised Object Detectors from Scratch use gluon reimplementation","archived":false,"fork":false,"pushed_at":"2018-08-18T09:20:22.000Z","size":48152,"stargazers_count":14,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-08T18:44:33.338Z","etag":null,"topics":["dsod","fromscratch","gluon","iccv-2017","mxnet","objectdetection"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leocvml.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-07-27T07:50:05.000Z","updated_at":"2020-02-20T07:23:27.000Z","dependencies_parsed_at":"2024-01-14T12:55:48.917Z","dependency_job_id":null,"html_url":"https://github.com/leocvml/DSOD-gluon-mxnet","commit_stats":null,"previous_names":["leocvml/dsod-gluon-mxnet"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocvml%2FDSOD-gluon-mxnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocvml%2FDSOD-gluon-mxnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocvml%2FDSOD-gluon-mxnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocvml%2FDSOD-gluon-mxnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leocvml","download_url":"https://codeload.github.com/leocvml/DSOD-gluon-mxnet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249288027,"owners_count":21244717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dsod","fromscratch","gluon","iccv-2017","mxnet","objectdetection"],"created_at":"2024-08-01T22:00:34.281Z","updated_at":"2025-04-16T23:33:07.778Z","avatar_url":"https://github.com/leocvml.png","language":"Python","funding_links":[],"categories":["\u003ca name=\"Vision\"\u003e\u003c/a\u003e2. Vision"],"sub_categories":["2.2 Object Detection"],"readme":"# DSOD-gluon-mxnet\n\n\n\nthis repo attemps to reproduce [DSOD: Learning Deeply Supervised Object Detectors from Scratch](https://arxiv.org/abs/1708.01241) use gluon reimplementation \n\n## Abstract ##\n\n**The  DSOD method is a multi-scale proposal-free detection framework similar to SSD** \n\n\nTrain detection model **from scratch**.\n\nState-of-the-art object objectors rely heavily on the off-the-shelf networks pre-trained on large-scale classification datasets like ImageNet, which incurs learning bias due to the difference on both the loss functions and the category distributions between classification and detection tasks.\n\n## quick start  (very easy) ##\n```\n1. clone (download)\n2. execution 'getpikachu.py' get dataset\n3. run 'DSOD.py' your will see result( no optimization)\n```\n## Requirements ##\n```\nmxnet 1.1.0\n```\n## Network Arch ##\n![](https://i.imgur.com/BW2ze1B.png)![](https://github.com/leocvml/DSOD-gluon-mxnet/blob/master/backbone_fisrthalf.PNG)\n```python\n####################################################\n###\n###  num of  channels in the 1st conv,\n###  num of layer in 1st conv\n###  growth rate,\n###  factor in transition layer)\n###  num_class  ( class + 1)\n###################################################\nclass DSOD(nn.HybridBlock):\n    def __init__(self,stem_filter, num_init_layer, growth_rate, factor,num_class):\n        if factor == 0.5:\n            self.factor = 2\n        else:\n            self.factor = 1\n        self.num_cls = num_class\n        self.sizes = [[.2, .2], [.37,.37],[.45,.45], [.54,.54], [.71,.71], [.88,.88]]  #\n        self.ratios = [[1,2,0.5]]*6\n        self.num_anchors = len(self.sizes[0]) + len(self.ratios[0]) - 1\n        trans1_filter = ((stem_filter * 2) + (num_init_layer * growth_rate) //self.factor )\n        super(DSOD, self).__init__()\n        self.backbone_fisrthalf = nn.HybridSequential()\n        with self.backbone_fisrthalf.name_scope():\n            self.backbone_fisrthalf.add(\n                stemblock(stem_filter),\n                DenseBlcok(6, growth_rate),\n                transitionLayer(trans1_filter),\n                DenseBlcok(8, growth_rate)\n\n            )\n        trans2_filter = ((trans1_filter) + (8 * growth_rate) //self.factor )\n        trans3_filter = ((trans2_filter) + (8 * growth_rate) //self.factor )\n\n\n        self.backbone_secondehalf = nn.HybridSequential()\n        with self.backbone_secondehalf.name_scope():\n            self.backbone_secondehalf.add(\n                transitionLayer(trans2_filter),\n                DenseBlcok(8, growth_rate),\n                transitionLayer(trans3_filter,with_pool=False),\n                DenseBlcok(8, growth_rate),\n                transitionLayer(256, with_pool=False)\n            )\n        self.PC_layer = nn.HybridSequential()   # pool -\u003e conv\n        numPC_layer =[256,256,128,128,128]\n        with self.PC_layer.name_scope():\n            for i in range(5):\n                self.PC_layer.add(\n                    pool_conv(numPC_layer[i]),\n                )\n        self.CC_layer = nn.HybridSequential() # conv1 -\u003e conv3\n        numCC_layer = [256,128,128,128]\n        with self.CC_layer.name_scope():\n            for i in range(4):\n                self.CC_layer.add(\n                    conv_conv(numCC_layer[i])\n                )\n\n        self.class_predictors = nn.HybridSequential()\n        with self.class_predictors.name_scope():\n            for _ in range(6):\n                self.class_predictors.add(\n                        cls_predictor(self.num_anchors,self.num_cls)\n                )\n\n        self.box_predictors = nn.HybridSequential()\n        with self.box_predictors.name_scope():\n            for _ in range(6):\n                self.box_predictors.add(\n                    bbox_predictor(self.num_anchors)\n                )\n\n    def flatten_prediction(self,pred):\n        return pred.transpose(axes=(0, 2, 3, 1)).flatten()\n\n    def concat_predictions(self,preds):\n        return nd.concat(*preds, dim=1)\n\n    def hybrid_forward(self, F, x):\n\n        anchors, class_preds, box_preds = [], [], []\n\n        scale_1 = self.backbone_fisrthalf(x)\n\n        anchors.append(MultiBoxPrior(\n            scale_1, sizes=self.sizes[0], ratios=self.ratios[0]))\n        class_preds.append(\n            self.flatten_prediction(self.class_predictors[0](scale_1)))\n        box_preds.append(\n            self.flatten_prediction(self.box_predictors[0](scale_1)))\n\n\n        out = self.backbone_secondehalf(scale_1)\n        PC_1 = self.PC_layer[0](scale_1)\n        scale_2 = F.concat(out,PC_1,dim=1)\n\n        anchors.append(MultiBoxPrior(\n            scale_2, sizes=self.sizes[1], ratios=self.ratios[1]))\n        class_preds.append(\n            self.flatten_prediction(self.class_predictors[1](scale_2)))\n        box_preds.append(\n            self.flatten_prediction(self.box_predictors[1](scale_2)))\n\n        scale_predict = scale_2\n        for i in range(1,5):\n\n            PC_Predict = self.PC_layer[i](scale_predict)\n            CC_Predict = self.CC_layer[i-1](scale_predict)\n            scale_predict = F.concat(PC_Predict, CC_Predict, dim=1)\n\n            anchors.append(MultiBoxPrior(\n                scale_predict, sizes=self.sizes[i+1], ratios=self.ratios[i+1]))\n            class_preds.append(\n                self.flatten_prediction(self.class_predictors[i+1](scale_predict)))\n            box_preds.append(\n                self.flatten_prediction(self.box_predictors[i+1](scale_predict)))\n\n           # print(scale_predict.shape)\n\n        anchors = self.concat_predictions(anchors)\n        class_preds = self.concat_predictions(class_preds)\n        box_preds = self.concat_predictions(box_preds)\n\n        class_preds = class_preds.reshape(shape=(0, -1, self.num_cls+1))\n\n        return anchors, class_preds, box_preds\n\nnet = nn.HybridSequential()\n####################################################\n###\n###  num of  channels in the 1st conv,\n###  num of layer in 1st conv\n###  growth rate,\n###  factor in transition layer)\n###  num_class  ( class + 1)\n###################################################\nwith net.name_scope():\n    net.add(\n        DSOD(32, 6, 48, 1, 1)  # 64 6 48 1 1 in paper\n    )\n\n```\n\n\n\n\n\n## training dataset ##\nthis repo is training on pikachu dataset\n**get pikachu dataset**\n```python\nfrom mxnet.test_utils import download\nimport os.path as osp\ndef verified(file_path, sha1hash):\n    import hashlib\n    sha1 = hashlib.sha1()\n    with open(file_path, 'rb') as f:\n        while True:\n            data = f.read(1048576)\n            if not data:\n                break\n            sha1.update(data)\n    matched = sha1.hexdigest() == sha1hash\n    if not matched:\n        print('Found hash mismatch in file {}, possibly due to incomplete download.'.format(file_path))\n    return matched\n\nurl_format = 'https://apache-mxnet.s3-accelerate.amazonaws.com/gluon/dataset/pikachu/{}'\nhashes = {'train.rec': 'e6bcb6ffba1ac04ff8a9b1115e650af56ee969c8',\n          'train.idx': 'dcf7318b2602c06428b9988470c731621716c393',\n          'val.rec': 'd6c33f799b4d058e82f2cb5bd9a976f69d72d520'}\nfor k, v in hashes.items():\n    fname = k\n    target = osp.join('data', fname)\n    url = url_format.format(k)\n    if not osp.exists(target) or not verified(target, v):\n        print('Downloading', target, url)\n        download(url, fname=fname, dirname='data', overwrite=True)\n```\n\n## how to train your own dataset  ##\n**first make your dataset to .rec \nyou can check my another repo \nhttps://github.com/leocvml/mxnet-im2rec_tutorial**\n## parameter setting  ##\n```python\n######################################################\n##\n##\n## parameter setting \n## set image size, batchsize\n## training( without retrain no inference ) : retrain =False, inference =False, epoch = number of epoch\n## training( with retrain and inference after training) : retrain =True, inference =True, inference_Data = name of image, epoch= number\n## only inference ( load weighting and inference) : retrain =True, inference =True, inference_data = name of image, epoch = 0\n#####################################################\ndata_shape = 512\nbatch_size = 4\nrgb_mean = nd.array([123, 117, 104])\nretrain = True\ninference = True\ninference_data = 'pikachu.jpg'\nepoch = 0\n```\n## result ##\n**i use pikachu dataset(from gluon tutorial) this result didn't optimization**\n**you can change anchor size ,Bigger network ,Add hidden layer,Long training time,NMS thresholding , hard negative mining etc**\n![](https://github.com/leocvml/DSOD-gluon-mxnet/blob/master/detection2.PNG)\n\n## learn more .. ##\nyou can also see these  tutorial by gluon team,\nLearn more about SSD and other detection model\n\nchinese:\nhttps://zh.gluon.ai/chapter_computer-vision/ssd.html\n\nenglish:\nhttps://gluon.mxnet.io/chapter08_computer-vision/object-detection.html\n\n\n## Note  ##\n\nthis result didn't optimization\n**fix bug on 2018/07/30**\n\n**I appreciate the author's effort in providing a nice experiment in this paper**\n\n**very thanks mxnet gluon team, they build the very nice tutorial for everyone**\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleocvml%2FDSOD-gluon-mxnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleocvml%2FDSOD-gluon-mxnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleocvml%2FDSOD-gluon-mxnet/lists"}