Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ksaito-ut committed Mar 24, 2019
0 parents commit 1f8e8ae
Show file tree
Hide file tree
Showing 148 changed files with 19,319 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Jianwei Yang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# A Pytorch Implementation of Strong-Weak Distribution Alignment for Adaptive Object Detection

<img src='./docs/swda.png' width=900/>
## Introduction
Follow [original repository](https://github.com/jwyang/faster-rcnn.pytorch).
to setup the environment. When installing pytorch-faster-rcnn, you may encounter some issues.
Many issues have been reported there to setup the environment.
### Data Preparation

* **PASCAL_VOC 07+12**: Please follow the instructions in [py-faster-rcnn](https://github.com/rbgirshick/py-faster-rcnn#beyond-the-demo-installation-for-training-and-testing-models) to prepare VOC datasets. Actually, you can refer to any others. After downloading the data, creat softlinks in the folder data/.
* **Clipart, WaterColor**: Dataset preparation instruction link [Cross Domain Detection ](https://github.com/naoto0804/cross-domain-detection/tree/master/datasets). Images translated by Cyclegan are available in the website.
* **Sim10k**: Website [Sim10k](https://fcav.engin.umich.edu/sim-dataset/)
* **Cityscape-Translated Sim10k**: TBA
* **CitysScape, FoggyCityscape**: Download website [Cityscape](https://www.cityscapes-dataset.com/)

All codes are written to fit for the format of PASCAL_VOC.
For example, the dataset [Sim10k](https://fcav.engin.umich.edu/sim-dataset/) is stored as follows.

```
$ cd Sim10k/VOC2012/
$ ls
Annotations ImageSets JPEGImages
$ cat ImageSets/Main/val.txt
3384827.jpg
3384828.jpg
3384829.jpg
.
.
.
```
If you want to test the code on your own dataset, arange the dataset
in the format of PASCAL, make dataset class in lib/datasets/. and add
it to lib/datasets/factory.py, lib/datasets/config_dataset.py. Then, add the dataset option to lib/model/utils/parser_func.py.
### Data Path
Write your dataset directories' paths in lib/datasets/config_dataset.py.

### Pretrained Model

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

* VGG16: [Dropbox](https://www.dropbox.com/s/s3brpk0bdq60nyb/vgg16_caffe.pth?dl=0), [VT Server](https://filebox.ece.vt.edu/~jw2yang/faster-rcnn/pretrained-base-models/vgg16_caffe.pth)

* ResNet101: [Dropbox](https://www.dropbox.com/s/iev3tkbz5wyyuz9/resnet101_caffe.pth?dl=0), [VT Server](https://filebox.ece.vt.edu/~jw2yang/faster-rcnn/pretrained-base-models/resnet101_caffe.pth)

Download them and write the path in __C.VGG_PATH and __C.RESNET_PATH at lib/model/utils/config.py.

## Train
* With only local alignment loss,
```
CUDA_VISIBLE_DEVICES=$GPU_ID python trainval_net_local.py \
--dataset source_dataset --dataset_t target_dataset --net vgg16 \
--cuda
```
Add --lc when using context-vector based regularization loss.

* With only global alignment loss,
```
CUDA_VISIBLE_DEVICES=$GPU_ID python trainval_net_global.py \
--dataset source_dataset --dataset_t target_dataset --net vgg16 \
--cuda
```
Add --gc when using context-vector based regularization loss.
* With global and local alignment loss,
```
CUDA_VISIBLE_DEVICES=$GPU_ID python trainval_net_global_local.py \
--dataset source_dataset --dataset_t target_dataset --net vgg16 \
--cuda
```
Add --lc and --gc when using context-vector based regularization loss.
## Test

```
CUDA_VISIBLE_DEVICES=$GPU_ID python test_net_global_local.py \
--dataset target_dataset --net vgg16 \
--cuda --lc --gc --load_name path_to_model
```
15 changes: 15 additions & 0 deletions _init_paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os.path as osp
import sys

def add_path(path):
if path not in sys.path:
sys.path.insert(0, path)

this_dir = osp.dirname(__file__)

# Add lib to PYTHONPATH
lib_path = osp.join(this_dir, 'lib')
add_path(lib_path)

coco_path = osp.join(this_dir, 'data', 'coco', 'PythonAPI')
add_path(coco_path)
19 changes: 19 additions & 0 deletions cfgs/res101.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
EXP_DIR: res101
TRAIN:
HAS_RPN: True
BBOX_NORMALIZE_TARGETS_PRECOMPUTED: True
RPN_POSITIVE_OVERLAP: 0.7
RPN_BATCHSIZE: 256
PROPOSAL_METHOD: gt
BG_THRESH_LO: 0.0
DISPLAY: 20
BATCH_SIZE: 128
RPN_POST_NMS_TOP_N_TARGET: 128
WEIGHT_DECAY: 0.0001
DOUBLE_BIAS: False
LEARNING_RATE: 0.001
TEST:
HAS_RPN: True
POOLING_SIZE: 7
POOLING_MODE: align
CROP_RESIZE_WITH_MAX_POOL: False
22 changes: 22 additions & 0 deletions cfgs/res101_ls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
EXP_DIR: res101
TRAIN:
HAS_RPN: True
BBOX_NORMALIZE_TARGETS_PRECOMPUTED: True
RPN_POSITIVE_OVERLAP: 0.7
RPN_BATCHSIZE: 256
PROPOSAL_METHOD: gt
BG_THRESH_LO: 0.0
DISPLAY: 20
BATCH_SIZE: 128
WEIGHT_DECAY: 0.0001
SCALES: [800]
DOUBLE_BIAS: False
LEARNING_RATE: 0.001
TEST:
HAS_RPN: True
SCALES: [800]
MAX_SIZE: 1200
RPN_POST_NMS_TOP_N: 1000
POOLING_SIZE: 7
POOLING_MODE: align
CROP_RESIZE_WITH_MAX_POOL: False
17 changes: 17 additions & 0 deletions cfgs/res50.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
EXP_DIR: res50
TRAIN:
HAS_RPN: True
# IMS_PER_BATCH: 1
BBOX_NORMALIZE_TARGETS_PRECOMPUTED: True
RPN_POSITIVE_OVERLAP: 0.7
RPN_BATCHSIZE: 256
PROPOSAL_METHOD: gt
BG_THRESH_LO: 0.0
DISPLAY: 20
BATCH_SIZE: 256
WEIGHT_DECAY: 0.0001
DOUBLE_BIAS: False
SNAPSHOT_PREFIX: res50_faster_rcnn
TEST:
HAS_RPN: True
POOLING_MODE: crop
15 changes: 15 additions & 0 deletions cfgs/vgg16.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
EXP_DIR: vgg16
TRAIN:
HAS_RPN: True
BBOX_NORMALIZE_TARGETS_PRECOMPUTED: True
RPN_POSITIVE_OVERLAP: 0.7
RPN_BATCHSIZE: 256
PROPOSAL_METHOD: gt
BG_THRESH_LO: 0.0
BATCH_SIZE: 256
RPN_POST_NMS_TOP_N_TARGET: 256
LEARNING_RATE: 0.001
TEST:
HAS_RPN: True
POOLING_MODE: align
CROP_RESIZE_WITH_MAX_POOL: False
Loading

0 comments on commit 1f8e8ae

Please sign in to comment.