A faster pytorch implementation of faster r-cnn

Overview

A Faster Pytorch Implementation of Faster R-CNN

Write at the beginning

[05/29/2020] This repo was initaited about two years ago, developed as the first open-sourced object detection code which supports multi-gpu training. It has been integrating tremendous efforts from many people. However, we have seen many high-quality repos emerged in the last years, such as:

At this point, I think this repo is out-of-data in terms of the pipeline and coding style, and will not maintain actively. Though you can still use this repo as a playground, I highly recommend you move to the above repos to delve into west world of object detection!

Introduction

💥 Good news! This repo supports pytorch-1.0 now!!! We borrowed some code and techniques from maskrcnn-benchmark. Just go to pytorch-1.0 branch!

This project is a faster pytorch implementation of faster R-CNN, aimed to accelerating the training of faster R-CNN object detection models. Recently, there are a number of good implementations:

During our implementing, we referred the above implementations, especailly longcw/faster_rcnn_pytorch. However, our implementation has several unique and new features compared with the above implementations:

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

  • It supports multi-image batch training. We revise all the layers, including dataloader, rpn, roi-pooling, etc., to support multiple images in each minibatch.

  • It supports multiple GPUs training. 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. More importantly, we modify all of them to support multi-image batch training.

  • It is memory efficient. We limit the image aspect ratio, and group images with similar aspect ratios into a minibatch. As such, we can train resnet101 and VGG16 with batchsize = 4 (4 images) on a single Titan X (12 GB). When training with 8 GPU, the maximum batchsize for each GPU is 3 (Res101), totaling 24.

  • It is faster. Based on the above modifications, the training is much faster. We report the training speed on NVIDIA TITAN Xp in the tables below.

What we are doing and going to do

  • Support both python2 and python3 (great thanks to cclauss).
  • Add deformable pooling layer (mainly supported by Xander).
  • Support pytorch-0.4.0 (this branch).
  • Support tensorboardX.
  • Support pytorch-1.0 (go to pytorch-1.0 branch).

Other Implementations

Tutorial

Benchmarking

We benchmark our code thoroughly on three datasets: pascal voc, coco and visual genome, using two different network architectures: vgg16 and resnet101. 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     time/epoch mem/GPU mAP
VGG-16     1 1 1e-3 5   6   0.76 hr 3265MB   70.1
VGG-16     1 4 4e-3 9   0.50 hr 9083MB   69.6
VGG-16     8 16 1e-2  8   10 0.19 hr 5291MB 69.4
VGG-16     8 24 1e-2 10 11 0.16 hr 11303MB 69.2
Res-101 1 1 1e-3 5 7 0.88 hr 3200 MB 75.2
Res-101   1 4 4e-3 8   10 0.60 hr 9700 MB 74.9
Res-101   8 16 1e-2 8   10 0.23 hr 8400 MB 75.2 
Res-101   8 24 1e-2 10 12 0.17 hr 10327MB 75.1  

2). COCO (Train/Test: coco_train+coco_val-minival/minival, scale=800, max_size=1200, ROI Align)

model #GPUs batch size lr lr_decay max_epoch time/epoch mem/GPU mAP
VGG-16     8 16   1e-2 4 6 4.9 hr 7192 MB 29.2
Res-101   8 16   1e-2 4   6 6.0 hr 10956 MB 36.2
Res-101   8 16   1e-2 4   10 6.0 hr 10956 MB 37.0

NOTE. Since the above models use scale=800, you need add "--ls" at the end of test command.

3). COCO (Train/Test: coco_train+coco_val-minival/minival, scale=600, max_size=1000, ROI Align)

model #GPUs batch size lr lr_decay max_epoch time/epoch mem/GPU mAP
Res-101   8 24   1e-2 4   6 5.4 hr   10659 MB 33.9
Res-101   8 24   1e-2 4   10 5.4 hr   10659 MB 34.5

4). Visual Genome (Train/Test: vg_train/vg_test, scale=600, max_size=1000, ROI Align, category=2500)

model #GPUs batch size lr lr_decay max_epoch time/epoch mem/GPU mAP
VGG-16   1 P100 4   1e-3 5   20 3.7 hr   12707 MB 4.4

Thanks to Remi for providing the pretrained detection model on visual genome!

  • Click the links in the above tables to download our pre-trained faster r-cnn models.
  • If not mentioned, the GPU we used is NVIDIA Titan X Pascal (12GB).

Preparation

First of all, clone the code

git clone https://github.com/jwyang/faster-rcnn.pytorch.git

Then, create a folder:

cd faster-rcnn.pytorch && mkdir data

prerequisites

  • Python 2.7 or 3.6
  • Pytorch 0.4.0 (now it does not support 0.4.1 or higher)
  • CUDA 8.0 or higher

Data Preparation

  • PASCAL_VOC 07+12: Please follow the instructions in py-faster-rcnn to prepare VOC datasets. Actually, you can refer to any others. After downloading the data, create softlinks in the folder data/.

  • COCO: Please also follow the instructions in py-faster-rcnn to prepare the data.

  • Visual Genome: Please follow the instructions in bottom-up-attention to prepare Visual Genome dataset. You need to download the images and object annotation files first, and then perform proprecessing to obtain the vocabulary and cleansed annotations based on the scripts provided in this repository.

Pretrained Model

We used two pretrained models in our experiments, VGG and ResNet101. You can download these two models from:

Download them and put them into the data/pretrained_model/.

NOTE. We compare the pretrained models from Pytorch and Caffe, and surprisingly find Caffe pretrained models have slightly better performance than Pytorch pretrained. We would suggest to use Caffe pretrained models from the above link to reproduce our results.

If you want to use pytorch pre-trained models, please remember to transpose images from BGR to RGB, and also use the same data transformer (minus mean and normalize) as used in pretrained model.

Compilation

As pointed out by ruotianluo/pytorch-faster-rcnn, choose the right -arch in make.sh file, to compile the cuda code:

GPU model Architecture
TitanX (Maxwell/Pascal) sm_52
GTX 960M sm_50
GTX 1080 (Ti) sm_61
Grid K520 (AWS g2.2xlarge) sm_30
Tesla K80 (AWS p2.xlarge) sm_37

More details about setting the architecture can be found here or here

Install all the python dependencies using pip:

pip install -r requirements.txt

Compile the cuda dependencies using following simple commands:

cd lib
sh make.sh

It will compile all the modules you need, including NMS, ROI_Pooing, ROI_Align and ROI_Crop. The default version is compiled with Python 2.7, please compile by yourself if you are using a different python version.

As pointed out in this issue, if you encounter some error during the compilation, you might miss to export the CUDA paths to your environment.

Train

Before training, set the right directory to save and load the trained models. Change the arguments "save_dir" and "load_dir" in trainval_net.py and test_net.py to adapt to your environment.

To train a faster R-CNN model with vgg16 on pascal_voc, simply run:

CUDA_VISIBLE_DEVICES=$GPU_ID python trainval_net.py \
                   --dataset pascal_voc --net vgg16 \
                   --bs $BATCH_SIZE --nw $WORKER_NUMBER \
                   --lr $LEARNING_RATE --lr_decay_step $DECAY_STEP \
                   --cuda

where 'bs' is the batch size with default 1. Alternatively, to train with resnet101 on pascal_voc, simple run:

 CUDA_VISIBLE_DEVICES=$GPU_ID python trainval_net.py \
                    --dataset pascal_voc --net res101 \
                    --bs $BATCH_SIZE --nw $WORKER_NUMBER \
                    --lr $LEARNING_RATE --lr_decay_step $DECAY_STEP \
                    --cuda

Above, BATCH_SIZE and WORKER_NUMBER can be set adaptively according to your GPU memory size. On Titan Xp with 12G memory, it can be up to 4.

If you have multiple (say 8) Titan Xp GPUs, then just use them all! Try:

python trainval_net.py --dataset pascal_voc --net vgg16 \
                       --bs 24 --nw 8 \
                       --lr $LEARNING_RATE --lr_decay_step $DECAY_STEP \
                       --cuda --mGPUs

Change dataset to "coco" or 'vg' if you want to train on COCO or Visual Genome.

Test

If you want to evaluate the detection performance of a pre-trained vgg16 model on pascal_voc test set, simply run

python test_net.py --dataset pascal_voc --net vgg16 \
                   --checksession $SESSION --checkepoch $EPOCH --checkpoint $CHECKPOINT \
                   --cuda

Specify the specific model session, checkepoch and checkpoint, e.g., SESSION=1, EPOCH=6, CHECKPOINT=416.

Demo

If you want to run detection on your own images with a pre-trained model, download the pretrained model listed in above tables or train your own models at first, then add images to folder $ROOT/images, and then run

python demo.py --net vgg16 \
               --checksession $SESSION --checkepoch $EPOCH --checkpoint $CHECKPOINT \
               --cuda --load_dir path/to/model/directoy

Then you will find the detection results in folder $ROOT/images.

Note the default demo.py merely support pascal_voc categories. You need to change the line to adapt your own model.

Below are some detection results:

Webcam Demo

You can use a webcam in a real-time demo by running

python demo.py --net vgg16 \
               --checksession $SESSION --checkepoch $EPOCH --checkpoint $CHECKPOINT \
               --cuda --load_dir path/to/model/directoy \
               --webcam $WEBCAM_ID

The demo is stopped by clicking the image window and then pressing the 'q' key.

Authorship

This project is equally contributed by Jianwei Yang and Jiasen Lu, and many others (thanks to them!).

Citation

@article{jjfaster2rcnn,
    Author = {Jianwei Yang and Jiasen Lu and Dhruv Batra and Devi Parikh},
    Title = {A Faster Pytorch Implementation of Faster R-CNN},
    Journal = {https://github.com/jwyang/faster-rcnn.pytorch},
    Year = {2017}
}

@inproceedings{renNIPS15fasterrcnn,
    Author = {Shaoqing Ren and Kaiming He and Ross Girshick and Jian Sun},
    Title = {Faster {R-CNN}: Towards Real-Time Object Detection
             with Region Proposal Networks},
    Booktitle = {Advances in Neural Information Processing Systems ({NIPS})},
    Year = {2015}
}
Comments
  • No module named cython_bbox

    No module named cython_bbox

    Hi, I'm trying your code but when I run:

    CUDA_VISIBLE_DEVICES=$GPU_ID python trainval_net.py --dataset pascal_voc --net vgg16 --cuda --bs $BATCH_SIZE

    for the training I have this error:

    from model.utils.cython_bbox import bbox_overlaps ImportError: No module named cython_bbox

    I've just installed cython doing: sudo pip install cython

    Thanks in advance

    opened by capuzz 37
  • CompileError: command 'gcc' failed with exit status 1

    CompileError: command 'gcc' failed with exit status 1

    I use anaconda(with python3.6) and cuda9.0(GTX1070), when I compile the make.sh, I got a problem which displayed:

    root@mqxwd68-System-Product-Name:/home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib# sh make.sh running build_ext skipping 'model/utils/bbox.c' Cython extension (up-to-date) skipping 'pycocotools/_mask.c' Cython extension (up-to-date) Compiling nms kernels by nvcc... Including CUDA code. /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/nms ['/home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/nms/src/nms_cuda_kernel.cu.o'] generating /tmp/tmpsosri8sf/_nms.c setting the current directory to '/tmp/tmpsosri8sf' running build_ext building '_nms' extension creating home creating home/mqxwd68 creating home/mqxwd68/Downloads creating home/mqxwd68/Downloads/pytorchFiles creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/nms creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/nms/src gcc -pthread -B /root/anaconda3/compiler_compat -Wl,--sysroot=/ -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/root/anaconda3/include/python3.6m -c _nms.c -o ./_nms.o -std=c99 gcc -pthread -B /root/anaconda3/compiler_compat -Wl,--sysroot=/ -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/root/anaconda3/include/python3.6m -c /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/nms/src/nms_cuda.c -o ./home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/nms/src/nms_cuda.o -std=c99 /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/nms/src/nms_cuda.c: In function ‘nms_cuda’: /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/nms/src/nms_cuda.c:14:22: error: dereferencing pointer to incomplete type ‘THCTensor {aka struct THCTensor}’ boxes_host->size[0], ^ Traceback (most recent call last): File "/root/anaconda3/lib/python3.6/distutils/unixccompiler.py", line 118, in _compile extra_postargs) File "/root/anaconda3/lib/python3.6/distutils/ccompiler.py", line 909, in spawn spawn(cmd, dry_run=self.dry_run) File "/root/anaconda3/lib/python3.6/distutils/spawn.py", line 36, in spawn _spawn_posix(cmd, search_path, dry_run=dry_run) File "/root/anaconda3/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix % (cmd, exit_status)) distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "/root/anaconda3/lib/python3.6/site-packages/cffi/ffiplatform.py", line 51, in _build dist.run_command('build_ext') File "/root/anaconda3/lib/python3.6/distutils/dist.py", line 974, in run_command cmd_obj.run() File "/root/anaconda3/lib/python3.6/distutils/command/build_ext.py", line 339, in run self.build_extensions() File "/root/anaconda3/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions self._build_extensions_serial() File "/root/anaconda3/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial self.build_extension(ext) File "/root/anaconda3/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension depends=ext.depends) File "/root/anaconda3/lib/python3.6/distutils/ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/root/anaconda3/lib/python3.6/distutils/unixccompiler.py", line 120, in _compile raise CompileError(msg) distutils.errors.CompileError: command 'gcc' failed with exit status 1

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "build.py", line 37, in ffi.build() File "/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/init.py", line 189, in build _build_extension(ffi, cffi_wrapper_name, target_dir, verbose) File "/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/init.py", line 111, in _build_extension outfile = ffi.compile(tmpdir=tmpdir, verbose=verbose, target=libname) File "/root/anaconda3/lib/python3.6/site-packages/cffi/api.py", line 697, in compile compiler_verbose=verbose, debug=debug, **kwds) File "/root/anaconda3/lib/python3.6/site-packages/cffi/recompiler.py", line 1520, in recompile compiler_verbose, debug) File "/root/anaconda3/lib/python3.6/site-packages/cffi/ffiplatform.py", line 22, in compile outputfilename = _build(tmpdir, ext, compiler_verbose, debug) File "/root/anaconda3/lib/python3.6/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 Compiling roi pooling kernels by nvcc... /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_pooling Including CUDA code. generating /tmp/tmpgb2kylxp/_roi_pooling.c setting the current directory to '/tmp/tmpgb2kylxp' running build_ext building '_roi_pooling' extension creating home creating home/mqxwd68 creating home/mqxwd68/Downloads creating home/mqxwd68/Downloads/pytorchFiles creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_pooling creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_pooling/src gcc -pthread -B /root/anaconda3/compiler_compat -Wl,--sysroot=/ -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/root/anaconda3/include/python3.6m -c _roi_pooling.c -o ./_roi_pooling.o -std=c99 gcc -pthread -B /root/anaconda3/compiler_compat -Wl,--sysroot=/ -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/root/anaconda3/include/python3.6m -c /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_pooling/src/roi_pooling.c -o ./home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_pooling/src/roi_pooling.o -std=c99 gcc -pthread -B /root/anaconda3/compiler_compat -Wl,--sysroot=/ -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/root/anaconda3/include/python3.6m -c /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_pooling/src/roi_pooling_cuda.c -o ./home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_pooling/src/roi_pooling_cuda.o -std=c99 gcc -pthread -shared -B /root/anaconda3/compiler_compat -L/root/anaconda3/lib -Wl,-rpath=/root/anaconda3/lib -Wl,--no-as-needed -Wl,--sysroot=/ -std=c99 ./_roi_pooling.o ./home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_pooling/src/roi_pooling.o ./home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_pooling/src/roi_pooling_cuda.o /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_pooling/src/roi_pooling.cu.o -o ./_roi_pooling.so Compiling roi align kernels by nvcc... /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_align Including CUDA code. generating /tmp/tmphjs0kouq/_roi_align.c setting the current directory to '/tmp/tmphjs0kouq' running build_ext building '_roi_align' extension creating home creating home/mqxwd68 creating home/mqxwd68/Downloads creating home/mqxwd68/Downloads/pytorchFiles creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_align creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_align/src gcc -pthread -B /root/anaconda3/compiler_compat -Wl,--sysroot=/ -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/root/anaconda3/include/python3.6m -c _roi_align.c -o ./_roi_align.o -std=c99 gcc -pthread -B /root/anaconda3/compiler_compat -Wl,--sysroot=/ -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/root/anaconda3/include/python3.6m -c /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_align/src/roi_align.c -o ./home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_align/src/roi_align.o -std=c99 /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_align/src/roi_align.c: In function ‘roi_align_backward’: /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_align/src/roi_align.c:65:9: warning: unused variable ‘batch_size’ [-Wunused-variable] int batch_size = THFloatTensor_size(bottom_grad, 0); ^ /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_align/src/roi_align.c: In function ‘ROIAlignForwardCpu’: /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_align/src/roi_align.c:87:0: warning: ignoring #pragma omp parallel [-Wunknown-pragmas] #pragma omp parallel for ^ /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_align/src/roi_align.c: In function ‘ROIAlignBackwardCpu’: /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_align/src/roi_align.c:145:0: warning: ignoring #pragma omp parallel [-Wunknown-pragmas] #pragma omp parallel for ^ gcc -pthread -B /root/anaconda3/compiler_compat -Wl,--sysroot=/ -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/root/anaconda3/include/python3.6m -c /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_align/src/roi_align_cuda.c -o ./home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_align/src/roi_align_cuda.o -std=c99 gcc -pthread -shared -B /root/anaconda3/compiler_compat -L/root/anaconda3/lib -Wl,-rpath=/root/anaconda3/lib -Wl,--no-as-needed -Wl,--sysroot=/ -std=c99 ./_roi_align.o ./home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_align/src/roi_align.o ./home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_align/src/roi_align_cuda.o /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_align/src/roi_align_kernel.cu.o -o ./_roi_align.so Compiling roi crop kernels by nvcc... Including CUDA code. /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop generating /tmp/tmpecg3_z_m/_roi_crop.c setting the current directory to '/tmp/tmpecg3_z_m' running build_ext building '_roi_crop' extension creating home creating home/mqxwd68 creating home/mqxwd68/Downloads creating home/mqxwd68/Downloads/pytorchFiles creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop creating home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop/src gcc -pthread -B /root/anaconda3/compiler_compat -Wl,--sysroot=/ -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/root/anaconda3/include/python3.6m -c _roi_crop.c -o ./_roi_crop.o -std=c99 gcc -pthread -B /root/anaconda3/compiler_compat -Wl,--sysroot=/ -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/root/anaconda3/include/python3.6m -c /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop/src/roi_crop.c -o ./home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop/src/roi_crop.o -std=c99 /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop/src/roi_crop.c: In function ‘BilinearSamplerBHWD_updateOutput’: /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop/src/roi_crop.c:10:30: error: dereferencing pointer to incomplete type ‘THTensor {aka struct THTensor}’ int batchsize = inputImages->size[0]; ^ /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop/src/roi_crop.c: In function ‘BilinearSamplerBHWD_updateGradInput’: /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop/src/roi_crop.c:190:14: warning: unused variable ‘inBottomRight’ [-Wunused-variable] real inBottomRight=0; ^ /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop/src/roi_crop.c:189:14: warning: unused variable ‘inBottomLeft’ [-Wunused-variable] real inBottomLeft=0; ^ /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop/src/roi_crop.c:188:14: warning: unused variable ‘inTopRight’ [-Wunused-variable] real inTopRight=0; ^ /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop/src/roi_crop.c:187:14: warning: unused variable ‘inTopLeft’ [-Wunused-variable] real inTopLeft=0; ^ /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop/src/roi_crop.c:186:14: warning: unused variable ‘v’ [-Wunused-variable] real v=0; ^ /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop/src/roi_crop.c: In function ‘BilinearSamplerBCHW_updateGradInput’: /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop/src/roi_crop.c:441:14: warning: unused variable ‘inBottomRight’ [-Wunused-variable] real inBottomRight=0; ^ /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop/src/roi_crop.c:440:14: warning: unused variable ‘inBottomLeft’ [-Wunused-variable] real inBottomLeft=0; ^ /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop/src/roi_crop.c:439:14: warning: unused variable ‘inTopRight’ [-Wunused-variable] real inTopRight=0; ^ /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop/src/roi_crop.c:438:14: warning: unused variable ‘inTopLeft’ [-Wunused-variable] real inTopLeft=0; ^ /home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib/model/roi_crop/src/roi_crop.c:437:14: warning: unused variable ‘v’ [-Wunused-variable] real v=0; ^ Traceback (most recent call last): File "/root/anaconda3/lib/python3.6/distutils/unixccompiler.py", line 118, in _compile extra_postargs) File "/root/anaconda3/lib/python3.6/distutils/ccompiler.py", line 909, in spawn spawn(cmd, dry_run=self.dry_run) File "/root/anaconda3/lib/python3.6/distutils/spawn.py", line 36, in spawn _spawn_posix(cmd, search_path, dry_run=dry_run) File "/root/anaconda3/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix % (cmd, exit_status)) distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "/root/anaconda3/lib/python3.6/site-packages/cffi/ffiplatform.py", line 51, in _build dist.run_command('build_ext') File "/root/anaconda3/lib/python3.6/distutils/dist.py", line 974, in run_command cmd_obj.run() File "/root/anaconda3/lib/python3.6/distutils/command/build_ext.py", line 339, in run self.build_extensions() File "/root/anaconda3/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions self._build_extensions_serial() File "/root/anaconda3/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial self.build_extension(ext) File "/root/anaconda3/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension depends=ext.depends) File "/root/anaconda3/lib/python3.6/distutils/ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/root/anaconda3/lib/python3.6/distutils/unixccompiler.py", line 120, in _compile raise CompileError(msg) distutils.errors.CompileError: command 'gcc' failed with exit status 1

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "build.py", line 36, in ffi.build() File "/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/init.py", line 189, in build _build_extension(ffi, cffi_wrapper_name, target_dir, verbose) File "/root/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/init.py", line 111, in _build_extension outfile = ffi.compile(tmpdir=tmpdir, verbose=verbose, target=libname) File "/root/anaconda3/lib/python3.6/site-packages/cffi/api.py", line 697, in compile compiler_verbose=verbose, debug=debug, **kwds) File "/root/anaconda3/lib/python3.6/site-packages/cffi/recompiler.py", line 1520, in recompile compiler_verbose, debug) File "/root/anaconda3/lib/python3.6/site-packages/cffi/ffiplatform.py", line 22, in compile outputfilename = _build(tmpdir, ext, compiler_verbose, debug) File "/root/anaconda3/lib/python3.6/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 root@mqxwd68-System-Product-Name:/home/mqxwd68/Downloads/pytorchFiles/faster-rcnn.pytorch/lib#


    Here is my make.sh:

    export CUDA_PATH=/usr/local/cuda/

    python setup.py build_ext --inplace rm -rf build

    CUDA_ARCH="-gencode arch=compute_60,code=sm_60 "

    cd model/nms/src echo "Compiling nms kernels by nvcc..." nvcc -c -o nms_cuda_kernel.cu.o nms_cuda_kernel.cu
    -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH

    cd ../ python build.py

    cd ../../ cd model/roi_pooling/src echo "Compiling roi pooling kernels by nvcc..." nvcc -c -o roi_pooling.cu.o roi_pooling_kernel.cu
    -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH cd ../ python build.py

    cd ../../ cd model/roi_align/src echo "Compiling roi align kernels by nvcc..." nvcc -c -o roi_align_kernel.cu.o roi_align_kernel.cu
    -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH cd ../ python build.py

    cd ../../ cd model/roi_crop/src echo "Compiling roi crop kernels by nvcc..." nvcc -c -o roi_crop_cuda_kernel.cu.o roi_crop_cuda_kernel.cu
    -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH cd ../ python build.py


    Are there any problems with my gcc or Anaconda? Or how do I compile it with python3.6?(Just see the introduction "The default version is compiled with Python 2.7, please compile by yourself if you are using a different python version.") I'm looking forward to an answer

    opened by DaVilla7 33
  • undefined symbol: __cudaPopCallConfiguration

    undefined symbol: __cudaPopCallConfiguration

    I've successfully compiled the cuda dependencies for ROI pooling. Everything looks fine but when I try to call the function RoIPoolFunction(), it comes an error:

    ImportError: /home/faster-rcnn.pytorch/lib/model/roi_pooling/_ext/roi_pooling/_roi_pooling.so: undefined symbol: __cudaPopCallConfiguration

    Any idea about the problem ? I'm using CUDA 9.2 and pytorch 0.4.

    Thanks!

    opened by xyang35 33
  • Training custom dataset

    Training custom dataset

    Hi @jwyang, As i mentioned in a previous post I would like to train a Faster-R-CNN model (vgg16) with my own dataset. I have followed this post based on the code of Ross Girshick but adapting it to your implementation. Now I'm trying to adapt the network model to my dataset but i don't know what should i modify to do it? Do you have any idea that could guide me? Thanks!!

    PS: I know that there is a closed issue regarding this but i posted here just in case you don't follow up closed issues.

    opened by JavHaro 28
  • Where is the _roi_polling.so

    Where is the _roi_polling.so

    There is a file _roi_align.so in /lib/model/roi_align/_ext/roi_align but the file _roi_polling.so not in /lib/model/roi_pooling/_ext/roi_pooling Thank you for answer my question

    opened by g5996706 26
  • A problem with sh make.sh

    A problem with sh make.sh

    : not found make.sh: : not found make.sh: : not found: make.sh: : not found: make.sh: usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py --help-commands or: setup.py cmd --help

    not recognized-inplace make.sh: 15: make.sh: rm: not found : not found: make.sh: : not found: make.sh: make.sh: 20: cd: can't cd to model/nms/src Compiling nms kernels by nvcc... nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified make.sh: 23: make.sh: -D: not found : not found: make.sh: make.sh: 25: cd: can't cd to ../ ': [Errno 2] No such file or directory : not found: make.sh: make.sh: 29: cd: can't cd to ../../ make.sh: 30: cd: can't cd to model/roi_pooling/src Compiling roi pooling kernels by nvcc... nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified make.sh: 33: make.sh: -D: not found make.sh: 34: cd: can't cd to ../ ': [Errno 2] No such file or directory : not found: make.sh: make.sh: 38: cd: can't cd to ../../ make.sh: 39: cd: can't cd to model/roi_align/src Compiling roi align kernels by nvcc... nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified make.sh: 42: make.sh: -D: not found make.sh: 43: cd: can't cd to ../ ': [Errno 2] No such file or directory : not found: make.sh: make.sh: 47: cd: can't cd to ../../ make.sh: 48: cd: can't cd to model/roi_crop/src Compiling roi crop kernels by nvcc... nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified make.sh: 51: make.sh: -D: not found make.sh: 52: cd: can't cd to ../ ': [Errno 2] No such file or directory

    So I do it step by step python setup.py build_ext --inplace rm -rf build

    CUDA_ARCH="-gencode arch=compute_70,code=sm_70"

    compile NMS

    cd model/nms/src echo "Compiling nms kernels by nvcc..." nvcc -c -o nms_cuda_kernel.cu.o nms_cuda_kernel.cu
    -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH

    The above is ok

    cd ../ python build.py

    this line I got the problem

    Including CUDA code. /home/wty/torch/faster-rcnn.pytorch/lib/model/nms ['/home/wty/torch/faster-rcnn.pytorch/lib/model/nms/src/nms_cuda_kernel.cu.o'] Traceback (most recent call last): File "build.py", line 33, in extra_objects=extra_objects File "/usr/local/lib/python2.7/dist-packages/torch/utils/ffi/init.py", line 179, in create_extension ffi.cdef(_typedefs + all_headers_source) File "/usr/local/lib/python2.7/dist-packages/cffi/api.py", line 107, in cdef self._cdef(csource, override=override, packed=packed) File "/usr/local/lib/python2.7/dist-packages/cffi/api.py", line 121, in _cdef self._parser.parse(csource, override=override, **options) File "/usr/local/lib/python2.7/dist-packages/cffi/cparser.py", line 315, in parse self._internal_parse(csource) File "/usr/local/lib/python2.7/dist-packages/cffi/cparser.py", line 320, in _internal_parse ast, macros, csource = self._parse(csource) File "/usr/local/lib/python2.7/dist-packages/cffi/cparser.py", line 278, in _parse self.convert_pycparser_error(e, csource) File "/usr/local/lib/python2.7/dist-packages/cffi/cparser.py", line 307, in convert_pycparser_error raise CDefError(msg) cffi.error.CDefError: parse error :31:1: Illegal character '\r'

    I do the search and I don't know why it's wrong? could someone help me with this? thanks

    opened by WangTianYuan 25
  • Pytorch 1.0 branch ImportError: torch.utils.ffi is deprecated

    Pytorch 1.0 branch ImportError: torch.utils.ffi is deprecated

    I followed the instructions for Pytorch 1.0: switched to pytorch-1.0 branch, went to lib and ran python setup.py build develop. Install succeeded with no errors.

    However, when I try to import roi_pool in the Python prompt, I get "torch.utils.ffi is deprecated" error. Isn't this supposed to be fixed in the pytorch-1.0 branch?

    Python 3.7.2 (default, Dec 29 2018, 06:19:36) 
    [GCC 7.3.0] :: Anaconda, Inc. on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from model.roi_pooling.modules import roi_pool
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/remoteuser/faster-rcnn.pytorch/lib/model/roi_pooling/modules/roi_pool.py", line 2, in <module>
        from ..functions.roi_pool import RoIPoolFunction
      File "/home/remoteuser/faster-rcnn.pytorch/lib/model/roi_pooling/functions/roi_pool.py", line 3, in <module>
        from .._ext import roi_pooling
      File "/home/remoteuser/faster-rcnn.pytorch/lib/model/roi_pooling/_ext/roi_pooling/__init__.py", line 2, in <module>
        from torch.utils.ffi import _wrap_function
      File "/home/remoteuser/.miniconda3/envs/outfit/lib/python3.7/site-packages/torch/utils/ffi/__init__.py", line 1, in <module>
        raise ImportError("torch.utils.ffi is deprecated. Please use cpp extensions instead.")
    ImportError: torch.utils.ffi is deprecated. Please use cpp extensions instead.
    

    Thank you!

    opened by andrewjong 22
  • ValueError: bg_num_rois = 0 and fg_num_rois = 0, this should not happen!

    ValueError: bg_num_rois = 0 and fg_num_rois = 0, this should not happen!

    When I tried to train the network with my own dataset which is actually https://github.com/udacity/self-driving-car/tree/master/annotations, this problem occurs after 900 iterations in the first epoch. Can you point out the source of problem?

    opened by artuncF 21
  • nms_gpu throws runtime error: illegal memory access

    nms_gpu throws runtime error: illegal memory access

    Trying to train this model on my own dataset.
    I converted it to pascal voc format, assured max resolution is of 1000 (most images are 600x900), adjusted some fine details, but I get the following error while training:

    Called with args:
    Namespace(batch_size=8, checkepoch=1, checkpoint=0, checkpoint_interval=10000, checksession=1, class_agnostic=False, cuda=True, dataset='my_custom_ds', disp_interval=100, large_scale=False, lr=0.004, lr_decay_gamma=0.1, lr_decay_step=8, mGPUs=True, max_epochs=2, net='res101', num_workers=2, optimizer='sgd', resume=False, save_dir='saved_models', session=1, start_epoch=1, use_tfboard=False)
    Using config:
    {'ANCHOR_RATIOS': [0.5, 1, 2],
     'ANCHOR_SCALES': [8, 16, 32],
     'CROP_RESIZE_WITH_MAX_POOL': False,
     'CUDA': False,
     'DATA_DIR': '/home/cyb/user/pycharm/src/faster-rcnn.pytorch/data',
     'DEDUP_BOXES': 0.0625,
     'EPS': 1e-14,
     'EXP_DIR': 'res101',
     'FEAT_STRIDE': [16],
     'GPU_ID': 0,
     'MATLAB': 'matlab',
     'MAX_NUM_GT_BOXES': 93,
     'MOBILENET': {'DEPTH_MULTIPLIER': 1.0,
                   'FIXED_LAYERS': 5,
                   'REGU_DEPTH': False,
                   'WEIGHT_DECAY': 4e-05},
     'PIXEL_MEANS': array([[[ 102.9801,  115.9465,  122.7717]]]),
     'POOLING_MODE': 'align',
     'POOLING_SIZE': 7,
     'RESNET': {'FIXED_BLOCKS': 1, 'MAX_POOL': False},
     'RNG_SEED': 3,
     'ROOT_DIR': '/home/cyb/user/pycharm/src/faster-rcnn.pytorch',
     'TEST': {'BBOX_REG': True,
              'HAS_RPN': True,
              'MAX_SIZE': 1000,
              'MODE': 'nms',
              'NMS': 0.3,
              'PROPOSAL_METHOD': 'gt',
              'RPN_MIN_SIZE': 16,
              'RPN_NMS_THRESH': 0.7,
              'RPN_POST_NMS_TOP_N': 300,
              'RPN_PRE_NMS_TOP_N': 6000,
              'RPN_TOP_N': 5000,
              'SCALES': [600],
              'SVM': False},
     'TRAIN': {'ASPECT_GROUPING': False,
               'BATCH_SIZE': 128,
               'BBOX_INSIDE_WEIGHTS': [1.0, 1.0, 1.0, 1.0],
               'BBOX_NORMALIZE_MEANS': [0.0, 0.0, 0.0, 0.0],
               'BBOX_NORMALIZE_STDS': [0.1, 0.1, 0.2, 0.2],
               'BBOX_NORMALIZE_TARGETS': True,
               'BBOX_NORMALIZE_TARGETS_PRECOMPUTED': True,
               'BBOX_REG': True,
               'BBOX_THRESH': 0.5,
               'BG_THRESH_HI': 0.5,
               'BG_THRESH_LO': 0.0,
               'BIAS_DECAY': False,
               'BN_TRAIN': False,
               'DISPLAY': 20,
               'DOUBLE_BIAS': False,
               'FG_FRACTION': 0.25,
               'FG_THRESH': 0.5,
               'GAMMA': 0.1,
               'HAS_RPN': True,
               'IMS_PER_BATCH': 1,
               'LEARNING_RATE': 0.001,
               'MAX_SIZE': 1000,
               'MOMENTUM': 0.9,
               'PROPOSAL_METHOD': 'gt',
               'RPN_BATCHSIZE': 256,
               'RPN_BBOX_INSIDE_WEIGHTS': [1.0, 1.0, 1.0, 1.0],
               'RPN_CLOBBER_POSITIVES': False,
               'RPN_FG_FRACTION': 0.5,
               'RPN_MIN_SIZE': 8,
               'RPN_NEGATIVE_OVERLAP': 0.3,
               'RPN_NMS_THRESH': 0.7,
               'RPN_POSITIVE_OVERLAP': 0.7,
               'RPN_POSITIVE_WEIGHT': -1.0,
               'RPN_POST_NMS_TOP_N': 2000,
               'RPN_PRE_NMS_TOP_N': 12000,
               'SCALES': [600],
               'SNAPSHOT_ITERS': 5000,
               'SNAPSHOT_KEPT': 3,
               'SNAPSHOT_PREFIX': 'res101_faster_rcnn',
               'STEPSIZE': [30000],
               'SUMMARY_INTERVAL': 180,
               'TRIM_HEIGHT': 600,
               'TRIM_WIDTH': 600,
               'TRUNCATED': False,
               'USE_ALL_GT': True,
               'USE_FLIPPED': True,
               'USE_GT': False,
               'WEIGHT_DECAY': 0.0001},
     'USE_GPU_NMS': True}
    Loaded dataset `voc_2007_trainval` for training
    Set proposal method: gt
    Appending horizontally-flipped training examples...
    wrote gt roidb to /home/cyb/user/pycharm/src/faster-rcnn.pytorch/data/cache/voc_2007_trainval_gt_roidb.pkl
    done
    Preparing training data...
    done
    before filtering, there are 4224 images...
    after filtering, there are 4224 images...
    4224 roidb entries
    /home/cyb/user/pycharm/src/faster-rcnn.pytorch/lib/model/rpn/rpn.py:68: 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)
    /home/cyb/user/pycharm/src/faster-rcnn.pytorch/lib/model/faster_rcnn/faster_rcnn.py:98: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.
      cls_prob = F.softmax(cls_score)
    [session 1][epoch  1][iter    0] loss: 233749.3594, lr: 4.00e-03
    			fg/bg=(24/1000), time cost: 6.419112
    			rpn_cls: 179158.4219, rpn_box: 41295.5859, rcnn_cls: 9535.8477, rcnn_box 3759.5171
    THCudaCheck FAIL file=/opt/conda/conda-bld/pytorch_1513368888240/work/torch/lib/THC/generic/THCTensorMath.cu line=267 error=77 : an illegal memory access was encountered
    an illegal memory access was encountered
    CUDA Error: an illegal memory access was encountered, at line 147
    CUDA Error: an illegal memory access was encountered, at line 154
    an illegal memory access was encountered
    an illegal memory access was encountered
    Traceback (most recent call last):
      File "/home/cyb/user/pycharm/src/faster-rcnn.pytorch/trainval_net.py", line 326, in <module>
        rois_label = fasterRCNN(im_data, im_info, gt_boxes, num_boxes)
      File "/home/cyb/user/.conda/envs/my_proj/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in __call__
        result = self.forward(*input, **kwargs)
      File "/home/cyb/user/.conda/envs/my_proj/lib/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 68, in forward
        outputs = self.parallel_apply(replicas, inputs, kwargs)
      File "/home/cyb/user/.conda/envs/my_proj/lib/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 78, in parallel_apply
        return parallel_apply(replicas, inputs, kwargs, self.device_ids[:len(replicas)])
      File "/home/cyb/user/.conda/envs/my_proj/lib/python3.6/site-packages/torch/nn/parallel/parallel_apply.py", line 67, in parallel_apply
        raise output
      File "/home/cyb/user/.conda/envs/my_proj/lib/python3.6/site-packages/torch/nn/parallel/parallel_apply.py", line 42, in _worker
        output = module(*input, **kwargs)
      File "/home/cyb/user/.conda/envs/my_proj/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in __call__
        result = self.forward(*input, **kwargs)
      File "/home/cyb/user/pycharm/src/faster-rcnn.pytorch/lib/model/faster_rcnn/faster_rcnn.py", line 50, in forward
        rois, rpn_loss_cls, rpn_loss_bbox = self.RCNN_rpn(base_feat, im_info, gt_boxes, num_boxes)
      File "/home/cyb/user/.conda/envs/my_proj/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in __call__
        result = self.forward(*input, **kwargs)
      File "/home/cyb/user/pycharm/src/faster-rcnn.pytorch/lib/model/rpn/rpn.py", line 78, in forward
        im_info, cfg_key))
      File "/home/cyb/user/.conda/envs/my_proj/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in __call__
        result = self.forward(*input, **kwargs)
      File "/home/cyb/user/pycharm/src/faster-rcnn.pytorch/lib/model/rpn/proposal_layer.py", line 148, in forward
        keep_idx_i = nms(torch.cat((proposals_single, scores_single), 1), nms_thresh)
      File "/home/cyb/user/pycharm/src/faster-rcnn.pytorch/lib/model/nms/nms_wrapper.py", line 18, in nms
        return nms_gpu(dets, thresh)
      File "/home/cyb/user/pycharm/src/faster-rcnn.pytorch/lib/model/nms/nms_gpu.py", line 11, in nms_gpu
        keep = keep[:num_out[0]]
    RuntimeError: cuda runtime error (77) : an illegal memory access was encountered at /opt/conda/conda-bld/pytorch_1513368888240/work/torch/lib/THC/generic/THCStorage.c:36
    
    Process finished with exit code 1
    

    I have two Titan K40 cards, however it's an illegal access and not out of memory error, so I wonder where does it come from.

    opened by CodeJjang 19
  • error in test_net.py

    error in test_net.py

    python test_net.py --dataset pascal_voc --net vgg16 --checksession 1 --checkepoch 19 --checkpoint 1251 --cuda

    Traceback (most recent call last): File "test_net.py", line 225, in rois, cls_prob, bbox_pred, rpn_loss, rcnn_loss = fasterRCNN(im_data, im_info, gt_boxes, num_boxes) File "/raid/home/wangw/.pyenv/versions/2.7.13/lib/python2.7/site-packages/torch/nn/modules/module.py", line 325, in call result = self.forward(*input, **kwargs) File "/raid/wangw/faster-rcnn.pytorch/lib/model/faster_rcnn/faster_rcnn_cascade.py", line 97, in forward bbox_pred_select = torch.gather(bbox_pred_view, 1, rois_label.long().view(rois_label.size(0), 1, 1).expand(rois_label.size(0), 1, 4)) AttributeError: 'NoneType' object has no attribute 'long'

    type(rois_label) is Nonetype, so it crashed, how to solve this problem? Thanks for your answer.

    opened by RichardMrLu 17
  •  Low mAP on pytorch 1.0 branch

    Low mAP on pytorch 1.0 branch

    I downloaded the trained model from here.

    model | #GPUs | batch size | lr | lr_decay | max_epoch | time/epoch | mem/GPU | mAP -- | -- | -- | -- | -- | -- | -- | -- | -- VGG-16 | 1 | 1 | 1e-3 | 5 | 6 | 0.76 hr | 3265MB | 70.1

    I use pytorch 1.0, and the mAP on pascal voc 2007 is 65.8, which is lower than 70.1. Here is the APs for each category.

    VOC07 metric? Yes
    AP for aeroplane = 0.6559
    AP for bicycle = 0.7750
    AP for bird = 0.6105
    AP for boat = 0.4600
    AP for bottle = 0.4542
    AP for bus = 0.7689
    AP for car = 0.7686
    AP for cat = 0.8393
    AP for chair = 0.4700
    AP for cow = 0.6777
    AP for diningtable = 0.6060
    AP for dog = 0.7668
    AP for horse = 0.8110
    AP for motorbike = 0.6922
    AP for person = 0.7295
    AP for pottedplant = 0.3714
    AP for sheep = 0.6060
    AP for sofa = 0.6509
    AP for train = 0.7408
    AP for tvmonitor = 0.7092
    Mean AP = 0.6582
    

    I also tested on the master branch using pytorch 0.4.0. The results are as follows:

    VOC07 metric? Yes
    AP for aeroplane = 0.7055
    AP for bicycle = 0.7761
    AP for bird = 0.6638
    AP for boat = 0.5457
    AP for bottle = 0.5221
    AP for bus = 0.8086
    AP for car = 0.8450
    AP for cat = 0.8411
    AP for chair = 0.5025
    AP for cow = 0.7824
    AP for diningtable = 0.6539
    AP for dog = 0.7754
    AP for horse = 0.8294
    AP for motorbike = 0.7267
    AP for person = 0.7726
    AP for pottedplant = 0.4223
    AP for sheep = 0.7188
    AP for sofa = 0.6555
    AP for train = 0.7526
    AP for tvmonitor = 0.7277
    Mean AP = 0.7014
    

    Is there something wrong about the evaluation code?

    opened by DHZS 16
  • failure of Compilation with command

    failure of Compilation with command "python setup.py build develop"

    Dear Jian Wei I've tried to build this project in conda envs with python3.6 and pytorch1.0.0 . But encountered failure when compiling the cuda dependencies using commands "python setup.py build develop" in lib folder.

    • Envs:

        OS: Manjaro Linux 21.2.6
        GCC version: gcc 12.1.0
        Gpu version: GeForce RTX 2050
        Pytorch version: pytorch 1.0.0 (py3.6_cuda9.0.176_cudnn7.4.1_1)
      
    • Configuration path:

        PATH=$PATH:/opt/cuda/bin:~/anaconda3/bin
        LD_LIBRARY_PATH=/opt/cuda/lib64:$LD_LIBRARY_PATH
        CUDA_HOME=/opt/cuda
      
    • Traceback:

    required from here /home/yang_hao/anaconda3/envs/faster-rcnn/lib/python3.6/site-packages/torch/lib/include/c10/util/ArrayRef.h:96:93: 警告:initializing ‘c10::ArrayRef::Data’ from ‘std::initializer_list::begin’ does not extend the lifetime of the underlying array [-Winit-list-lifetime] error: command '/opt/cuda/bin/nvcc' failed with exit status 1

    opened by ThomaswellY 0
  • Try to convert pth to onnx. But error

    Try to convert pth to onnx. But error

    I wanna convert pth to onnx format. This is my code:

    import torch from model.faster_rcnn.vgg16 import vgg16 from model.faster_rcnn.resnet import resnet import numpy as np from torch.autograd import Variable

    def load_model(model, pretrained_path): print('Loading pretrained model from {}'.format(pretrained_path)) pretrained_dict = torch.load(pretrained_path, map_location=lambda storage, loc: storage)
    model.load_state_dict(pretrained_dict, strict=False) return model

    output_onnx = './output.onnx' raw_weights = './faster_rcnn_1_10_2504.pth' pascal_classes = np.asarray(['background', 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor'])

    load weight

    net = resnet(pascal_classes, 101, pretrained=False, class_agnostic=False) net.create_architecture() checkpoint = torch.load(raw_weights) for k in checkpoint.keys(): print(k)
    net.load_state_dict(checkpoint['model'])

    initilize the tensor holder here.

    im_data = torch.FloatTensor(1) im_info = torch.FloatTensor(1) num_boxes = torch.LongTensor(1) gt_boxes = torch.FloatTensor(1)

    ship to cuda

    im_data = im_data.cuda() im_info = im_info.cuda() num_boxes = num_boxes.cuda() gt_boxes = gt_boxes.cuda()

    make variable

    im_data = Variable(im_data, volatile=True) im_info = Variable(im_info, volatile=True) num_boxes = Variable(num_boxes, volatile=True) gt_boxes = Variable(gt_boxes, volatile=True)

    net.eval() print('Finished loading model!') device = torch.device("cuda") net = net.to(device)

    input_names = ["input0"] output_names = ["output0"] inputs = torch.randn(1, 3, 300, 300).to(device)

    output model

    torch_out = torch.onnx.export(net, inputs, output_onnx, export_params=True, verbose=False,keep_initializers_as_inputs=True, input_names=input_names, output_names=output_names)

    but when I run it, I got this error. How can I fix it?Thanks! Traceback (most recent call last): File "pth2onnx.py", line 67, in torch_out = torch.onnx.export(net, inputs, output_onnx, export_params=True, verbose=False,keep_initializers_as_inputs=True, input_names=input_names, output_names=output_names) File "/usr/local/lib/python3.6/dist-packages/torch/onnx/init.py", line 276, in export custom_opsets, enable_onnx_checker, use_external_data_format) File "/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py", line 94, in export use_external_data_format=use_external_data_format) File "/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py", line 701, in _export dynamic_axes=dynamic_axes) File "/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py", line 459, in _model_to_graph use_new_jit_passes) File "/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py", line 420, in _create_jit_graph graph, torch_out = _trace_and_get_graph_from_model(model, args) File "/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py", line 380, in _trace_and_get_graph_from_model torch.jit._get_trace_graph(model, args, strict=False, _force_outplace=False, _return_inputs_states=True) File "/usr/local/lib/python3.6/dist-packages/torch/jit/_trace.py", line 1139, in _get_trace_graph outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "/usr/local/lib/python3.6/dist-packages/torch/jit/_trace.py", line 130, in forward self._force_outplace, File "/usr/local/lib/python3.6/dist-packages/torch/jit/_trace.py", line 116, in wrapper outs.append(self.inner(*trace_inputs)) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 887, in _call_impl result = self._slow_forward(*input, **kwargs) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 860, in _slow_forward result = self.forward(*input, **kwargs) TypeError: forward() missing 3 required positional arguments: 'im_info', 'gt_boxes', and 'num_boxes'

    opened by caizhaoxin 0
  • I want to convert to onnx

    I want to convert to onnx

    It has error: RuntimeError: Only tuples, lists and Variables are supported as JIT inputs/outputs. Dictionaries and strings are also accepted, but their usage is not recommended. Here, received an input of unsupported type: int Has anyone tried converting to onnx?

    opened by velonica0 3
  • Pytorch 1.11

    Pytorch 1.11

    Hi everyone. I'm pretty sure this repo is not maintained, you clearly stated in the readme :) But it looks like some people still try to use it, including me. I updated some of the stuff to support latest packages (including pytorch 1.11) in case anyone is stubborn enough.

    opened by cagdasbas 0
Owner
Jianwei Yang
Senior Researcher @ Microsoft
Jianwei Yang
NFT-Price-Prediction-CNN - Using visual feature extraction, prices of NFTs are predicted via CNN (Alexnet and Resnet) architectures.

NFT-Price-Prediction-CNN - Using visual feature extraction, prices of NFTs are predicted via CNN (Alexnet and Resnet) architectures.

null 5 Nov 3, 2022
PyTorch implementation of the Quasi-Recurrent Neural Network - up to 16 times faster than NVIDIA's cuDNN LSTM

Quasi-Recurrent Neural Network (QRNN) for PyTorch Updated to support multi-GPU environments via DataParallel - see the the multigpu_dataparallel.py ex

Salesforce 1.3k Dec 28, 2022
A pytorch implementation of faster RCNN detection framework (Use detectron2, it's a masterpiece)

Notice(2019.11.2) This repo was built back two years ago when there were no pytorch detection implementation that can achieve reasonable performance.

Ruotian(RT) Luo 1.8k Jan 1, 2023
Tacotron 2 - PyTorch implementation with faster-than-realtime inference

Tacotron 2 (without wavenet) PyTorch implementation of Natural TTS Synthesis By Conditioning Wavenet On Mel Spectrogram Predictions. This implementati

NVIDIA Corporation 4.1k Jan 3, 2023
Dense Deep Unfolding Network with 3D-CNN Prior for Snapshot Compressive Imaging, ICCV2021 [PyTorch Code]

Dense Deep Unfolding Network with 3D-CNN Prior for Snapshot Compressive Imaging, ICCV2021 [PyTorch Code]

Jian Zhang 20 Oct 24, 2022
This repository contains the implementation of the paper: "Towards Frequency-Based Explanation for Robust CNN"

RobustFreqCNN About This repository contains the implementation of the paper "Towards Frequency-Based Explanation for Robust CNN" arxiv. It primarly d

Sarosij Bose 2 Jan 23, 2022
This is a Keras implementation of a CNN for estimating age, gender and mask from a camera.

face-detector-age-gender This is a Keras implementation of a CNN for estimating age, gender and mask from a camera. Before run face detector app, expr

Devdreamsolution 2 Dec 4, 2021
A CNN implementation using only numpy. Supports multidimensional images, stride, etc.

A CNN implementation using only numpy. Supports multidimensional images, stride, etc. Speed up due to heavy use of slicing and mathematical simplification..

null 2 Nov 30, 2021
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
Faster RCNN with PyTorch

Faster RCNN with PyTorch Note: I re-implemented faster rcnn in this project when I started learning PyTorch. Then I use PyTorch in all of my projects.

Long Chen 1.6k Dec 23, 2022
A GPU-optional modular synthesizer in pytorch, 16200x faster than realtime, for audio ML researchers.

torchsynth The fastest synth in the universe. Introduction torchsynth is based upon traditional modular synthesis written in pytorch. It is GPU-option

torchsynth 229 Jan 2, 2023
Faster RCNN pytorch windows

Faster-RCNN-pytorch-windows Faster RCNN implementation with pytorch for windows Open cmd, compile this comands: cd lib python setup.py build develop T

Hwa-Rang Kim 1 Nov 11, 2022
FAIR's research platform for object detection research, implementing popular algorithms like Mask R-CNN and RetinaNet.

Detectron is deprecated. Please see detectron2, a ground-up rewrite of Detectron in PyTorch. Detectron Detectron is Facebook AI Research's software sy

Facebook Research 25.5k Jan 7, 2023
CoTr: Efficiently Bridging CNN and Transformer for 3D Medical Image Segmentation

CoTr: Efficient 3D Medical Image Segmentation by bridging CNN and Transformer This is the official pytorch implementation of the CoTr: Paper: CoTr: Ef

null 218 Dec 25, 2022
git《Beta R-CNN: Looking into Pedestrian Detection from Another Perspective》(NeurIPS 2020) GitHub:[fig3]

Beta R-CNN: Looking into Pedestrian Detection from Another Perspective This is the pytorch implementation of our paper "[Beta R-CNN: Looking into Pede

null 35 Sep 8, 2021
A spherical CNN for weather forecasting

DeepSphere-Weather - Deep Learning on the sphere for weather/climate applications. The code in this repository provides a scalable and flexible framew

DeepSphere 47 Dec 25, 2022
BossNAS: Exploring Hybrid CNN-transformers with Block-wisely Self-supervised Neural Architecture Search

BossNAS This repository contains PyTorch evaluation code, retraining code and pretrained models of our paper: BossNAS: Exploring Hybrid CNN-transforme

Changlin Li 127 Dec 26, 2022
《A-CNN: Annularly Convolutional Neural Networks on Point Clouds》(2019)

A-CNN: Annularly Convolutional Neural Networks on Point Clouds Created by Artem Komarichev, Zichun Zhong, Jing Hua from Department of Computer Science

Artёm Komarichev 44 Feb 24, 2022
Detection of drones using their thermal signatures from thermal camera through YOLO-V3 based CNN with modifications to encapsulate drone motion

Drone Detection using Thermal Signature This repository highlights the work for night-time drone detection using a using an Optris PI Lightweight ther

Chong Yu Quan 6 Dec 31, 2022