Pytorch implementation of Feature Pyramid Network (FPN) for Object Detection

Overview

fpn.pytorch Pytorch implementation of Feature Pyramid Network (FPN) for Object Detection

Introduction

This project inherits the property of our pytorch implementation of faster r-cnn. Hence, it also has the following unique features:

  • It is pure Pytorch code. We convert all the numpy implementations to pytorch.

  • It supports trainig batchsize > 1. We revise all the layers, including dataloader, rpn, roi-pooling, etc., to train with multiple images at each iteration.

  • It supports multiple GPUs. We use a multiple GPU wrapper (nn.DataParallel here) to make it flexible to use one or more GPUs, as a merit of the above two features.

  • It supports three pooling methods. We integrate three pooling methods: roi pooing, roi align and roi crop. Besides, we convert them to support multi-image batch training.

Benchmarking

We benchmark our code thoroughly on three datasets: pascal voc, coco. Below are the results:

1). PASCAL VOC 2007 (Train/Test: 07trainval/07test, scale=600, ROI Align)

model GPUs Batch Size lr lr_decay max_epoch Speed/epoch Memory/GPU mAP
Res-101   8 TitanX 24 1e-2 10 12 0.22 hr 9688MB 74.2

Results on coco are on the way.

Comments
  • collapses after the trainval_net.py finishing its first  training iter

    collapses after the trainval_net.py finishing its first training iter

    I am training my own dataset using fpn, i set the num_workers > 0 like =4, and then it collapses after the first training iter, but it will be ok if num_workers = 0, my device is following: OS: Ubuntu 16.04 PyTorch version: pytorch 0.3.1 Python version: python 2.7 CUDA version: 8.0 GPU models : Tesla P40

    [session 3][epoch  1][iter    0] loss: 4.3830, lr: 1.00e-03
    			fg/bg=(115/397), time cost: 5.939724
    			rpn_cls: 0.6945, rpn_box: 1.2795, rcnn_cls: 2.3964, rcnn_box 0.0127
    Traceback (most recent call last):
      File "trainval_net.py", line 339, in <module>
        data = data_iter.next()
      File "/root/anaconda2/lib/python2.7/site-packages/torch/utils/data/dataloader.py", line 204, in __next__
        idx, batch = self.data_queue.get()
      File "/root/anaconda2/lib/python2.7/multiprocessing/queues.py", line 378, in get
        return recv()
      File "/root/anaconda2/lib/python2.7/site-packages/torch/multiprocessing/queue.py", line 22, in recv
        return pickle.loads(buf)
      File "/root/anaconda2/lib/python2.7/pickle.py", line 1388, in loads
        return Unpickler(file).load()
      File "/root/anaconda2/lib/python2.7/pickle.py", line 864, in load
        dispatch[key](self)
      File "/root/anaconda2/lib/python2.7/pickle.py", line 1139, in load_reduce
        value = func(*args)
      File "/root/anaconda2/lib/python2.7/site-packages/torch/multiprocessing/reductions.py", line 68, in rebuild_storage_fd
        fd = multiprocessing.reduction.rebuild_handle(df)
      File "/root/anaconda2/lib/python2.7/multiprocessing/reduction.py", line 155, in rebuild_handle
        conn = Client(address, authkey=current_process().authkey)
      File "/root/anaconda2/lib/python2.7/multiprocessing/connection.py", line 169, in Client
        c = SocketClient(address)
      File "/root/anaconda2/lib/python2.7/multiprocessing/connection.py", line 308, in SocketClient
        s.connect(address)
      File "/root/anaconda2/lib/python2.7/socket.py", line 228, in meth
        return getattr(self._sock,name)(*args)
    socket.error: [Errno 111] Connection refused
    

    i saw the same problem https://github.com/pytorch/pytorch/issues/1355, but his python verison is 3.x, and i tried that solution, it does not works. @jwyang

    opened by destinyzs 3
  • fpn.pytorch/lib/model/nms/src/nms_cuda.c: No such file or directory

    fpn.pytorch/lib/model/nms/src/nms_cuda.c: No such file or directory

    When running make.sh, I'm getting a no such file or directory error for the file nms_cuda.c. This appears to be missing from the lib/model/nms/src directory.

    running build_ext
    building '_nms' extension
    creating home
    creating home/thomasbalestri
    creating home/thomasbalestri/PycharmProjects
    creating home/thomasbalestri/PycharmProjects/fpn.pytorch
    creating home/thomasbalestri/PycharmProjects/fpn.pytorch/lib
    creating home/thomasbalestri/PycharmProjects/fpn.pytorch/lib/model
    creating home/thomasbalestri/PycharmProjects/fpn.pytorch/lib/model/nms
    creating home/thomasbalestri/PycharmProjects/fpn.pytorch/lib/model/nms/src
    gcc -pthread -B /home/thomasbalestri/anaconda3/envs/pytorch0.3.0_py2/compiler_compat -Wl,--sysroot=/ -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DWITH_CUDA -I/home/thomasbalestri/anaconda3/envs/pytorch0.3.0_py2/lib/python2.7/site-packages/torch/utils/ffi/../../lib/include -I/home/thomasbalestri/anaconda3/envs/pytorch0.3.0_py2/lib/python2.7/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/thomasbalestri/anaconda3/envs/pytorch0.3.0_py2/lib/python2.7/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/home/thomasbalestri/anaconda3/envs/pytorch0.3.0_py2/include/python2.7 -c _nms.c -o ./_nms.o
    gcc -pthread -B /home/thomasbalestri/anaconda3/envs/pytorch0.3.0_py2/compiler_compat -Wl,--sysroot=/ -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DWITH_CUDA -I/home/thomasbalestri/anaconda3/envs/pytorch0.3.0_py2/lib/python2.7/site-packages/torch/utils/ffi/../../lib/include -I/home/thomasbalestri/anaconda3/envs/pytorch0.3.0_py2/lib/python2.7/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/thomasbalestri/anaconda3/envs/pytorch0.3.0_py2/lib/python2.7/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/home/thomasbalestri/anaconda3/envs/pytorch0.3.0_py2/include/python2.7 -c /home/thomasbalestri/PycharmProjects/fpn.pytorch/lib/model/nms/src/nms_cuda.c -o ./home/thomasbalestri/PycharmProjects/fpn.pytorch/lib/model/nms/src/nms_cuda.o
    gcc: error: /home/thomasbalestri/PycharmProjects/fpn.pytorch/lib/model/nms/src/nms_cuda.c: No such file or directory
    Traceback (most recent call last):
      File "build.py", line 36, in <module>
        ffi.build()
      File "/home/thomasbalestri/anaconda3/envs/pytorch0.3.0_py2/lib/python2.7/site-packages/torch/utils/ffi/__init__.py", line 167, in build
        _build_extension(ffi, cffi_wrapper_name, target_dir, verbose)
      File "/home/thomasbalestri/anaconda3/envs/pytorch0.3.0_py2/lib/python2.7/site-packages/torch/utils/ffi/__init__.py", line 103, in _build_extension
        ffi.compile(tmpdir=tmpdir, verbose=verbose, target=libname)
      File "/home/thomasbalestri/anaconda3/envs/pytorch0.3.0_py2/lib/python2.7/site-packages/cffi/api.py", line 690, in compile
        compiler_verbose=verbose, debug=debug, **kwds)
      File "/home/thomasbalestri/anaconda3/envs/pytorch0.3.0_py2/lib/python2.7/site-packages/cffi/recompiler.py", line 1513, in recompile
        compiler_verbose, debug)
      File "/home/thomasbalestri/anaconda3/envs/pytorch0.3.0_py2/lib/python2.7/site-packages/cffi/ffiplatform.py", line 22, in compile
        outputfilename = _build(tmpdir, ext, compiler_verbose, debug)
      File "/home/thomasbalestri/anaconda3/envs/pytorch0.3.0_py2/lib/python2.7/site-packages/cffi/ffiplatform.py", line 58, in _build
        raise VerificationError('%s: %s' % (e.__class__.__name__, e))
    cffi.error.VerificationError: CompileError: command 'gcc' failed with exit status 1
    
    
    opened by Feynman27 3
  • Cuda Error: invalid argument nms_cuda_kernel.cu

    Cuda Error: invalid argument nms_cuda_kernel.cu

    I'm experiencing a CUDA error when running the scripts. There errors occurs here. in lib/model/nms/src/nms_cuda_kernel.cu. The error is: CUDA Error: invalid argument, at line 147 CUDA Error: invalid argument, at line 154 which I assuming is referring to the line in the nms cuda kernel.

    When executing nms in this line, of lib/model/rpn/proposal_layer_fpn.py nms(torch.cat((proposals_single, scores_single), 1), nms_thresh).

    as a check, I have ensured in the make.sh file I changed compute to my gtx1080. I'm using pytorch 0.4 with python 2.7.

    I haven't worked with cuda files before so I'm not too sure how to solve this.

    opened by ljtruong 2
  • Resnet output doesn't match the FPN_FEAT_STRIDES

    Resnet output doesn't match the FPN_FEAT_STRIDES

    The default cnn network is res101. However, on the fpn.py line 184, the size of p2, p3, p4, p5, p6 are 1/4,1/8,1/16,1/16,1/32 of the input image's size, so the FPN_FEAT_STRIDES should be [4,8,16,16,32]. But on the trainval_net.py line 173, default FPN_FEAT_STRIDES is [4, 8, 16, 32, 64], the config and code don't match. I not sure whether the result will be affected, but i think you can modify it. @jwyang

    opened by destinyzs 2
  • when i porting fpn pytorch version 0.4 to 1.0, i face with error

    when i porting fpn pytorch version 0.4 to 1.0, i face with error

        if cfg.POOLING_MODE == "crop":
    
            grid_xy = _affine_grid_gen(rois, base_feat.size()[2:], self.grid_size)
            grid_yx = torch.stack([grid_xy.data[:,:,:,1], grid_xy.data[:,:,:,0]], 3).contiguous()
            roi_pool_feat = self.RCNN_roi_crop(base_feat, Variable(grid_yx).detach())
            if cfg.CROP_RESIZE_WITH_MAX_POOL:
                roi_pool_feat = F.max_pool2d(roi_pool_feat, 2, 2)
        else :
            roi_pool_feats = []
            box_to_levels = []
            for i, l in enumerate(range(2, 6)):
                if (roi_level == l).sum() == 0:
                    continue
                idx_l = (roi_level == l).nonzero().squeeze()
                box_to_levels.append(idx_l)
                #scale = feat_maps[i].size(2) / im_info[0][0]
                if cfg.POOLING_MODE == 'align':
                    feat = self.RCNN_roi_align(feat_maps[i], rois[idx_l])
                elif cfg.POOLING_MODE == 'pool':
                    feat = self.RCNN_roi_pool(feat_maps[i], rois[idx_l])
                roi_pool_feats.append(feat)
     
         
            roi_pool_feat = torch.cat(roi_pool_feats, 0)       
            box_to_level = torch.cat(box_to_levels, 0)
            idx_sorted, order = torch.sort(box_to_level)
            roi_pool_feat = roi_pool_feat[order]
            
        return roi_pool_feat
    

    in _PyramidRoI_Feat function of fpn.py when i porting test_net code to change torch version 0.4 to 1,
    occured "runtime error : zero-dimensional tensor(at position 3) cannot be concatenated " because 724 box_to_levle[3]'s dimesion is 1 error data shape : tensor(271,device='cuda:0') other data shape : tensor([3, 10, 13, 14, .... 282],device='cuda:0')

    i change some code

    1. test_net.py ( line : 277 ) before : cls_dets = torch.cat(cls_boxes, cls_scores, 1) after : cls_dets = torch.cat((cls_boxes, cls_scores.unsqueeze(1)), 1)
    2. test_net.py ( line : 279 ) before : keep = nms(cls_dets, cfg.TEST.NMS) after : keep = nms(cls_boxes[order, :], cls_scores[order], cfg.TEST.NMS)

    my enviorment : based project is your faster - rcnn , which support version torch 1.0 anaconda pytorch1.0, cuda version is 10 python version is 2.7 dataset is voc2007 ( occured error in 001433 data, test data 724th of vocdata2007)

    i wondering where i shold debug. i should not get a sense.

    opened by EzoBear 1
  • When I set the pooling mode as 'pool', an error arise

    When I set the pooling mode as 'pool', an error arise

    /home/zhuyuhe/.conda/envs/dwzpy/lib/python3.5/site-packages/torch/nn/functional.py:1749: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details. "See the documentation of nn.Upsample for details.".format(mode)) /home/zhuyuhe/duwangzhe/fpn_pytorch/lib/model/rpn/rpn_fpn.py:79: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument. rpn_cls_prob_reshape = F.softmax(rpn_cls_score_reshape) Traceback (most recent call last): File "trainval_net.py", line 332, in roi_labels = FPN(im_data, im_info, gt_boxes, num_boxes) File "/home/zhuyuhe/.conda/envs/dwzpy/lib/python3.5/site-packages/torch/nn/modules/module.py", line 491, in call result = self.forward(*input, **kwargs) File "/home/zhuyuhe/duwangzhe/fpn_pytorch/lib/model/fpn/fpn.py", line 246, in forward roi_pool_feat = self._PyramidRoI_Feat(mrcnn_feature_maps, rois, im_info) File "/home/zhuyuhe/duwangzhe/fpn_pytorch/lib/model/fpn/fpn.py", line 160, in _PyramidRoI_Feat feat = self.RCNN_roi_pool(feat_maps[i], rois[idx_l], scale) File "/home/zhuyuhe/.conda/envs/dwzpy/lib/python3.5/site-packages/torch/nn/modules/module.py", line 491, in call result = self.forward(*input, **kwargs) File "/home/zhuyuhe/duwangzhe/fpn_pytorch/lib/model/roi_pooling/modules/roi_pool.py", line 14, in forward return RoIPoolFunction(self.pooled_height, self.pooled_width, scale)(features, rois) File "/home/zhuyuhe/duwangzhe/fpn_pytorch/lib/model/roi_pooling/functions/roi_pool.py", line 26, in forward features, rois, output, ctx.argmax) File "/home/zhuyuhe/.conda/envs/dwzpy/lib/python3.5/site-packages/torch/utils/ffi/init.py", line 197, in safe_call result = torch._C._safe_call(*args, **kwargs) TypeError: float() not supported on cdata 'void *' Anyone can help me? Thx!

    opened by duwangzhe 1
  • ImportError:/fpn.pytorch-master/lib/model/nms/_ext/nms/_nms.so: undefined symbol: __cudaPopCallConfiguration

    ImportError:/fpn.pytorch-master/lib/model/nms/_ext/nms/_nms.so: undefined symbol: __cudaPopCallConfiguration

    When there is a problem with demo.py, we first use the demo.py given by the author @jwyang and report an error import error: no module named fast_ rcnn.faster_ rcnn_ cascade。 It was found that the demo of the project was not updated for FPN, so it was replaced by the demo.py provided by @Zongxianlee. My environment is Python 2.7.18, CUDA 9.0.176, torch 0.4.0 torch vision 0.2.1 cudatoolkit 9.0. It is confirmed that the CUDA version is consistent with the CUDA version of PyTorch, but running the updated demo.py still reports an error: undefined symbol:__ cudaPopCallConfiguration。Any idea about the problem? Thanks!

    demo.py出现问题,最开始使用作者@jwyang给出的demo.py,报错ImportError: No module named faster_rcnn.faster_rcnn_cascade。发现该项目的demo并没有针对FPN更新,于是换成了@ZongxianLee 提供的demo.py. 我的环境是:python 2.7.18 、cuda 9.0.176 、torch 0.4.0 torchvision 0.2.1 cudatoolkit 9.0. 确定了cuda的版本和pytorch 的cuda版本是一致的,但运行更新后的demo.py依旧报错:undefined symbol: __cudaPopCallConfiguration。有什么建议吗?谢谢!

    opened by AndrewNest 0
  • sh make.sh 编译不通过

    sh make.sh 编译不通过

    进入代码目录 到lib,首先要编译c代码 sh make.sh,但是我得到了以下错误 fpn.pytorch/lib/model/roi_crop/src/roi_crop.c:10:30: error: dereferencing pointer to incomplete type int batchsize = inputImages->size[0]; ^ /fpn.pytorch/lib/model/roi_crop/src/roi_crop.c:11:39: error: dereferencing pointer to incomplete type int inputImages_height = inputImages->size[1]; 2020-11-29-14-27-04

    opened by lllllmaster-lulllll 0
  • Why is the result not as good as faster-rcnn? Have you modified the code?

    Why is the result not as good as faster-rcnn? Have you modified the code?

    I have run this code, based on resnet101, the best epoch result is 70.1, which is much less compared to faster-rcnn ---74.X, I want to know why?Can you tell me?Thank you!

    opened by puyiwen 0
  • roi pooling

    roi pooling

    grid_xy = _affine_grid_gen(rois, base_feat.size()[2:], self.grid_size)
    

    NameError: global name 'base_feat' is not defined how to solve this problem?Is there someone meet this problem?Hope your request,thanks!

    opened by Youggie 0
Owner
Jianwei Yang
Senior Researcher @ Microsoft
Jianwei Yang
The code repository for "RCNet: Reverse Feature Pyramid and Cross-scale Shift Network for Object Detection" (ACM MM'21)

RCNet: Reverse Feature Pyramid and Cross-scale Shift Network for Object Detection (ACM MM'21) By Zhuofan Zong, Qianggang Cao, Biao Leng Introduction F

TempleX 9 Jul 30, 2022
This is an unofficial implementation of the paper “Student-Teacher Feature Pyramid Matching for Unsupervised Anomaly Detection”.

This is an unofficial implementation of the paper “Student-Teacher Feature Pyramid Matching for Unsupervised Anomaly Detection”.

haifeng xia 32 Oct 26, 2022
[ICCV 2021] FaPN: Feature-aligned Pyramid Network for Dense Image Prediction

FaPN: Feature-aligned Pyramid Network for Dense Image Prediction [arXiv] [Project Page] @inproceedings{ huang2021fapn, title={{FaPN}: Feature-alig

Shihua Huang 23 Jul 22, 2022
An Implementation of SiameseRPN with Feature Pyramid Networks

SiameseRPN with FPN This project is mainly based on HelloRicky123/Siamese-RPN. What I've done is just add a Feature Pyramid Network method to the orig

null 3 Apr 16, 2022
Pyramid R-CNN: Towards Better Performance and Adaptability for 3D Object Detection

Pyramid R-CNN: Towards Better Performance and Adaptability for 3D Object Detection

null 61 Jan 7, 2023
Pyramid Grafting Network for One-Stage High Resolution Saliency Detection. CVPR 2022

PGNet Pyramid Grafting Network for One-Stage High Resolution Saliency Detection. CVPR 2022, CVPR 2022 (arXiv 2204.05041) Abstract Recent salient objec

CVTEAM 109 Dec 5, 2022
CFC-Net: A Critical Feature Capturing Network for Arbitrary-Oriented Object Detection in Remote Sensing Images

CFC-Net This project hosts the official implementation for the paper: CFC-Net: A Critical Feature Capturing Network for Arbitrary-Oriented Object Dete

ming71 55 Dec 12, 2022
a reimplementation of Optical Flow Estimation using a Spatial Pyramid Network in PyTorch

pytorch-spynet This is a personal reimplementation of SPyNet [1] using PyTorch. Should you be making use of this work, please cite the paper according

Simon Niklaus 269 Jan 2, 2023
Pytorch reimplementation of PSM-Net: "Pyramid Stereo Matching Network"

This is a Pytorch Lightning version PSMNet which is based on JiaRenChang/PSMNet. use python main.py to start training. PSM-Net Pytorch reimplementatio

XIAOTIAN LIU 1 Nov 25, 2021
This is the official implementation of 3D-CVF: Generating Joint Camera and LiDAR Features Using Cross-View Spatial Feature Fusion for 3D Object Detection, built on SECOND.

3D-CVF This is the official implementation of 3D-CVF: Generating Joint Camera and LiDAR Features Using Cross-View Spatial Feature Fusion for 3D Object

YecheolKim 97 Dec 20, 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
Hybrid CenterNet - Hybrid-supervised object detection / Weakly semi-supervised object detection

Hybrid-Supervised Object Detection System Object detection system trained by hybrid-supervision/weakly semi-supervision (HSOD/WSSOD): This project is

null 5 Dec 10, 2022
Yolo object detection - Yolo object detection with python

How to run download required files make build_image make download Docker versio

null 3 Jan 26, 2022
(IEEE TIP 2021) Regularized Densely-connected Pyramid Network for Salient Instance Segmentation

RDPNet IEEE TIP 2021: Regularized Densely-connected Pyramid Network for Salient Instance Segmentation PyTorch training and testing code are available.

Yu-Huan Wu 41 Oct 21, 2022
EDPN: Enhanced Deep Pyramid Network for Blurry Image Restoration

EDPN: Enhanced Deep Pyramid Network for Blurry Image Restoration Ruikang Xu, Zeyu Xiao, Jie Huang, Yueyi Zhang, Zhiwei Xiong. EDPN: Enhanced Deep Pyra

null 69 Dec 15, 2022
EPSANet:An Efficient Pyramid Split Attention Block on Convolutional Neural Network

EPSANet:An Efficient Pyramid Split Attention Block on Convolutional Neural Network This repo contains the official Pytorch implementaion code and conf

Hu Zhang 175 Jan 7, 2023
Adaptive Pyramid Context Network for Semantic Segmentation (APCNet CVPR'2019)

Adaptive Pyramid Context Network for Semantic Segmentation (APCNet CVPR'2019) Introduction Official implementation of Adaptive Pyramid Context Network

null 21 Nov 9, 2022
Cascaded Pyramid Network (CPN) based on Keras (Tensorflow backend)

ML2 Takehome Project Reimplementing the paper: Cascaded Pyramid Network for Multi-Person Pose Estimation Dataset The model uses the COCO dataset which

Vo Van Tu 1 Nov 22, 2021