Пример #1
0
        np.random.seed(cfg.RNG_SEED)
        caffe.set_random_seed(cfg.RNG_SEED)

    # set up caffe
    caffe.set_mode_gpu()
    caffe.set_device(args.gpu_id)

    output_dir = "./"
    imdb = []

    # 训练中并没有使用到imdb的信息,也不清楚那是个什么玩意,无伤大雅
    # roidb中记录了文本实例,以及对应图片路径,之类的信息
    print args.imdb_name
    if args.imdb_name == "MSRA_TRAIN":
        output_dir = "."
        roidb = get_rroidb("train")
    else:
        imdb, roidb = combined_roidb(args.imdb_name)
        print('{:d} roidb entries'.format(len(roidb)))
        #print roidb
        output_dir = get_output_dir(imdb)

    print('{:d} roidb entries'.format(len(roidb)))

    print('Output will be saved to `{:s}`'.format(output_dir))

    train_net(args.solver,
              roidb,
              output_dir,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters)
Пример #2
0
#encoding:utf-8
import numpy as np
import cv2

from rotation.data_extractor import get_rroidb
from rotation.r_roidb import add_rbbox_regression_targets
from rotation.r_minibatch import r_get_minibatch
from fast_rcnn.config import cfg, cfg_from_file, cfg_from_list, get_output_dir
from rotation.rt_train import filter_roidb

cfg_from_file('../../experiments/cfgs/faster_rcnn_end2end.yml')
for c in cfg:
    print c, ':', cfg[c]

roidb = get_rroidb()
print 'len', len(roidb)
#print roidb[0]
roidb = filter_roidb(roidb)
print 'len_after', len(roidb)
print roidb[0]
bbox_means, bbox_stds = add_rbbox_regression_targets(roidb)  #To test
#print roidb[0]
#print 'bbox_means',bbox_means
#print 'bbox_stds',bbox_stds
blobs = r_get_minibatch(roidb, 2)

im = blobs['data'].transpose(0, 2, 3, 1)[0]
gt_boxes = blobs['gt_boxes']
info = blobs['im_info']

#print 'im:',im
Пример #3
0
    # Warmup on a dummy image
    im = 128 * np.ones((300, 500, 3), dtype=np.uint8)
    for i in xrange(2):
        _, _ = r_im_detect(net, im)

#     im_names = []
#     gt_boxes = []

#     test_dir = './data/dataset/ICDAR_2015/ch4_test_images'
#     for img in os.listdir(test_dir):
#         # ignore files created by jupyter
#         if img[0] == '.':
#             continue
#         im_names.append(os.path.join(test_dir, img))
#         gt_boxes.append([0, 0, 0, 0, 0])
    roidb = get_rroidb(args.imdb_name)

    # The detection results will save in cood_dir in txt
    cood_dir = "./data/dataset/ICDAR_2015/results_txt"

    #     for im_idx in range(len(im_names)):
    for im_idx in range(min(10, len(roidb))):
        im_path = roidb[im_idx]['image']
        im_name = im_path.split('/')[-1].split('.')[0]
        gt_boxes = roidb[im_idx]['boxes']
        ori_gt_boxes = roidb[im_idx]['ori_boxes']
        print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
        print 'detect for {}'.format(im_name)
        #         vis_image(im_names[im_idx], demo(net, im_names[im_idx], gt_boxes[im_idx], cood_dir))
        vis_detections(im_path, demo(net,
                                     im_path,
Пример #4
0
    if not args.randomize:
        # fix the random seeds (numpy and caffe) for reproducibility
        np.random.seed(cfg.RNG_SEED)
        caffe.set_random_seed(cfg.RNG_SEED)

    # set up caffe
    caffe.set_mode_gpu()
    caffe.set_device(args.gpu_id)

    output_dir = "./"
    imdb = []

    print args.imdb_name
    if args.imdb_name == "MSRA_TRAIN":
	output_dir = "."
	roidb = get_rroidb("train")
    else:
        imdb, roidb = combined_roidb(args.imdb_name)
        print ('{:d} roidb entries'.format(len(roidb)))
        #print roidb
        output_dir = get_output_dir(imdb)

    print ('{:d} roidb entries'.format(len(roidb)))

    #output_dir = get_output_dir(imdb)
    print ('Output will be saved to `{:s}`'.format(output_dir))

    train_net(args.solver, roidb, output_dir,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters)
Пример #5
0
def _get_next_minibatch(self):
    """Return the blobs to be used for the next minibatch.

    If cfg.TRAIN.USE_PREFETCH is True, then blobs will be computed in a
    separate process and made available through self._blob_queue.
    """
    #随机抽取一张图片
    db_inds = self._get_next_minibatch_inds()
    minibatch_db = [self._roidb[i] for i in db_inds]
    return r_get_rotate_minibatch(minibatch_db, self._num_classes)  # D


if __name__ == '__main__':
    np.set_printoptions(suppress=True)
    cfg_from_file('experiments/cfgs/faster_rcnn_end2end.yml')
    roidb = get_rroidb('train')
    #for i in range(len(roidb)):
    #print roidb[i]
    #add_rbbox_regression_targets(roidb)
    a_roidb = roidb[1]
    print __file__, 'a_roidb[gt]', a_roidb['boxes']
    print a_roidb['gt_classes']
    src = cv2.imread(a_roidb['image'])
    img = src[:]
    #cv2.imshow('src',img)
    #vis_image(img,a_roidb['boxes'])

    #blobs = r_get_minibatch([a_roidb], 2)
    blobs = r_get_rotate_minibatch([a_roidb], 3)
    #  ['gt_boxes', 'data', 'im_info']
    print 'blobs : ', blobs.keys()
Пример #6
0
        self._cur = 0

    def _get_next_minibatch_inds(self):
        """Return the roidb indices for the next minibatch."""
        # TODO(rbg): remove duplicated code
        if self._cur + cfg.TRAIN.IMS_PER_BATCH >= len(self._roidb):
            self._shuffle_roidb_inds()

        db_inds = self._perm[self._cur:self._cur + cfg.TRAIN.IMS_PER_BATCH]
        self._cur += cfg.TRAIN.IMS_PER_BATCH
        return db_inds

    def run(self):
        print 'BlobFetcher started'
        while True:
            db_inds = self._get_next_minibatch_inds()
            minibatch_db = [self._roidb[i] for i in db_inds]
            blobs = r_get_minibatch(minibatch_db, self._num_classes)
            self._queue.put(blobs)

if __name__ == '__main__':

	roidb = get_rroidb()
	#for i in range(len(roidb)):
		#print roidb[i]
	add_rbbox_regression_targets(roidb)
	print roidb
	print r_get_minibatch(roidb, 2)
	
	
Пример #7
0
    if not args.randomize:
        # fix the random seeds (numpy and caffe) for reproducibility
        np.random.seed(cfg.RNG_SEED)
        caffe.set_random_seed(cfg.RNG_SEED)

    # set up caffe
    caffe.set_mode_gpu()
    caffe.set_device(args.gpu_id)

    output_dir = "./"
    imdb = []

    print args.imdb_name
    if args.imdb_name == "MSRA_TRAIN":
	output_dir = "."
	roidb = get_rroidb()   # "train"
    else:
        imdb, roidb = combined_roidb(args.imdb_name)
        print ('{:d} roidb entries'.format(len(roidb)))
        #print roidb
        output_dir = get_output_dir(imdb)

    print ('{:d} roidb entries'.format(len(roidb)))

    #output_dir = get_output_dir(imdb)
    print ('Output will be saved to `{:s}`'.format(output_dir))

    train_net(args.solver, roidb, output_dir,
              pretrained_model=args.pretrained_model,
              max_iters=args.max_iters)