Giter VIP home page Giter VIP logo

centernet_pro_max's Introduction

CenterNet Pro Max

updates. code deprecation!!! due some internal issue, this code is close-source, sorry for it!!

For anybody wanna ask/consult/obtain any resource of CenterNet_Pro_Max I'd like to help u even though we close-source this version. Also welcome community join this dicuss platform to talk about AI:

http://t.manaai.cn

why this name? Because this repo based on centernet-better while there was somebody opensource another implementation which called centernet-better-plus, so that we have to using this name: centernet_pro_max.

this repo is the reconstruct of original CenterNet. Unlike most implementation base on detectron2 or mmdetection, highly modulized code base makes users hard to understand what's the basic idea going on. So in this repo, we make it as simply as possible, and let you can customized any idea or any new architecture you have.

This version build upon Centernet-Better, but unlike original repo, we provide something else:

  • Without any lib (not based on detectron2 or based on dl_lib), it's just single folder contains some modeling scripts;
  • Train is more intuitive, you can follow train.py and centernet.py to debug your own model architecture and experiments on your own losses or heads;
  • We provide demo scripts to detect and visualize;
  • We ported DCN from mmdetection with latest updates (this part is not like centernet-better);
  • We provide single GPU training settings (for some smaller datasets 1 GPU is enough, also you can using 8 GPUs as well);
  • We will provide onnx export.
  • We will provide onnx export and TensorRT inference;
  • More backbones such as Vovnets;
  • More heads such as 3D and mask and CenterFace;
  • CenterFace model ready;

Please start and fork and watching this repo to subscribe latest updates!

Updates

  • 2050.01.01: more news to come;

  • 2020.03.25: Help wanted!

    Currently export onnx requires this function:

    def gather_feature(fmap, index, mask=None, use_transform=False):
        if use_transform:
            # change a (N, C, H, W) tenor to (N, HxW, C) shape
            batch, channel = fmap.shape[:2]
            fmap = fmap.view(batch, channel, -1).permute((0, 2, 1)).contiguous()
    
        dim = fmap.size(-1)
        index  = index.unsqueeze(len(index.shape)).expand(*index.shape, dim)
        fmap = fmap.gather(dim=1, index=index)
        if mask is not None:
            # this part is not called in Res18 dcn COCO
            mask = mask.unsqueeze(2).expand_as(fmap)
            fmap = fmap[mask]
            fmap = fmap.reshape(-1, dim)
        return fmap

    Which will involved OneHot op in onnx, is there way to avoid it? Anyone knows why probably can open an issue and PR are welcome!

  • 2020.03.24: Training on any coco like dataset:

    register_coco_instances('coco_tl', {}, './datasets/coco_tl/annotations/instances_train2017.json', './datasets/coco_tl/images')
    MetadataCatalog.get("coco_tl").thing_classes = categories
    

    Using 2 line of codes, you can train your custom dataset freely! More example see our train_tl.py.

  • 2020.03.23: We have supported ONNX export! Now this exported onnx is an experimental support since we merged all post process into onnx, there may be some unsupported op in other frameworks. here is current onnx model ops:

    > onnxexp centernet_r50_coco.onnx summary
    Exploring on onnx model: centernet_r50_coco.onnx
    ONNX model sum on: centernet_r50_coco.onnx
    
    
    -------------------------------------------
    ir version: 6
    opset_import: 9 
    producer_name: pytorch
    doc_string: 
    all ops used: Constant,Gather,Shape,Cast,Or,Add,Unsqueeze,Concat,Reshape,ConstantOfShape,Mul,Equal,Where,Expand,NonZero,Transpose,Squeeze,Slice,ATen,Conv,BatchNormalization,Relu,MaxPool,ConvTranspose,Sigmoid,TopK,Flatten,Div
    -------------------------------------------
    

    Be note that, Nonzero not supported by onnx2trt, we will polish onnx model make it simply enough to deploy!

    Also, we have support a custom dataset training which is nuScenes! Checkout our codes to try yourself!

  • 2020.03.21: Thanks for issue: #3 pointed out, gaussian radius calculate method has been updated. What's gaussian radius? From my perspective, we want keep all alternative boxes that top left and right bottom point with some range, this picture can explain this:

    we want keep all boxes that corner point within a certain range, how to calculate this range? We using gaussian radius, in code we updated to:

    @staticmethod
    def get_gaussian_radius(box_size, min_overlap):
        """
        copyed from CornerNet
        box_size (w, h), it could be a torch.Tensor, numpy.ndarray, list or tuple
        notice: we are using a bug-version, please refer to fix bug version in CornerNet
        """
        box_tensor = torch.Tensor(box_size)
        width, height = box_tensor[..., 0], box_tensor[..., 1]
    
        a1  = 1
        b1  = (height + width)
        c1  = width * height * (1 - min_overlap) / (1 + min_overlap)
        sq1 = torch.sqrt(b1 ** 2 - 4 * a1 * c1)
        # r1  = (b1 + sq1) / 2
        r1 = (b1 - sq1)/(2*a1)
    
        a2  = 4
        b2  = 2 * (height + width)
        c2  = (1 - min_overlap) * width * height
        sq2 = torch.sqrt(b2 ** 2 - 4 * a2 * c2)
        # r2  = (b2 + sq2) / 2
        r1 = (b2 - sq2) / (2*a2)
    
        a3  = 4 * min_overlap
        b3  = -2 * min_overlap * (height + width)
        c3  = (min_overlap - 1) * width * height
        sq3 = torch.sqrt(b3 ** 2 - 4 * a3 * c3)
        # r3  = (b3 + sq3) / 2
        r3 = (b3 + sq3) / (2*a3)
        return torch.min(r1, torch.min(r2, r3))

    more info can refer to that issue.

  • 2020.03.20: CenterFace model supported!.

  • 2020.03.19: First release the codes, meanwhile centerface model architecture has been added in.

Demo

We have provide resnet50 pretrained weights and resnet101 pretrained weights (head without DCN), to run demo visualize, simply:

sudo pip3 install alfred-py
python demo.py

alfred-py is a deep learning util lib for visualization and common utils, github url: https://github.com/jinfagang/alfred, you can easy install from pip.

note: As you can see, CenterNet is very good at detect very small objects, I intended place these images here, if you try any other anchor based model such as yolov3 or retinanet even maskrcnn, it all will fail at such small objects!

Backbone Head FPS(GTX1080ti) mAP model link
resnet50 without DCN 35.7 (3.1% )↑ model newest model
resnet50 with DCN
resnet18 without DCN
resnet18 with DCN -
volvenet39
mobilenetv3

the model linked above maybe updates in the future, so pls subscribe our updates! CenterFace will update once we finished training.

Train

You can simply train the model by change your import way:

# default using config from configs.ct_coco_r50_config import config
python train.py

Reference

thanks to original author of CenterNet-Better, and there also some implementations such as CenterNet-Bettter-Plus, but keep in mind that CenterNet-Pro-Max is always the best!

centernet_pro_max's People

Contributors

111hh111 avatar lucasjinreal avatar nicholasjela avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

centernet_pro_max's Issues

run in CPU mode

Dear Sir:

when i run the demo code with CPU mode, nothing detected, the output is :

try load weights from: ./weights/model_0509999.pth
INFO 03.21 16:31:38 checkpoint.py:121: Loading checkpoint from ./weights/model_0509999.pth
tensor([ 1, 80, 112, 168])
tensor([[[18815, 16863, 16887, ..., 2773, 2781, 2757],
[18207, 18703, 18231, ..., 9472, 15063, 15039],
[18728, 18720, 18752, ..., 18243, 18227, 18251],
...,
[18648, 11093, 11760, ..., 7292, 7316, 7324],
[ 167, 18815, 18648, ..., 18670, 12431, 9408],
[18815, 18648, 167, ..., 3, 18773, 16743]]])
tensor(112)
tensor(168)
tensor(18816)
b.pred_boxes: []
b.scores: []
b.pred_classes: []

How to train on multi gpu device?

Thanks for your amazing work! I have tried to train the code on my own dataset with multi gpus, but it still works on the first one! And I find that the parameter '--num-gpus' not be used! How did you train on 8 gpus?

Problem in training with resNet18 backbone

Thanks for the great job.
So far I m trying to train with "resnet18 + without DCN". But it occurs error as bellow.
File "/home/administrator/anaconda3/envs/CenterNet/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 778, in forward output_padding, self.groups, self.dilation) RuntimeError: Given transposed=1, weight of size 2048 256 4 4, expected input[8, 512, 16, 16] to have 2048 channels, but got 512 channels instead

Original code of gaussian_radius has been fixed

the code for gaussian radius from CenterNet repo was brought from Cornernet and the gaussian_radius() function is wrong, it has been fixed by the author here is the code

def gaussian_radius(det_size, min_overlap):
    height, width = det_size

    a1  = 1
    b1  = (height + width)
    c1  = width * height * (1 - min_overlap) / (1 + min_overlap)
    sq1 = np.sqrt(b1 ** 2 - 4 * a1 * c1)
    r1  = (b1 - sq1) / (2 * a1)

    a2  = 4
    b2  = 2 * (height + width)
    c2  = (1 - min_overlap) * width * height
    sq2 = np.sqrt(b2 ** 2 - 4 * a2 * c2)
    r2  = (b2 - sq2) / (2 * a2)

    a3  = 4 * min_overlap
    b3  = -2 * min_overlap * (height + width)
    c3  = (min_overlap - 1) * width * height
    sq3 = np.sqrt(b3 ** 2 - 4 * a3 * c3)
    r3  = (b3 + sq3) / (2 * a3)
    return min(r1, r2, r3)

Please refer to this for formula derivation
princeton-vl/CornerNet#110

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.