Skip to content

Written by Alex Choi, Oct. 8, 2020.


Basic Environment


Creating CONDA Environment

  • Run a command line tool, i.e. Anaconda Prompt and type the following command:

    conda create -n centernet python=3.7
    
    NOTE: Python 3.8 not tested yet. But you can try if you want.

  • Activate centernet Anaconda environment:

    conda activate centernet
    


Installing Python Packages

  • Install pytorch(ver.1.4) and torchvision based on your cudatoolkit version.

    conda install pytorch=1.4 torchvision cudatoolkit=10.1 -c pytorch
    
    NOTE: CenterNet build didn't work with pytorch version 1.5 or 1.6.
    NOTE: cudatoolkit version 10.2 not tested yet.

  • Install necessary python packages:

    python -m pip install opencv-python Cython numba progress matplotlib easydict scipy
    


Building cocoapi Tools

  • Clone cocoapi tools git repository to any path where you want

    git clone https://github.com/cocodataset/cocoapi.git
    

  • Open cocoapi/PythonAPI/setup.py using a text editor and modify the following line:

    extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99']
    
    to
    extra_compile_args={'gcc': ['/Qstd=c99']},
    

  • In the command line tool move to the following path:

    cd cocoapi/PythonAPI
    

  • Build cocoapi tools:

    python setup.py build_ext install
    


Modifying cpp_extension.py

  • Using a text editor open up C:/ProgramData/Anaconda3/envs/centernet/Lib/site-packages/torch/utils/cpp_extension.py and modify the following line:
    match = re.search(r'(\d+)\.(\d+)\.(\d+)', compiler_info.decode().strip())
    
    to
    match = re.search(r'(\d+)\.(\d+)\.(\d+)', compiler_info.decode("utf8", "ignore").strip())
    

Copying and Unzipping CenterNet.zip

  • Copy "CenterNet.zip" file to any path you want (maybe COI project folder).
  • Unzip the file using BandiZip or any unzipping software you want. NOTE: You can find more information from the PyTorch CenterNet official repo.

Building NMS

  • 'nms' is short for "Non-Maximum Suppression." CenterNet does not usually use Non-Maximum Suppression, but it is sometimes useful.
  • In order to avoid build error comment out the following line after opening CenterNet/src/lib/external/setup.py up using a text editor.
    #extra_compile_args=["-Wno-cpp", "-Wno-unused-function"]
    
    NOTE: The line above may be already commented out actually.
  • Build nms with the following command line:
    python setup.py  build_ext --inplace
    
    NOTE: You can find more information about building nms here.

Building DCNv2

  • Move to the following path in your CenterNet path:
    cd CenterNet/src/lib/models/networks/DCNv2/
    
  • Build DCNv2 using the following command line (this may take some time to finish building):
    python setup.py build develop
    
    NOTE: You can find more information about DCNv2 here.

Test with Pre-trained Models

  • Unzip "ImageNet-Weights.zip" and copy all the contained files (ImageNet pre-trained models) to C:\Users\{WINDOWS_USER_ACCOUNT_NAME}\.cache\torch\checkpoints\.
  • Unzip "Centernet-Models.zip" and copy all the contained files to CenterNet/models/.
  • Finally, test with some COI images using the following command line:
    python demo.py ctdet --demo ../data/COI/images/image_0001.jpg --load_model ../exp/ctdet/COI/model_best.pth
    
    python demo.py ctdet --demo ../data/COI/images/image_0002.jpg --load_model ../exp/ctdet/COI/model_best.pth
    
    python demo.py ctdet --demo ../data/COI/images/image_0003.jpg --load_model ../exp/ctdet/COI/model_best.pth
    

Simple Trial for Training

  • If you are using CenterNet.zip you can find the training information for COI from CenterNet/exp/ctdet/COI/.
  • There are 2 options for training:
    • One is training from scratch (random initialization).
      python main.py ctdet --exp_id COI --batch_size 16 --lr 1.25e-4 --gpus 0 --load_model ../models/ctdet_coco_resdcn18.pth --resume False
      
    • The other is resume training from pre-trained model.
      python main.py ctdet --exp_id COI --batch_size 16 --lr 1.25e-4 --gpus 0 --load_model ../models/ctdet_coco_resdcn18.pth --resume True
      

Checking Training Information

  • You can check your training information such as loss history, accuracy history and so on using TensorBoard.
  • You can find your training information for COI from the path, CenterNet/exp/ctdet/COI/
  • Install tensorboard using the following command line:
    python -m pip install tensorboard