Official PyTorch implementation of Data-free Knowledge Distillation for Object Detection, WACV 2021.

Overview

Introduction

This repository is the official PyTorch implementation of Data-free Knowledge Distillation for Object Detection, WACV 2021.

Data-free Knowledge Distillation for Object Detection
Akshay Chawla, Hongxu Yin, Pavlo Molchanov and Jose Alvarez
NVIDIA

Abstract: We present DeepInversion for Object Detection (DIODE) to enable data-free knowledge distillation for neural networks trained on the object detection task. From a data-free perspective, DIODE synthesizes images given only an off-the-shelf pre-trained detection network and without any prior domain knowledge, generator network, or pre-computed activations. DIODE relies on two key components—first, an extensive set of differentiable augmentations to improve image fidelity and distillation effectiveness. Second, a novel automated bounding box and category sampling scheme for image synthesis enabling generating a large number of images with a diverse set of spatial and category objects. The resulting images enable data-free knowledge distillation from a teacher to a student detector, initialized from scratch. In an extensive set of experiments, we demonstrate that DIODE’s ability to match the original training distribution consistently enables more effective knowledge distillation than out-of-distribution proxy datasets, which unavoidably occur in a data-free setup given the absence of the original domain knowledge.

[PDF - OpenAccess CVF]

Core idea

LICENSE

Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.

This work is made available under the Nvidia Source Code License (1-Way Commercial). To view a copy of this license, visit https://github.com/NVlabs/DIODE/blob/master/LICENSE

Setup environment

Install conda [link] python package manager then install the lpr environment and other packages as follows:

$ conda env create -f ./docker_environment/lpr_env.yml
$ conda activate lpr
$ conda install -y -c conda-forge opencv
$ conda install -y tqdm
$ git clone https://github.com/NVIDIA/apex
$ cd apex
$ pip install -v --no-cache-dir ./

Note: You may also generate a docker image based on provided Dockerfile docker_environments/Dockerfile.

How to run?

This repository allows for generating location and category conditioned images from an off-the-shelf Yolo-V3 object detection model.

  1. Download the directory DIODE_data from google cloud storage: gcs-link (234 GB)
  2. Copy pre-trained yolo-v3 checkpoint and pickle files as follows:
    $ cp /path/to/DIODE_data/pretrained/names.pkl /pathto/lpr_deep_inversion/models/yolo/
    $ cp /path/to/DIODE_data/pretrained/colors.pkl /pathto/lpr_deep_inversion/models/yolo/
    $ cp /path/to/DIODE_data/pretrained/yolov3-tiny.pt /pathto/lpr_deep_inversion/models/yolo/
    $ cp /path/to/DIODE_data/pretrained/yolov3-spp-ultralytics.pt /pathto/lpr_deep_inversion/models/yolo/
    
  3. Extract the one-box dataset (single object per image) as follows:
    $ cd /path/to/DIODE_data
    $ tar xzf onebox/onebox.tgz -C /tmp
    
  4. Confirm the folder /tmp/onebox containing the onebox dataset is present and has following directories and text file manifest.txt:
    $ cd /tmp/onebox
    $ ls
    images  labels  manifest.txt
    
  5. Generate images from yolo-v3:
    $ cd /path/to/lpr_deep_inversion
    $ chmod +x scripts/runner_yolo_multiscale.sh
    $ scripts/runner_yolo_multiscale.sh
    

Images

Notes:

  1. For ngc, use the provided bash script scripts/diode_ngc_interactivejob.sh to start an interactive ngc job with environment setup, code and data setup.
  2. To generate large dataset use bash script scripts/LINE_looped_runner_yolo.sh.
  3. Check knowledge_distillation subfolder for code for knowledge distillation using generated datasets.

Citation

@inproceedings{chawla2021diode,
	title = {Data-free Knowledge Distillation for Object Detection},
	author = {Chawla, Akshay and Yin, Hongxu and Molchanov, Pavlo and Alvarez, Jose M.},
	booktitle = {The IEEE/CVF Winter Conference on Applications of Computer Vision (WACV)},
	month = January,
	year = {2021}
}
Comments
  • Regarding training using BDD100K dataset

    Regarding training using BDD100K dataset

    Greetings,

    This is Aman Goyal. I am currently pursuing research in MSU in the domain of knowledge distillation and I had come across your paper and github repo. I actually wanted to train on BDD100K detection dataset. Is it possible to integrate with your codebase ? If yes, then please guide on how to do it. I already have BDD100K dataset ready.

    Regards, Aman Goyal

    opened by AmanGoyal99 9
  • Confusion about the one box dataset

    Confusion about the one box dataset

    Thank you for sharing ! I have a questions about your code. I noticed that the codes load the images in onebox dataset to mix up with the randomly-initialized tensor, as the initial tensor to generate images. init = (args.real_mixin_alpha)*imgs + (1.0-args.real_mixin_alpha)*init However, onebox dataset is the one that we want to generate, isn't it ?

    opened by merlinarer 4
  • Re: Self-similarity hook

    Re: Self-similarity hook

    Hi @akshaychawla. Can you share any resources for the SelfSimilarityHook which you have in the deepinversion code? In the original code, it was not present, and I am not able to find relevant papers for it.

    Originally posted by @animesh-007 in https://github.com/NVlabs/DIODE/issues/6#issuecomment-979319976

    opened by akshaychawla 3
  • Same content in label files on bdd100k dataset

    Same content in label files on bdd100k dataset

    I downloaded bdd100k dataset from the provided link bdd100k dataset , and found that all contents of label files are same (at least 20 label files I have seen). e.g.: cat bdd100k\labels\train2014\0a0a0b1a-7c39d841.txt

    16 0.711640 0.774731 0.102000 0.068660 0 0.057500 0.594460 0.045600 0.122158 13 0.307800 0.763254 0.109320 0.191058 25 0.400000 0.774302 0.097640 0.155459

    cat bdd100k\labels\train2014\0a0a0b1a-27d9fc44.txt

    16 0.711640 0.774731 0.102000 0.068660 0 0.057500 0.594460 0.045600 0.122158 13 0.307800 0.763254 0.109320 0.191058 25 0.400000 0.774302 0.097640 0.155459

    cat bdd100k\labels\train2014\0a0b16e2-93f8c456.txt

    16 0.711640 0.774731 0.102000 0.068660 0 0.057500 0.594460 0.045600 0.122158 13 0.307800 0.763254 0.109320 0.191058 25 0.400000 0.774302 0.097640 0.155459

    Shall I extract label files from the official bdd100k dataset?

    opened by abse4411 2
  • Image variance collapses to zero

    Image variance collapses to zero

    Hi, thanks for the code, I just want to make sure whether what I'm currently encountering is due to parameter settings or the architecture I'm using.

    I've made some modifications to the code so this will not be representative of the original training code but when I'm generating images using a pretrained resnest-101 the generated images quickly reaches a zero-variance (less than 0.01 after 100 iterations). Is this something that often happen or is this a problem that occur due to the differing architecture?

    Some potential causes: Different architecture (Resnest-101 + DeepLabv3) All BN layers are used in the loss (I've tried to use the cosine annealing of the number of layers to include) Loss balances (I've tried to completely remove the task loss and only use the task loss + include an image statistics loss matching the mean and variance to a N(0,1) distribution (after normalization))

    Thanks beforehand for any insights

    opened by karlHolmquist 1
  • ERROR occurs when doing distillation!! help!

    ERROR occurs when doing distillation!! help!

    @akshaychawla Hi, I recently try to reproduce your work, and face one error and didnt figure it out yet. I just downloaded the tiled pseudo data as the training data, and after run the distill.py one epoch, the follows error occurs that is 'Trying to create tensor with negative dimension -1682796288: [-1682796288]' can anyone tell me what todo and figure it out?? thanks!

    opened by hongge831 0
  • Training time consumption

    Training time consumption

    As the comments in LINE_looped_runner_yolo.sh show, the authors use 28 gpus to generate a dataset in 48 hours.

    Can you provide the detailed running time of a) generate 160x160 images, b) upsample images from 160x160 to 320x320, c) fine-tune 320x320 images, d) knowledge distillation.

    Thank you. @akshaychawla

    opened by DCNSW 1
  • Question about the pretrained model.

    Question about the pretrained model.

    I just download the pretrained model 'yolo-tiny.pt' and 'yolov3-spp-ultralytics.pt' and try to run the script. However, I met the loading error 'RuntimeError: storage has wrong size: expected 0 got 32768' can anyone help me out? Thanks alot!!

    opened by hongge831 1
  • About L2 & TV loss, mean value

    About L2 & TV loss, mean value

    Good day, Thank you for the nice job and for making it open-source ~ I have some doubts about these two losses. Could you please explain why you have taken the "mean of L2 loss and TV loss"? https://github.com/NVlabs/DIODE/blob/80a396d5772528d4c393a301b0a1390eb7e7e039/deepinversion_yolo.py#L178

    and

    https://github.com/NVlabs/DIODE/blob/80a396d5772528d4c393a301b0a1390eb7e7e039/deepinversion_yolo.py#L245

    Thank you ~

    opened by mountains-high 1
TorchDistiller - a collection of the open source pytorch code for knowledge distillation, especially for the perception tasks, including semantic segmentation, depth estimation, object detection and instance segmentation.

This project is a collection of the open source pytorch code for knowledge distillation, especially for the perception tasks, including semantic segmentation, depth estimation, object detection and instance segmentation.

yifan liu 147 Dec 3, 2022
Official PyTorch code for WACV 2022 paper "CFLOW-AD: Real-Time Unsupervised Anomaly Detection with Localization via Conditional Normalizing Flows"

CFLOW-AD: Real-Time Unsupervised Anomaly Detection with Localization via Conditional Normalizing Flows WACV 2022 preprint:https://arxiv.org/abs/2107.1

Denis 156 Dec 28, 2022
Instance-conditional Knowledge Distillation for Object Detection

Instance-conditional Knowledge Distillation for Object Detection This is a MegEngine implementation of the paper "Instance-conditional Knowledge Disti

MEGVII Research 47 Nov 17, 2022
Official implementation for (Refine Myself by Teaching Myself : Feature Refinement via Self-Knowledge Distillation, CVPR-2021)

FRSKD Official implementation for Refine Myself by Teaching Myself : Feature Refinement via Self-Knowledge Distillation (CVPR-2021) Requirements Pytho

null 75 Dec 28, 2022
Official implementation for (Show, Attend and Distill: Knowledge Distillation via Attention-based Feature Matching, AAAI-2021)

Show, Attend and Distill: Knowledge Distillation via Attention-based Feature Matching Official pytorch implementation of "Show, Attend and Distill: Kn

Clova AI Research 80 Dec 16, 2022
The official implementation of CVPR 2021 Paper: Improving Weakly Supervised Visual Grounding by Contrastive Knowledge Distillation.

Improving Weakly Supervised Visual Grounding by Contrastive Knowledge Distillation This repository is the official implementation of CVPR 2021 paper:

null 9 Nov 14, 2022
This is the official pytorch implementation of Student Helping Teacher: Teacher Evolution via Self-Knowledge Distillation(TESKD)

Student Helping Teacher: Teacher Evolution via Self-Knowledge Distillation (TESKD) By Zheng Li[1,4], Xiang Li[2], Lingfeng Yang[2,4], Jian Yang[2], Zh

Zheng Li 9 Sep 26, 2022
Official implementation of the paper "Lightweight Deep CNN for Natural Image Matting via Similarity Preserving Knowledge Distillation"

Lightweight-Deep-CNN-for-Natural-Image-Matting-via-Similarity-Preserving-Knowledge-Distillation Introduction Accepted at IEEE Signal Processing Letter

DongGeun-Yoon 19 Jun 7, 2022
[NeurIPS-2021] Mosaicking to Distill: Knowledge Distillation from Out-of-Domain Data

MosaicKD Code for NeurIPS-21 paper "Mosaicking to Distill: Knowledge Distillation from Out-of-Domain Data" 1. Motivation Natural images share common l

ZJU-VIPA 37 Nov 10, 2022
Code implementation of Data Efficient Stagewise Knowledge Distillation paper.

Data Efficient Stagewise Knowledge Distillation Table of Contents Data Efficient Stagewise Knowledge Distillation Table of Contents Requirements Image

IvLabs 112 Dec 2, 2022
Pytorch implementation for Patient Knowledge Distillation for BERT Model Compression

Patient Knowledge Distillation for BERT Model Compression Knowledge distillation for BERT model Installation Run command below to install the environm

Siqi 180 Dec 19, 2022
PyTorch implementation of paper A Fast Knowledge Distillation Framework for Visual Recognition.

FKD: A Fast Knowledge Distillation Framework for Visual Recognition Official PyTorch implementation of paper A Fast Knowledge Distillation Framework f

Zhiqiang Shen 129 Dec 24, 2022
Pytorch implementation of "Geometrically Adaptive Dictionary Attack on Face Recognition" (WACV 2022)

Geometrically Adaptive Dictionary Attack on Face Recognition This is the Pytorch code of our paper "Geometrically Adaptive Dictionary Attack on Face R

null 6 Nov 21, 2022
Light-weight network, depth estimation, knowledge distillation, real-time depth estimation, auxiliary data.

light-weight-depth-estimation Boosting Light-Weight Depth Estimation Via Knowledge Distillation, https://arxiv.org/abs/2105.06143 Junjie Hu, Chenyou F

Junjie Hu 13 Dec 10, 2022
Code for "ShineOn: Illuminating Design Choices for Practical Video-based Virtual Clothing Try-on", accepted at WACV 2021 Generation of Human Behavior Workshop.

ShineOn: Illuminating Design Choices for Practical Video-based Virtual Clothing Try-on [ Paper ] [ Project Page ] This repository contains the code fo

Andrew Jong 97 Dec 13, 2022
Official PyTorch implementation of Joint Object Detection and Multi-Object Tracking with Graph Neural Networks

This is the official PyTorch implementation of our paper: "Joint Object Detection and Multi-Object Tracking with Graph Neural Networks". Our project website and video demos are here.

Richard Wang 443 Dec 6, 2022
Localization Distillation for Object Detection

Localization Distillation for Object Detection This repo is based on mmDetection. This is the code for our paper: Localization Distillation

null 274 Dec 26, 2022
LiDAR Distillation: Bridging the Beam-Induced Domain Gap for 3D Object Detection

LiDAR Distillation Paper | Model LiDAR Distillation: Bridging the Beam-Induced Domain Gap for 3D Object Detection Yi Wei, Zibu Wei, Yongming Rao, Jiax

Yi Wei 75 Dec 22, 2022
Block-wisely Supervised Neural Architecture Search with Knowledge Distillation (CVPR 2020)

DNA This repository provides the code of our paper: Blockwisely Supervised Neural Architecture Search with Knowledge Distillation. Illustration of DNA

Changlin Li 215 Dec 19, 2022