Commit a8a0f55d authored by Ross Girshick's avatar Ross Girshick

reorg code

parent caa4a46f
# --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------
from .imdb import imdb
from .pascal_voc import pascal_voc
from . import factory
import os.path as osp
ROOT_DIR = osp.join(osp.dirname(__file__), '..', '..')
# We assume your matlab binary is in your path and called `matlab'.
# If either is not true, just add it to your path and alias it as matlab, or
# you could change this file.
MATLAB = 'matlab'
# http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
def _which(program):
import os
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
if _which(MATLAB) is None:
msg = ("MATLAB command '{}' not found. "
"Please add '{}' to your PATH.").format(MATLAB, MATLAB)
raise EnvironmentError(msg)
......@@ -10,7 +10,7 @@ import PIL
import utils.cython_bbox
import numpy as np
import scipy.sparse
from fast_rcnn_config import cfg
import datasets
class imdb(object):
def __init__(self, name):
......@@ -62,7 +62,7 @@ class imdb(object):
@property
def cache_path(self):
return os.path.join(cfg.ROOT_DIR, 'data', 'cache')
return os.path.join(datasets.ROOT_DIR, 'data', 'cache')
@property
def num_images(self):
......
......@@ -5,6 +5,7 @@
# Written by Ross Girshick
# --------------------------------------------------------
import datasets
import datasets.pascal_voc
import os
import datasets.imdb
......@@ -15,7 +16,6 @@ import scipy.io as sio
import utils.cython_bbox
import cPickle
import subprocess
from fast_rcnn_config import cfg
class pascal_voc(datasets.imdb):
def __init__(self, image_set, year, devkit_path=None):
......@@ -81,7 +81,7 @@ class pascal_voc(datasets.imdb):
"""
Return the default path where PASCAL VOC is expected to be installed.
"""
return os.path.join(cfg.ROOT_DIR, 'data', 'VOCdevkit' + self._year)
return os.path.join(datasets.ROOT_DIR, 'data', 'VOCdevkit' + self._year)
def gt_roidb(self):
"""
......@@ -261,7 +261,7 @@ class pascal_voc(datasets.imdb):
path = os.path.join(os.path.dirname(__file__),
'VOCdevkit-matlab-wrapper')
cmd = 'cd {} && '.format(path)
cmd += '{:s} -nodisplay -nodesktop '.format(cfg.MATLAB)
cmd += '{:s} -nodisplay -nodesktop '.format(datasets.MATLAB)
cmd += '-r "dbstop if error; '
cmd += 'voc_eval(\'{:s}\',\'{:s}\',\'{:s}\',\'{:s}\',{:d}); quit;"' \
.format(self._devkit_path, comp_id,
......
......@@ -5,5 +5,6 @@
# Written by Ross Girshick
# --------------------------------------------------------
from .imdb import imdb
from .pascal_voc import pascal_voc
from . import config
from . import train
from . import test
......@@ -6,7 +6,7 @@
# --------------------------------------------------------
import numpy as np
from fast_rcnn_config import cfg
from fast_rcnn.config import cfg
import utils.cython_bbox
def _compute_targets(rois, overlaps, labels):
......
......@@ -18,16 +18,10 @@
import os
import os.path as osp
import sys
import numpy as np
# `pip install easydict` if you don't have it
from easydict import EasyDict as edict
# Add caffe to PYTHONPATH
caffe_path = osp.abspath(osp.join(osp.dirname(__file__), '..',
'caffe-fast-rcnn', 'python'))
sys.path.insert(0, caffe_path)
__C = edict()
# Consumers can get config by:
# from fast_rcnn_config import cfg
......@@ -126,15 +120,11 @@ __C.RNG_SEED = 3
__C.EPS = 1e-14
# Root directory of project
__C.ROOT_DIR = osp.abspath(osp.join(osp.dirname(__file__), '..'))
__C.ROOT_DIR = osp.join(osp.dirname(__file__), '..', '..')
# Place outputs under an experiments directory
__C.EXP_DIR = 'default'
# The shell command to start matlab
# If `matlab` is in your path, then this default should work
__C.MATLAB = 'matlab'
def get_output_path(imdb, net):
path = os.path.join(__C.ROOT_DIR, 'output', __C.EXP_DIR, imdb.name)
if net is None:
......
......@@ -8,7 +8,7 @@
import numpy as np
import cv2
import matplotlib.pyplot as plt
from fast_rcnn_config import cfg
from fast_rcnn.config import cfg
import utils.blob
def get_minibatch(roidb):
......
......@@ -5,7 +5,7 @@
# Written by Ross Girshick
# --------------------------------------------------------
from fast_rcnn_config import cfg, get_output_path
from fast_rcnn.config import cfg, get_output_path
import argparse
from utils.timer import Timer
import numpy as np
......
......@@ -5,7 +5,7 @@
# Written by Ross Girshick
# --------------------------------------------------------
from fast_rcnn_config import cfg, get_output_path
from fast_rcnn.config import cfg, get_output_path
import numpy as np
import cv2
import caffe
......
# --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick
# --------------------------------------------------------
import os.path as osp
import sys
this_dir = osp.dirname(__file__)
# Add caffe to PYTHONPATH
caffe_path = osp.join(this_dir, '..', 'caffe-fast-rcnn', 'python')
if caffe_path not in sys.path:
sys.path.insert(0, caffe_path)
lib_path = osp.join(this_dir, '..', 'lib')
if lib_path not in sys.path:
sys.path.insert(0, lib_path)
......@@ -7,21 +7,17 @@
# Written by Ross Girshick
# --------------------------------------------------------
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),
'..', 'src')))
import fast_rcnn_config
import _init_paths
import caffe
import argparse
import numpy as np
import os, sys
def parse_args():
"""
Parse input arguments
"""
parser = argparse.ArgumentParser(description='Compress a fast R-CNN net')
parser = argparse.ArgumentParser(description='Compress a Fast R-CNN network')
parser.add_argument('--def', dest='prototxt',
help='prototxt file defining the uncompressed network',
default=None, type=str)
......
#!/usr/bin/env python
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),
'..', 'src')))
import _init_paths
import fast_rcnn as frc
from fast_rcnn.config import cfg
from datasets.factory import get_imdb
import cPickle
import fast_rcnn_test
from fast_rcnn_config import cfg
import os, sys
def main(imdb_name, output_dir):
imdb = get_imdb(imdb_name)
......@@ -18,7 +15,7 @@ def main(imdb_name, output_dir):
dets = cPickle.load(f)
print 'Applying NMS to all detections'
nms_dets = fast_rcnn_test.apply_nms(dets, cfg.TEST.NMS)
nms_dets = frc.test.apply_nms(dets, cfg.TEST.NMS)
print 'Evaluating detections'
imdb.evaluate_detections(nms_dets, output_dir)
......
......@@ -7,24 +7,20 @@
# Written by Ross Girshick
# --------------------------------------------------------
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),
'..', 'src')))
from fast_rcnn_config import cfg, cfg_from_file
import fast_rcnn_test
import _init_paths
import fast_rcnn as frc
from fast_rcnn.config import cfg, cfg_from_file
from datasets.factory import get_imdb
import caffe
import argparse
import pprint
import time
import time, os, sys
def parse_args():
"""
Parse input arguments
"""
parser = argparse.ArgumentParser(description='Test a fast R-CNN')
parser = argparse.ArgumentParser(description='Test a Fast R-CNN network')
parser.add_argument('--gpu', dest='gpu_id', help='GPU id to use',
default=0, type=int)
parser.add_argument('--def', dest='prototxt',
......@@ -61,7 +57,7 @@ if __name__ == '__main__':
if args.cfg_file is not None:
cfg_from_file(args.cfg_file)
print('Using fast_rcnn_config:')
print('Using config:')
pprint.pprint(cfg)
while not os.path.exists(args.caffemodel) and args.wait:
......@@ -80,4 +76,4 @@ if __name__ == '__main__':
if 'cleanup' in imdb.config:
imdb.config['cleanup'] = False
fast_rcnn_test.test_net(net, imdb)
frc.test.test_net(net, imdb)
......@@ -7,24 +7,21 @@
# Written by Ross Girshick
# --------------------------------------------------------
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),
'..', 'src')))
from fast_rcnn_config import cfg, cfg_from_file
import fast_rcnn_train
import _init_paths
import fast_rcnn as frc
from fast_rcnn.config import cfg, cfg_from_file
from datasets.factory import get_imdb
import caffe
import argparse
import pprint
import numpy as np
import sys
def parse_args():
"""
Parse input arguments
"""
parser = argparse.ArgumentParser(description='Train a fast R-CNN')
parser = argparse.ArgumentParser(description='Train a Fast R-CNN network')
parser.add_argument('--gpu', dest='gpu_id', help='GPU device id to use [0]',
default=0, type=int)
parser.add_argument('--solver', dest='solver', help='solver prototxt',
......@@ -57,7 +54,7 @@ if __name__ == '__main__':
if args.cfg_file is not None:
cfg_from_file(args.cfg_file)
print('Using fast_rcnn_config:')
print('Using config:')
pprint.pprint(cfg)
# fix the random seed for reproducibility
......@@ -71,6 +68,6 @@ if __name__ == '__main__':
imdb_train = get_imdb(args.imdb_name)
print 'Loaded dataset `{:s}` for training'.format(imdb_train.name)
fast_rcnn_train.train_net(args.solver, imdb_train,
pretrained_model=args.pretrained_model,
max_iters=args.max_iters)
frc.train.train_net(args.solver, imdb_train,
pretrained_model=args.pretrained_model,
max_iters=args.max_iters)
......@@ -7,15 +7,10 @@
# Written by Ross Girshick
# --------------------------------------------------------
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),
'..', '..', 'src')))
from fast_rcnn_config import cfg, cfg_from_file
from fast_rcnn_test import im_detect
import fast_rcnn_train
import _init_paths
from fast_rcnn.config import cfg, cfg_from_file
from datasets.factory import get_imdb
from fast_rcnn.test import im_detect
from utils.timer import Timer
import caffe
import argparse
......@@ -23,6 +18,7 @@ import pprint
import numpy as np
import cv2
from sklearn import svm
import os, sys
class SVMTrainer(object):
def __init__(self, net, imdb):
......@@ -280,7 +276,7 @@ if __name__ == '__main__':
if args.cfg_file is not None:
cfg_from_file(args.cfg_file)
print('Using fast_rcnn_config:')
print('Using config:')
pprint.pprint(cfg)
# fix the random seed for reproducibility
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment