Code for the ICCV 2021 paper "Pixel Difference Networks for Efficient Edge Detection" (Oral).

Overview

Pixel Difference Convolution

This repository contains the PyTorch implementation for "Pixel Difference Networks for Efficient Edge Detection" by Zhuo Su*, Wenzhe Liu*, Zitong Yu, Dewen Hu, Qing Liao, Qi Tian, Matti Pietikäinen and Li Liu** (* Authors have equal contributions, ** Corresponding author). [arXiv]

The writing style of this code is based on Dynamic Group Convolution.

Running environment

Training: Pytorch 1.9 with cuda 10.1 and cudnn 7.5 in an Ubuntu 18.04 system
Evaluation: Matlab 2019a

Ealier versions may also work~ :)

Dataset

We use the links in RCF Repository. The augmented BSDS500, PASCAL VOC, and NYUD datasets can be downloaded with:

wget http://mftp.mmcheng.net/liuyun/rcf/data/HED-BSDS.tar.gz
wget http://mftp.mmcheng.net/liuyun/rcf/data/PASCAL.tar.gz
wget http://mftp.mmcheng.net/liuyun/rcf/data/NYUD.tar.gz

To create BSDS dataset, please follow:

  1. create a folder /path/to/BSDS500,
  2. extract HED-BSDS.tar.gz to /path/to/BSDS500/HED-BSDS,
  3. extract PASCAL.tar.gz to /path/to/BSDS500/PASCAL,
  4. if you want to evaluate on BSDS500 val set, the val images can be downloaded from this link, please extract it to /path/to/BSDS500/HED-BSDS/val,
  5. cp the *.lst files in data/BSDS500/HED-BSDS to /path/to/BSDS500/HED-BSDS/, cp the *.lst files in data/BSDS500 to /path/to/BSDS500/.

To create NYUD dataset, please follow:

  1. create a folder /path/to/NYUD,
  2. extract NYUD.tar.gz to /path/to/NYUD,
  3. cp the *.lst files in data/NYUD to /path/to/NYUD/.

Training, and Generating edge maps

Here we provide the scripts for training the models appeared in the paper. For example, we refer to the PiDiNet model in Table 5 in the paper as table5_pidinet.

table5_pidinet

# train, the checkpoints will be save in /path/to/table5_pidinet/save_models/ during training
python main.py --model pidinet --config carv4 --sa --dil --resume --iter-size 24 -j 4 --gpu 0 --epochs 20 --lr 0.005 --lr-type multistep --lr-steps 10-16 --wd 1e-4 --savedir /path/to/table5_pidinet --datadir /path/to/BSDS500 --dataset BSDS

# generating edge maps using the original model
python main.py --model pidinet --config carv4 --sa --dil -j 4 --gpu 0 --savedir /path/to/table5_pidinet --datadir /path/to/BSDS500 --dataset BSDS --evaluate /path/to/table5_pidinet/save_models/checkpointxxx.tar

# generating edge maps using the converted model, it should output the same results just like using the original model
# the process will convert pidinet to vanilla cnn, using the saved checkpoint
python main.py --model pidinet_converted --config carv4 --sa --dil -j 4 --gpu 0 --savedir /path/to/table5_pidinet --datadir /path/to/BSDS500 --dataset BSDS --evaluate /path/to/table5_pidinet/save_models/checkpointxxx.tar --evaluate-converted

# test FPS on GPU
python throughput.py --model pidinet_converted --config carv4 --sa --dil -j 1 --gpu 0 --datadir /path/to/BSDS500 --dataset BSDS

It is similar for other models, please see detailed scripts in scripts.sh.

The performance of some of the models are listed below (click the items to download the checkpoints and training logs). FPS metrics are tested on a NVIDIA RTX 2080 Ti, showing slightly faster than that recorded in the paper (you probably get different FPS records in different runs, but they will not vary too much):

Model ODS OIS FPS Training logs
table5_baseline 0.798 0.816 101 log
table5_pidinet 0.807 0.823 96 log, running log
table5_pidinet-l 0.800 0.815 135 log
table5_pidinet-small 0.798 0.814 161 log
table5_pidinet-small-l 0.793 0.809 225 log
table5_pidinet-tiny 0.789 0.806 182 log
table5_pidinet-tiny-l 0.787 0.804 253 log
table6_pidinet 0.733 0.747 66 log, running_log
table7_pidinet 0.818 0.824 17 log, running_log

Evaluation

The matlab code used for evaluation in our experiments can be downloaded in matlab code for evaluation.

Possible steps:

  1. extract the downloaded file to /path/to/edge_eval_matlab,
  2. change the first few lines (path settings) in eval_bsds.m, eval_nyud.m, eval_multicue.m for evaluating the three datasets respectively,
  3. in a terminal, open Matlab like
matlab -nosplash -nodisplay -nodesktop

# after entering the Matlab environment, 
>>> eval_bsds
  1. you could change the number of works in parpool in /path/to/edge_eval_matlab/toolbox.badacost.public/matlab/fevalDistr.m in line 100. The default value is 16.

For evaluating NYUD, following RCF, we increase the localization tolerance from 0.0075 to 0.011. The Matlab code is based on the following links:

PR curves

Please follow plot-edge-pr-curves, files for plotting pr curves of PiDiNet are provided in pidinet_pr_curves.

Generating edge maps for your own images

python main.py --model pidinet_converted --config carv4 --sa --dil -j 4 --gpu 0 --savedir /path/to/savedir --datadir /path/to/custom_images --dataset Custom --evaluate /path/to/table5_pidinet/save_models/checkpointxxx.tar --evaluate-converted

The results of our model look like this. The top image is the messy office table, the bottom image is the peaceful Saimaa lake in southeast of Finland.
Comments
  • 输出的图片的含义

    输出的图片的含义

    作者你好,你做的实在是太棒了!因为课程要复现论文,我也不是CV领域的,所以我的问题可能有些幼稚,我想询问一下自己的图片输入之后,输出的一张长图片各个小图片是不是不同的edge map的结果?另外输出了一张被裁剪过的图是最终的结果吗?最后我还有一个小问题,我输入了一张1200W像素的图片就提醒我显卡内存不足了,我显卡内存是4G,我主要想知道为什么一张1200W像素的照片为什么能填满4G的显存,如果您有空解答我的问题,我将不胜感激!!!

    opened by yuyouyu32 6
  • Multicue dataset, set 1 set 2 set 3

    Multicue dataset, set 1 set 2 set 3

    Hi Zhuo, Nice work, and it helps a lot! Thanks.

    But, why does it has three different sets (e.g. train_pair_edge_set_1/2/3.lst) for Multicue dataset? Are they randomly split from the corresponding train_pair_edge.lst?

    To get results in Table 7 (Multicue, boundary and edge), one should run the code separately with each of the three sets and then average their edge maps for evaluation? For their five GTs(1,2,3,4,5 ), which should be used for evaluation, or all of them?

    opened by wasaCheney 4
  • About edge detection fps

    About edge detection fps

    When I use python main.py --model pidinet_tiny to generate the edge images of my data set, the average edge extraction of each image can only reach about 90ms, and when using python main.py --model pidinet_tiny, it is displayed as: Threshold for ground truth: 76.800000 on BSDS_VOC, fps: 148.358999. I would like to ask what ways can be used to improve the speed of python main.py --model pidinet_tiny edge detection, such as not generating jpg and mat files?

    opened by KengDong 4
  • Checkpoints file and table5_pidinet model

    Checkpoints file and table5_pidinet model

    Hello, where can I download the checkpoints file? I want to train a table5_pidinet model, but I have encountered some difficulties. Is it convenient for email to contact?

    opened by emmmmmmmer 4
  • weights_c

    weights_c

    Hello, your work is perfect, but I took a look at the CPDC program you wrote today. I don't quite understand the solution of weights_c. Did something go wrong?

    opened by RuosiZhou 3
  • 运行命令行出错,可以帮忙看一下这是哪里出错了吗

    运行命令行出错,可以帮忙看一下这是哪里出错了吗

    python main.py --model pidinet --config carv4 --sa --dil --resume --iter-size 24 -j 0 --gpu 0 --epochs 20 --lr 0.005 --lr-type multistep --lr-steps 10-16 --wd 1e-4 --savedir /path/to/table5_pidinet --datadir path/to/BSDS500 --dataset BSDS 会出现错误 No such file or directory: 'path/to/BSDS500\PASCAL/aug_gt/0.0_0/2009_003007.png' 麻烦请教一下可以帮忙看看这是哪里出错了吗

    opened by dongliuqingqing 2
  • Error: Generating edge maps for your own images

    Error: Generating edge maps for your own images

    When I test the code to generate edge maps for my own images following the readme guide, an error occurs. Running the test code by: python main.py --model pidinet_converted --config carv4 --sa --dil -j 4 --datadir ./data/test --dataset Custom --evaluate ./trained_models/table5_pidinet.pth --evaluate-converted

    Error:

    Namespace(ablation=False, checkinfo=False, config='carv4', datadir='./data/test', datase
     epochs=20, eta=0.3, evaluate='./trained_models/table5_pidinet.pth', evaluate_converted=
    =24, lmbda=1.1, lr=0.005, lr_steps=None, lr_type='multistep', model='pidinet', only_bsds
    nt_freq=10, resume=False, sa=True, save_freq=1, savedir='results/savedir', seed=16383577
    0.0001, workers=4)                                                                      
    {'layer0': 'cd', 'layer1': 'ad', 'layer2': 'rd', 'layer3': 'cv', 'layer4': 'cd', 'layer5
    , 'layer7': 'cv', 'layer8': 'cd', 'layer9': 'ad', 'layer10': 'rd', 'layer11': 'cv', 'lay
     'ad', 'layer14': 'rd', 'layer15': 'cv'}                                                
    initialization done                                                                     
    conv weights: lr 0.005000, wd 0.000100  bn weights: lr 0.005000, wd 0.000010    relu wei
    .000000                                                                                 
    cuda is not used, the running might be slow                                             
    => loading checkpoint from './trained_models/table5_pidinet.pth'                        
    => loaded checkpoint './trained_models/table5_pidinet.pth' successfully                 
    {'layer0': 'cd', 'layer1': 'ad', 'layer2': 'rd', 'layer3': 'cv', 'layer4': 'cd', 'layer5
    , 'layer7': 'cv', 'layer8': 'cd', 'layer9': 'ad', 'layer10': 'rd', 'layer11': 'cv', 'lay
     'ad', 'layer14': 'rd', 'layer15': 'cv'}                                                
    Traceback (most recent call last):                                                      
      File "main.py", line 418, in <module>                                                 
        main(f)                                                                             
      File "main.py", line 201, in main                                                     
        model.load_state_dict(convert_pidinet(checkpoint['state_dict'], args.config))       
      File "D:\Miniconda3\envs\paintly\lib\site-packages\torch\nn\modules\module.py", line 1
                                                                                            
        self.__class__.__name__, "\n\t".join(error_msgs)))                                  
    RuntimeError: Error(s) in loading state_dict for PiDiNet:                               
            Missing key(s) in state_dict: "init_block.weight", "block1_1.conv1.weight", "blo
    lock1_2.conv1.weight", ....                              
            Unexpected key(s) in state_dict: "module.init_block.weight", "module.block1_1.co
    ock1_1.conv2.weight", "module.block1_2.conv1.weight"...
    

    Seems like the loaded model does not match the defined model. @zhuoinoulu Did I miss something? Very much appreciated for your help!

    opened by michael-gc 2
  • Why the FPS of pidinet_converted model tested on my own Geforce RTX 2080Ti is only 92.9?

    Why the FPS of pidinet_converted model tested on my own Geforce RTX 2080Ti is only 92.9?

    Hello~ The FPS of pidinet_tiny_converted and pidinet_small_converted is higher than your results when tested on my own Geforce RTX 2080Ti, which are 203.5FPS and 162.9FPS respectively. However, the FPS of pidinet_converted is only 92.9FPS, which is lower than 96FPS. And I have another question, why the speed test code do not use the torch.cuda.synchronize() to get a more resonable result?

    opened by liuzhidemaomao 2
  • Prepare the Multicue dataset

    Prepare the Multicue dataset

    Hi, Your paper and code save my life really! But, there are no links or instructions when I try to get the results in Table 7 (Multicue dataset). I have also downloaded the official dataset, but it could not be directly used in this project.

    I am a fresh hand in Edge Detection. Would you please share with me the code for preparing Multicue?

    Thank you very much!

    PS my email address, [email protected]

    opened by wasaCheney 1
  • 關於table2的訓練

    關於table2的訓練

    以下是我訓練table2的參數 但是ods, ois與論文不同 請問是該修改哪裡呢 python main.py --model pidinet --config carv4 --sa --dil --resume --iter-size 24 -j 4 --gpu 0 --epochs 14 --lr 0.005 --lr-type multistep --lr-steps 8-12 --wd 1e-1 --savedir mysave --datadir data/BSDS500/HED-BSDS --dataset BSDS --only-bsds ODS=0.761, OIS=0.775

    opened by nancy971323 1
  • About getting edge image using onnx runtime

    About getting edge image using onnx runtime

    I tried to convert the .pth file to .onnx files onnx. I followed this website onnxruntime. Finally I get a numpy array with size (5,1,1,256,256). Should I get an array with 3 dimension rather than 5 dimension? Thank you.

    import onnxruntime as ort
    import numpy as np
    import cv2
    import matplotlib.pyplot as plt
    
    img_path = "0.jpg"
    input_img = cv2.imread(img_path)
    
    mean = np.array([0.485, 0.456, 0.406]) * 255.0
    scale = 1 / 255.0
    std = [0.229, 0.224, 0.225]
    input_blob = cv2.dnn.blobFromImage(
        image=input_img,
        scalefactor=scale,
        size=(256, 256),  # img target size
        mean=mean,
        swapRB=True,  # BGR -> RGB
        crop=False  # center crop
    )
    input_blob[0] /= np.asarray(std, dtype=np.float32).reshape(3, 1, 1)
    
    ort_sess = ort.InferenceSession("pidinet_tiny_converted_new.onnx")
    outputs = ort_sess.run(None, {'input': input_blob})
    
    outputs = np.asarray(outputs)
    print(outputs.shape)
    
    opened by liyingyinsimon 1
  • question about .train()

    question about .train()

    I notice that in the function train() of main.py , the model are converted to training mode through model.train(). But, batch normalization or DropOut is not adopted in the network. I wonder is it necessary to use model.train(). Can I abandon it?

    opened by ForawardStar 0
  • How to convert the PASCAL VOC Context dataset to the binary graph used by GT?

    How to convert the PASCAL VOC Context dataset to the binary graph used by GT?

    thanks to your excellent works. How to convert the PASCAL VOC Context dataset to the binary graph used by GT? 请问如何把 PASCAL VOC Context dataset转换为GT使用的二值图?

    opened by xkangKK 0
  • How long it takes to evaluate the NYUD dataset?

    How long it takes to evaluate the NYUD dataset?

    Thanks for your excellent job. I am a new learner of edge detection. When I evaluate my results on NYUD dataset, I found I need very very much time(Use 32 workers)... So I would like to inquire about the timing of the evaluation in order to verify that I am doing the right thing. Thank you.

    opened by HereNowL 0
  • Converting your model to onnx requires loading the pytorch model (including structure and parameters), could you publish a tutorial on loading your model?

    Converting your model to onnx requires loading the pytorch model (including structure and parameters), could you publish a tutorial on loading your model?

    Converting your model to onnx requires loading the pytorch model (including structure and parameters), could you publish a tutorial on loading your model?

    opened by chenguilin111 0
Owner
Alex
A researcher in Oulu, Finland. Working on model compression and acceleration on Computer Vision.
Alex
Code Release for ICCV 2021 (oral), "AdaFit: Rethinking Learning-based Normal Estimation on Point Clouds"

AdaFit: Rethinking Learning-based Normal Estimation on Point Clouds (ICCV 2021 oral) **Project Page | Arxiv ** Runsong Zhu¹, Yuan Liu², Zhen Dong¹, Te

null 40 Dec 30, 2022
Official PyTorch code of DeepPanoContext: Panoramic 3D Scene Understanding with Holistic Scene Context Graph and Relation-based Optimization (ICCV 2021 Oral).

DeepPanoContext (DPC) [Project Page (with interactive results)][Paper] DeepPanoContext: Panoramic 3D Scene Understanding with Holistic Scene Context G

Cheng Zhang 66 Nov 16, 2022
Improving Contrastive Learning by Visualizing Feature Transformation, ICCV 2021 Oral

Improving Contrastive Learning by Visualizing Feature Transformation This project hosts the codes, models and visualization tools for the paper: Impro

Bingchen Zhao 83 Dec 15, 2022
BARF: Bundle-Adjusting Neural Radiance Fields 🤮 (ICCV 2021 oral)

BARF ?? : Bundle-Adjusting Neural Radiance Fields Chen-Hsuan Lin, Wei-Chiu Ma, Antonio Torralba, and Simon Lucey IEEE International Conference on Comp

Chen-Hsuan Lin 539 Dec 28, 2022
[ICCV 2021 Oral] PoinTr: Diverse Point Cloud Completion with Geometry-Aware Transformers

PoinTr: Diverse Point Cloud Completion with Geometry-Aware Transformers Created by Xumin Yu*, Yongming Rao*, Ziyi Wang, Zuyan Liu, Jiwen Lu, Jie Zhou

Xumin Yu 317 Dec 26, 2022
[ICCV 2021 Oral] NerfingMVS: Guided Optimization of Neural Radiance Fields for Indoor Multi-view Stereo

NerfingMVS Project Page | Paper | Video | Data NerfingMVS: Guided Optimization of Neural Radiance Fields for Indoor Multi-view Stereo Yi Wei, Shaohui

Yi Wei 369 Dec 24, 2022
[ICCV 2021 (oral)] Planar Surface Reconstruction from Sparse Views

Planar Surface Reconstruction From Sparse Views Linyi Jin, Shengyi Qian, Andrew Owens, David F. Fouhey University of Michigan ICCV 2021 (Oral) This re

Linyi Jin 89 Jan 5, 2023
ILVR: Conditioning Method for Denoising Diffusion Probabilistic Models (ICCV 2021 Oral)

ILVR + ADM This is the implementation of ILVR: Conditioning Method for Denoising Diffusion Probabilistic Models (ICCV 2021 Oral). This repository is h

Jooyoung Choi 225 Dec 28, 2022
A PyTorch implementation of the baseline method in Panoptic Narrative Grounding (ICCV 2021 Oral)

A PyTorch implementation of the baseline method in Panoptic Narrative Grounding (ICCV 2021 Oral)

Biomedical Computer Vision @ Uniandes 52 Dec 19, 2022
[ICCV 2021 Oral] SnowflakeNet: Point Cloud Completion by Snowflake Point Deconvolution with Skip-Transformer

This repository contains the source code for the paper SnowflakeNet: Point Cloud Completion by Snowflake Point Deconvolution with Skip-Transformer (ICCV 2021 Oral). The project page is here.

AllenXiang 65 Dec 26, 2022
This Repo is the official CUDA implementation of ICCV 2019 Oral paper for CARAFE: Content-Aware ReAssembly of FEatures

Introduction This Repo is the official CUDA implementation of ICCV 2019 Oral paper for CARAFE: Content-Aware ReAssembly of FEatures. @inproceedings{Wa

Jiaqi Wang 42 Jan 7, 2023
Code for CVPR 2021 oral paper "Exploring Data-Efficient 3D Scene Understanding with Contrastive Scene Contexts"

Exploring Data-Efficient 3D Scene Understanding with Contrastive Scene Contexts The rapid progress in 3D scene understanding has come with growing dem

Facebook Research 182 Dec 30, 2022
This is the code for CVPR 2021 oral paper: Jigsaw Clustering for Unsupervised Visual Representation Learning

JigsawClustering Jigsaw Clustering for Unsupervised Visual Representation Learning Pengguang Chen, Shu Liu, Jiaya Jia Introduction This project provid

DV Lab 73 Sep 18, 2022
Official Pytorch Implementation of 'Learning Action Completeness from Points for Weakly-supervised Temporal Action Localization' (ICCV-21 Oral)

Learning-Action-Completeness-from-Points Official Pytorch Implementation of 'Learning Action Completeness from Points for Weakly-supervised Temporal A

Pilhyeon Lee 67 Jan 3, 2023
A Fast and Accurate One-Stage Approach to Visual Grounding, ICCV 2019 (Oral)

One-Stage Visual Grounding ***** New: Our recent work on One-stage VG is available at ReSC.***** A Fast and Accurate One-Stage Approach to Visual Grou

Zhengyuan Yang 118 Dec 5, 2022
Official pytorch implementation of paper "Inception Convolution with Efficient Dilation Search" (CVPR 2021 Oral).

IC-Conv This repository is an official implementation of the paper Inception Convolution with Efficient Dilation Search. Getting Started Download Imag

Jie Liu 111 Dec 31, 2022
Based on the paper "Geometry-aware Instance-reweighted Adversarial Training" ICLR 2021 oral

Geometry-aware Instance-reweighted Adversarial Training This repository provides codes for Geometry-aware Instance-reweighted Adversarial Training (ht

Jingfeng 47 Dec 22, 2022
Code for ICCV 2021 paper "Distilling Holistic Knowledge with Graph Neural Networks"

HKD Code for ICCV 2021 paper "Distilling Holistic Knowledge with Graph Neural Networks" cifia-100 result The implementation of compared methods are ba

Wang Yucheng 30 Dec 18, 2022
code for ICCV 2021 paper 'Generalized Source-free Domain Adaptation'

G-SFDA Code (based on pytorch 1.3) for our ICCV 2021 paper 'Generalized Source-free Domain Adaptation'. [project] [paper]. Dataset preparing Download

Shiqi Yang 84 Dec 26, 2022