Coder Social home page Coder Social logo

liulei01 / drbox Goto Github PK

View Code? Open in Web Editor NEW
421.0 27.0 142.0 94.25 MB

A deep learning based algorithm to detect rotated object, for example, objects in remote sensing images

License: Other

CMake 2.29% Makefile 0.59% Shell 0.38% C++ 80.91% Cuda 6.09% MATLAB 0.74% Python 9.01%
detection caffe rotation-invariant

drbox's Introduction

DRBox

By Lei Liu (mail: [email protected])

Introduction

DRBox is used for detection tasks where the objects are orientated arbitrarily. This code show examples that DRBox is used to detect vehicles, ships and airplanes in remote sensing images. I'm also looking forward for its use in other problems.

image

The codes are modified from the original Caffe and SSD.

Citing DRBox

The article for this method can be downloaded here: arXiv:1711.09405. Please cite this work in your publications if it helps your research.

Contents

  1. Installation
  2. Preparation
  3. Train
  4. Deployment
  5. View Results
  6. Build Your Own Dataset

Installation

  1. DRBox is written in Caffe with some newly defined layers. So you should prepare nessasary environment for Caffe installation. DThen you can get the code:
git clone https://github.come/liulei01/drbox.git
  1. Matlab is also neccessary so that the results can be viewed.

  2. If you only want to apply our trained models directly to your applications, then you can ignore the following instruction and jump to Deployment.

  3. Build the code. Please follow Caffe instruction to install all necessary packages and build it.

# Modify Makefile.config according to your Caffe installation.
cp Makefile.config.example Makefile.config
make -j8
# Make sure to include $CAFFE_ROOT/python to your PYTHONPATH.
make py

Preparation

  1. Download fully convolutional reduced (atrous) VGGNet. By default, we assume the model is stored in $CAFFE_ROOT/models/VGGNet/

  2. Download the training data for DRBox at https://pan.baidu.com/s/1sliHG09 , extract them and place the files at the corresponding position of data/. (Tips: There are two folders named larger and smaller respectively, you can download files in either of them. This website would ask you to install a software to download files that larger than 200M, so if you want to download file from your browser directly, you should download the files in folder "smaller".)

  3. Run create_data.sh in each subfolders in data/ to create LMDB for training. For example, when you want to train a airplane detection network, then you can

cd $CAFFEROOT
./data/Airplane/create_data.sh

Train

DRBox is now designed as a single task network. So you should train it for each type of objects separately. The python codes are in examples/rbox/. If you want to train a airplane detection network, then you can start training by:

cd $CAFFEROOT
python examples/rbox/rbox_pascal_airplane.py

Training for vehicle is similar with airplane.

cd $CAFFEROOT
python examples/rbox/rbox_pascal_car.py

Before training for ship, you should replace src/caffe/util/rbox_util.cpp with src/caffe/util.rbox_util.cpp.ship and rebuilding the codes. The reason is that we ignore the head and tail of a ship to make the problem easier.

cd $CAFFEROOT
mv src/caffe/util/rbox_util.cpp src/caffe/util/rbox_util.cpp.old
mv src/caffe/util/rbox_util.cpp.ship src/caffe/util/rbox_util.cpp
make -j8
python examples/rbox/rbox_pascal_ship_opt.py

The trained models are stored in models/RBOX/.

Deployment

The codes for deployment are in examples/rbox/deploy.

  1. If you only want to apply a pre-trained models directly to your applications in any Caffe environment, then you can copy this folder to your own Caffe folder and run the following commands.
mv librbox.cpp.code librbox.cpp
g++ -o librbox.so -shared -fPIC librbox.cpp
cp deploy.py.general_example deploy.py
# you should modify the following file accordingly.
python deploy.py
  1. Otherwise, make sure that caffemodel file, deploy.prototxt file are generated during training. Then run the following commands:
mv librbox.cpp.code librbox.cpp
g++ -o librbox.so -shared -fPIC librbox.cpp
mv librbox.cpp librbox.cpp.code
cp deploy.py.example deploy.py
# you should modify the following file accordingly.
python deploy.py

View Results

The detection results are stored in a text file named like output.rbox.score. We provide a matlab function to view the results. In matlab, open examples/rbox/deploy/SelectRotatedTarget.m and run it. You are asked to select the demo tiff figure and the output.rbox.score file, then the results will be plotted. Press Z to zoom in and X to zoom out. In the first view, each result is plotted in a red circle, you can press Z to change them to rectangles.

A .rbox.score file contains several lines where each line corresponds to one bounding box. Each line contains 7 numbers. The first two numbers are position of the center point of the bounding box. Number 3-4 are width and height of the bounding box. The 5th is the label of the object, which is fixed to 1 recently because DRBox only provide one class of predictions. The 6th number is the angle of this bounding box in degrees. The 7th is the score. The detected objects are sorted with their scores.

Build Your Own Dataset

SelectRotatedTarget.m is not only a figure plot tool, but also a bounding box labeling tool to help you build your own dataset. Firstly, run this function in Matlab and select a image. Then, when it is asked to select a .rbox file, click cancel button then a empty .rbox file will be created. Press space key to switch into edit mode, then you can press H to see instructions on how to draw a rotatable bounding box on the image. When you click right on the mouse to quit the edit mode, the marked bounding boxes will be saved to the .rbox file.

.rbox file uses a similar format with .rbox.score file to record bounding boxes, unless that each line contains 6 numbers except the score value.

drbox's People

Contributors

liulei01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

drbox's Issues

Why batch_size = 1 throws an error?

Hi,
I wanted to try batch_size 1 rather than 64 because I have only one image at a time and with 64 it takes much longer. However, when I change batch size to 1 both in the deploy.py and deploy.prototxt, I see the following error:

inputdata[count] = subimage IndexError: index 1 is out of bounds for axis 0 with size 1

dataset format

The "smaller" dataset is very large and can't be directly downloaded. Could you at least provide some guidelines on how to build our own dataset?

How do you define the angle value?

In the rbox format file, ‘xcenter >> ycenter >> anno_width >> anno_height >> label >> angle‘,
I see the angle value will be greater than 360 degrees, how do you define the angle value and determine the main direction?

more instruction for labeling tool

Hello

If you don't mind giving more instruction for labeling tool.
when I use it the .rbox file stays empty.
and also when labeling there is no feedback I mean no line or anything that shows it creating a label

make error /usr/bin/ld: cannot find -l boost_thread

image
CXX tools/upgrade_net_proto_binary.cpp CXX examples/rbox/deploy/librbox.cpp examples/rbox/deploy/librbox.cpp: In function ‘double Overlap(double*, double*)’: examples/rbox/deploy/librbox.cpp:567:7: warning: unused variable ‘i’ [-Wunused-variable] int i; ^ examples/rbox/deploy/librbox.cpp: In function ‘void DecodeAndNMS(double*, double*, int*, double*, int*, double)’: examples/rbox/deploy/librbox.cpp:574:7: warning: unused variable ‘i’ [-Wunused-variable] int i; ^ examples/rbox/deploy/librbox.cpp: In function ‘void NMS(double*, int*, double*, int*, double)’: examples/rbox/deploy/librbox.cpp:587:7: warning: unused variable ‘i’ [-Wunused-variable] int i; ^ CXX .build_release/src/caffe/proto/caffe.pb.cc AR -o .build_release/lib/libcaffe.a LD -o .build_release/lib/libcaffe.so.1.0.0-rc3 /usr/bin/ld: cannot find -l boost_thread collect2: error: ld returned 1 exit status Makefile:568: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1
can u help me ?!!
image
I have libboost_thread.o in /usr/lib,but it still cant find it
I dont know how to fix it, anyone can help me ?
thanks a lot in advance!

Could you help me!

Hi,
I can't download the files. Who can send me all the file if you have?
My qq or wechat is:409067552
Thank you!

Deployment problem

when I follow the deployment steps,error occurs as follow:

dong@dong:~/Downloads/caffe-ssd/examples/rbox/deploy/Airplane$ python deploy.py

WARNING: Logging before InitGoogleLogging() is written to STDERR
W1224 12:42:21.621986 21588 _caffe.cpp:122] DEPRECATION WARNING - deprecated use of Python interface
W1224 12:42:21.622025 21588 _caffe.cpp:123] Use this instead (with the named "weights" parameter):
W1224 12:42:21.622030 21588 _caffe.cpp:125] Net('/home/dong/Downloads/caffe-ssd/examples/rbox/deploy/Airplane/deploy.prototxt', 1, weights='/home/dong/Downloads/caffe-ssd/examples/rbox/deploy/Airplane/RBOX_AIRPLANE_RBOX_300x300_AIRPLANE_VGG_iter_140000.caffemodel')
[libprotobuf ERROR google/protobuf/text_format.cc:298] Error parsing text-format caffe.NetParameter: 483:20: Message type "caffe.LayerParameter" has no field named "prior_rbox_param".
F1224 12:42:21.624474 21588 upgrade_proto.cpp:88] Check failed: ReadProtoFromTextFile(param_file, param) Failed to parse NetParameter file: /home/dong/Downloads/caffe-ssd/examples/rbox/deploy/Airplane/deploy.prototxt
*** Check failure stack trace: ***
Aborted (core dumped)

[libprotobuf ERROR google/protobuf/text_format.cc:298] Error parsing text-format caffe.NetParameter: 483:20: Message type "caffe.LayerParameter" has no field named "prior_rbox_param".

can anyone tell me why?How to solve this??

Thanks in advance!

The Use of Functions SelectRotatedTarget.m

I want to use this function SelectRotatedTarget.m to annotate my data set, but the Edit mode (selection point) has no response when we click the image . How to solve this problem?

Question on GPU build with GFORCE RTX 2080

Hi, we are working on ubuntu 18.04 with NVIDIA GeForce RTX 2080 with driver version 418.56. cuda version 10.1.
Is caffe compatible with this gpu and driver? It is not working for us.

make error ---Headache problem ina long time

default
it's a strange question while I make the project.I spent a lot of time debugging。But there are almost no corresponding answers to the online answers.So I have to ask you for help, can you give me some advice?

hello, How to use this "DummyData"?

layer {
name: "data"
type: "DummyData"
top: "data"
dummy_data_param {
shape {
dim: 1
dim: 3
dim: 300
dim: 300
}
}
}
How do I use DummyData when I use deploy.PROTOTXT to make a prediction in caffe.cpp?,thanks very much .

what‘s the impact of resolution

@ liulei01 thank for your work

the resolution in labeling tool was set as 1, I found that change it will cause different box size,besides that , does it have other influences?

请问,这个resolution参数除了标注数据时候除了影响box大小以外还有别的影响吗,谢谢

the loss of detection is so high

@liulei01 I am wondering why the the detection loss is so high? Does this normal?
1202 I1225 12:11:46.674068 9085 caffe.cpp:243] Resuming from models/RBOX/Airplane/RBOX_300x300_AIRPLANE_VGG_new/RBOX_AIRPLANE_RBOX_300x300_AIRPLANE_VGG_new_iter_81472.solverstate
1203 I1225 12:11:46.745776 9085 sgd_solver.cpp:356] SGDSolver: restoring history
1204 I1225 12:11:46.810129 9085 caffe.cpp:253] Starting Optimization
1205 I1225 12:11:46.810154 9085 solver.cpp:295] Solving RBOX_AIRPLANE_RBOX_300x300_AIRPLANE_VGG_new_train
1206 I1225 12:11:46.810158 9085 solver.cpp:296] Learning Rate Policy: multistep
1207 I1225 12:11:47.542913 9085 solver.cpp:244] Iteration 81472, loss = 46.3588
1208 I1225 12:11:47.542959 9085 solver.cpp:260] Train net output #0: mbox_loss_plane = 46.3588 (* 1 = 46.3588 loss)
1209 I1225 12:11:47.542980 9085 sgd_solver.cpp:138] Iteration 81472, lr = 2.5e-06
1210 I1225 12:11:48.096568 9085 solver.cpp:244] Iteration 81473, loss = 67.1444
1211 I1225 12:11:48.096614 9085 solver.cpp:260] Train net output #0: mbox_loss_plane = 87.93 (* 1 = 87.93 loss)
1212 I1225 12:11:48.096622 9085 sgd_solver.cpp:138] Iteration 81473, lr = 2.5e-06
1213 I1225 12:11:48.610831 9085 solver.cpp:244] Iteration 81474, loss = 88.3024
1214 I1225 12:11:48.610878 9085 solver.cpp:260] Train net output #0: mbox_loss_plane = 130.618 (* 1 = 130.618 loss)
1215 I1225 12:11:48.610887 9085 sgd_solver.cpp:138] Iteration 81474, lr = 2.5e-06
1216 I1225 12:11:49.130704 9085 solver.cpp:244] Iteration 81475, loss = 111.279
1217 I1225 12:11:49.130739 9085 solver.cpp:260] Train net output #0: mbox_loss_plane = 180.209 (* 1 = 180.209 loss)
1218 I1225 12:11:49.130746 9085 sgd_solver.cpp:138] Iteration 81475, lr = 2.5e-06
1219 I1225 12:11:49.671315 9085 solver.cpp:244] Iteration 81476, loss = 132.512
1220 I1225 12:11:49.671350 9085 solver.cpp:260] Train net output #0: mbox_loss_plane = 217.444 (* 1 = 217.444 loss)
1221 I1225 12:11:49.671357 9085 sgd_solver.cpp:138] Iteration 81476, lr = 2.5e-06
1222 I1225 12:11:50.194638 9085 solver.cpp:244] Iteration 81477, loss = 153.352
1223 I1225 12:11:50.194689 9085 solver.cpp:260] Train net output #0: mbox_loss_plane = 257.552 (* 1 = 257.552 loss)

CUDNN and OpenCV version

Hi,

If I want to use images with different resolution e.g. 15 cm. what should I change?

I have changed "resolution" parameter in > SelectRotatedTarget.m to 0.15.
Also in deploy.py file I have changed "resolutionIn = 0.15 and resolutionOut = [0.15]. The results are however so bad only a few cars are detected with mostly wrong rotation estimation.
I am using a 569x561px image.

BTW, I am trying to install your modified caffe with CUDNN and OpenCV.
Could you please let me know which version you used?

python.h no such file

I tried install on ubuntu 18.04 ,when I run make py got errors below,

CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
python/caffe/_caffe.cpp:1:52: fatal error: Python.h: No such file or directory
#include <Python.h> // NOLINT(build/include_alpha)
^
compilation terminated.
Makefile:505: recipe for target 'python/caffe/_caffe.so' failed
make: *** [python/caffe/_caffe.so] Error 1

and my PYTHONPATH set as below

(caffe) llc@qkm:~/workshop/DRBox-master$ echo $PYTHONPATH
/home/llc/workshop/DRBox-master/python

Make Error

I think your project has some bugs, can you compile this project????

question about your dataset

Did you evaluate the three models(DRBox, Faster R-CNN, SSD) with the totally same dataset? It's not so clear to me when I read your paper.

I mean Faster R-CNN and SSD only works for the horizontal bounding box, so you create a larger bounding box to cover the rotated bounding box on the same image? Then DRBox uses the smaller rotated bounding box, faster R-CNN uses the larger horizontal bounding box.

There is limited research on rotated bounding box in this domain, you provide a nice way to solve it, hope you will provide more continuous valuable work. (e.g. when there are many overlap objects, whether there are some conflicts in predicting bounding box for each of them, especially when we use non-maximum suppression approach to remove duplicate neighbor bounding box)

Thank you for your work!

cannot find trainval.txt

thanks for your github
i ran create_data.sh and it said cannot find trainval.txt
could you tell me how to fix it

How should I evaluate the model?

I have trained a model with my own dataset. I want to evaluate the performance of this model, so how should I evaluate the model? I want to get the value of AP and P-R curve.

Issue training custom dataset

I made a very small dataset just to test the framework. I placed the files in data/MyDataset/train_data (jpg files and .jpg.rbox files with same name). The I created the trainval.txt file in data/MyDataset and I copied create_data.sh in the same folder. I ran the script and two MDB files were generated (data and lock). Finally, I created a script in examples/rbox just like the others and I ran it, but I got the following error:

I0828 15:01:18.558032 26291 base_data_layer.cpp:32] DataLayerSetUp:
I0828 15:01:18.559165 26298 db_lmdb.cpp:35] Opened lmdb examples/MyDataset/MyDataset_trainval_lmdb
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
*** Aborted at 1535461278 (unix time) try "date -d @1535461278" if you are using GNU date ***

Did I do something wrong?

About openmp errors in building the code.

Hi liulei, thanks for your great job! I downloaded the project and tried to buid it on Ubuntu 14.04. It seems like that you work on Ubuntu 16, so I changed lib "libhdf5-serial" to "libhdf5" in "Makefile" but I got some errors about "openmp", such like "undefined xxxxxx". Then I add "-fopenmp" in "Makefile", code could be compiled. When I "import caffe" with python, still getting errors about openmp. What's wrong with it? I feel so confused, eager for your reply~~~

librbox.so的源码

编译librbox.cpp.code生成的librbox.so与现成提供的的librbox.so文件应该是不一样的吧,请问你能提供下代码吗,因为我想在window上运行,因此要讲动态库转换成 .dll ,所以需要源代码,谢谢

你好,请问长、宽,角度标记时是怎么确定的

cv::RotatedRect rect = cv::RotatedRect(cv::Point(centerX, centerY), cv::Size(widths, heights), -angle);
cv::Point2f vertices[4];
rect.points(vertices);
for (int k = 0; k < 4; k++)
{
cv::line(img, vertices[k], vertices[(k + 1) % 4], cv::Scalar(0, 0, 255));
}
我使用你的标记信息,使用此函数在图像上把框画出来,不知道正确与否?因为画框与角度太相关。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

第二个问:
此外,我在标记的时候,每个目标对应一些列的凸包点,
std::vector<std::vectorcv::Point>pointBase(position.size());
Rect = cv::minAreaRect(pointBase[i]); // 第 i 个目标
cv::Point2f P[4];
Rect.points(P);
以此求出目标的外接矩形、宽高、角度,此角度不能直接用,它是[-90, 0],因此我采用图像矩求的外接矩形的角度。

第三问:
请问是你的标记信息是否是规定x方向就是宽,y方向就是高?
目前训练不收敛,应该是自己准备的数据的角度有问题,还请大大你指点,非常感谢!!!

Not able to run deployment

Hi

Thanks for sharing your work, I am facing some difficulty in getting the deployment code to work.

As mentioned i cloned the repo, and move the deploy folder to my caffe root.

mv librbox.cpp.code librbox.cpp 
g++ -o librbox.so -shared -fPIC librbox.cpp
cp deploy.py.general_example deploy.py

but when i run this

python deploy.py

i get

  File "deploy.py", line 3, in <module>
    from caffe.model_libs import *
ImportError: No module named model_libs

Did i mess up any step?

Any suggestions would be really helpful.
Thanks in advance.

coding missing

Is there a script that converts rbox files into trainlists in the code? Is this what we need to write ourselves?

can`t find -lhdf5_serial_hl

Hi @liulei01 , sorry for bothering you. When I make caffe, I got the following information. What I should do?

AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
/usr/bin/ld: 找不到 -lhdf5_serial_hl
/usr/bin/ld: 找不到 -lhdf5_serial
collect2: error: ld returned 1 exit status
make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] 错误 1

make error

I compiled your code under ubuntu14.04 system, but there was an error about openmp, I can not solve it myself, asking for your help. Looking forward to your reply. Very grateful!
2018-01-31 16 21 45

The model was trained with a custom dataset and found that nothing was learned

hello,recently, I use custom dataset to train a model but found that nothing was learned.because prediction has no result.
I am trying to modify the airplane rbox_pascal_airplane. py files, to train the new dataset, and the corresponding DRBox/examples/rbox/deploy/airplane/deploy. py and deploy. prototxt file used for prediction and display.The training process well,I'm not quite sure what caused this problem. Could you give me some advice? Thank you very much.

error on stdlib.h

Hi, I was having a problem with make. This is the error I'm getting.
/usr/include/c++/7/cstdlib:75:15: fatal error: stdlib.h: No such file or directory

IndexError: index 1 is out of bounds for axis 0 with size 1

I wanted to try batch_size 1 rather than 64 because I have only one image at a time and with 64 it takes much longer. However, when I change batch size to 1 both in the deploy.py and deploy.prototxt, I see the following error:

inputdata[count] = subimage IndexError: index 1 is out of bounds for axis 0 with size 1

Extraction problem!!!

Hi, I download the dataset from the network disk, and I also use command cat data.tar.gz*>data.tar.gz to merge each subfile together. But I get an error when I unzip the data.tar.gz use the command "tar -zxvf data.tar.gz". Which command should I use to unzip the tar file, thank you!

Wrong Code

In src/caffe/util/rbox_util.cpp, line 887, the first rbox2 should be changed to rbox1

Database Annotation

Hello,
anyone has Annotation for a different database with the same format as this reposit.
I am still working on my database, but I still need a different database.
Once I finish mine, I will provide a link here.

Please, any database will help.

out of memory

I tried to execute "python deploy.py" under "drbox/examples/rbox/deploy/Airplane", and the error is:

Check failed: error == cudaSuccess (2 vs. 0) out of memory

I'm using GeForce GTX 1070 (8GB). Does it means that GeForce GTX 1070 has not enough memory to run DRBox on it?
What's the hardware requirement for DRBox?

Hello, Thank you very much for your Git

What is the data storage format of the label TXT file?For example, there are multiple targets in an image, and how it corresponds to the label TXT file. I can't open the downloaded data and show the damage.Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.