def combined_roidb(imdb_names): """ Combine multiple roidbs """ def get_roidb(imdb_name): # 构造了两个类:数据集类pascal_voc和图片类imdb imdb = get_imdb(imdb_name) print('Loaded dataset `{:s}` for training'.format(imdb.name)) # 即选择真实物体groundtruth imdb.set_proposal_method("gt") print('Set proposal method: {:s}'.format("gt")) # 获得训练数据 roidb = get_training_roidb(imdb) return roidb roidbs = [get_roidb(s) for s in imdb_names.split('+')] roidb = roidbs[0] if len(roidbs) > 1: for r in roidbs[1:]: roidb.extend(r) tmp = get_imdb(imdb_names.split('+')[1]) imdb = imdb2(imdb_names, tmp.classes) else: imdb = get_imdb(imdb_names) return imdb, roidb
def combined_roidb(imdb_names): """ Combine multiple roidbs """ #print('get_roidb') def get_roidb(imdb_name): imdb = get_imdb(imdb_name) print('Loaded Dataset `{:s}` for training'.format(imdb.name)) imdb.set_proposal_method("gt") print('Set proposal method: {:s}'.format("gt")) roidb = get_training_roidb(imdb) return roidb roidbs = [get_roidb(s) for s in imdb_names.split('+')] roidb = roidbs[0] #print('roidbs',roidbs) if len(roidbs) > 1: for r in roidbs[1:]: roidb.extend(r) tmp = get_imdb(imdb_names.split('+')[1]) imdb = imdb2(imdb_names, tmp.classes) else: imdb = get_imdb(imdb_names) return imdb, roidb
def combined_roidb(imdb_names): """Combine multiple roidbs""" # 融合roidb,roidb来自于数据集(实验可能用到多个),所以需要combine多个数据集的roidb def get_roidb(imdb_name): imdb = get_imdb(imdb_name) print('imdb*******/n', imdb) print('Loaded dataset `{:s}` for training'.format(imdb_name)) imdb.set_proposal_method("gt") # 设置proposal方法 print('Set proposal method: gt') roidb = get_training_roidb(imdb) # 得到用于训练的roidb,定义在train.py,进行了水平翻转,以及为原始roidb添加了一些说明性的属性 return roidb roidbs = [get_roidb(s) for s in imdb_names.split('+')] roidb = roidbs[0] if len(roidbs) > 1: # 如果大于一个,则进行combine roidb for r in roidbs[1:]: roidb.extend(r) tmp = get_imdb(imdb_names.split('+')[1]) imdb = imdb2(imdb_names, tmp.classes) else: imdb = get_imdb(imdb_names) # get_imdb方法定义在factory.py中,通过名字得到imdb return imdb, roidb
def combined_roidb(imdb_names): """ Combine multiple roidbs """ def get_roidb(imdb_name): #实例化一个pascal_voc类对象 imdb = get_imdb(imdb_name) print('Loaded dataset `{:s}` for training'.format(imdb.name)) #为imbd.roidb_handler赋值为self.gt_roidb imdb.set_proposal_method("gt") print('Set proposal method: {:s}'.format("gt")) roidb = get_training_roidb(imdb) return roidb roidbs = [get_roidb(s) for s in imdb_names.split('+')] roidb = roidbs[0] if len(roidbs) > 1: for r in roidbs[1:]: roidb.extend(r) tmp = get_imdb(imdb_names.split('+')[1]) imdb = imdb2(imdb_names, tmp.classes) else: #实例化一个pascal_voc类对象 imdb = get_imdb(imdb_names) return imdb, roidb
def combined_roidb(imdb_names): """ Combine multiple roidbs """ if imdb_names.split('+').__len__() > 1: tmp = get_imdb(imdb_names.split('+')[1]) imdb = imdb2(imdb_names, tmp.classes) else: imdb = get_imdb(imdb_names) return imdb
def combined_roidb(imdb_names): """ Combine multiple roidbs """ roidbs = [get_roidb(s) for s in imdb_names.split('+')] roidb = roidbs[0] if len(roidbs) > 1: for r in roidbs[1:]: roidb.extend(r) tmp = get_imdb(imdb_names.split('+')[1]) imdb = imdb2(imdb_names, tmp.classes) else: imdb = get_imdb(imdb_names) return imdb, roidb
def combined_roidb(imdb_names, training=True, root_path=None): """ Combine multiple roidbs """ def get_training_roidb(imdb): """Returns a roidb (Region of Interest database) for use in training.""" if cfg.TRAIN.USE_FLIPPED: print('Appending horizontally-flipped training examples...') imdb.append_flipped_images() if cfg.TRAIN.USE_VER_FLIPPED: print('Appending vertically-flipped training examples...') imdb.append_vertical_flipped_images() print('Preparing training data...') prepare_roidb(imdb) # ratio_index = rank_roidb_ratio(imdb) return imdb.roidb def get_roidb(imdb_name, root_path=None): imdb = get_imdb(imdb_name, root_path) print('Loaded dataset `{:s}` for training'.format(imdb.name)) imdb.set_proposal_method(cfg.TRAIN.PROPOSAL_METHOD) print('Set proposal method: {:s}'.format(cfg.TRAIN.PROPOSAL_METHOD)) roidb = get_training_roidb(imdb) return roidb roidbs = [get_roidb(s, root_path=root_path) for s in imdb_names.split('+')] roidb = roidbs[0] if len(roidbs) > 1: for r in roidbs[1:]: roidb.extend(r) tmp = get_imdb(imdb_names.split('+')[1], root_path) imdb = datasets.imdb.imdb(imdb_names, tmp.classes) else: imdb = get_imdb(imdb_names, root_path) if training: roidb = filter_roidb(roidb) return imdb, roidb else: ratio_list, ratio_index = rank_roidb_ratio(roidb) return imdb, roidb, ratio_list, ratio_index
def get_roidb(imdb_name): imdb = get_imdb(imdb_name) print('Loaded dataset `{:s}` for training'.format(imdb.name)) imdb.set_proposal_method(cfg.TRAIN.PROPOSAL_METHOD) print('Set proposal method: {:s}'.format(cfg.TRAIN.PROPOSAL_METHOD)) roidb = get_training_roidb(imdb) return roidb
def load_db(db_name): """ TOR-related database """ roidb = get_roidb(db_name) imdb = get_imdb(db_name) return imdb, roidb
def train_main(data_dir, model_dir, train_steps, input_yaml): cfg_from_file(input_yaml) print('Using config:') pprint.pprint(cfg) imdb = get_imdb('voc_2007_trainval') print('Loaded dataset `{:s}` for training'.format(imdb.name)) roidb = get_training_roidb(imdb) output_dir = get_output_dir(imdb, None) log_dir = get_log_dir(imdb) print('Output will be saved to `{:s}`'.format(output_dir)) print('Logs will be saved to `{:s}`'.format(log_dir)) device_name = '/gpu:0' print(device_name) network = get_network('VGGnet_train') train_net(network, imdb, roidb, output_dir=output_dir, log_dir=log_dir, pretrained_model='data/pretrain_model/VGG_imagenet.npy', max_iters=int(cfg.TRAIN.max_steps), restore=bool(int(cfg.TRAIN.restore)))
def get_roidb(imdb_name): imdb = get_imdb(imdb_name) print('Loaded dataset `{:s}` for training'.format(imdb.name)) imdb.set_proposal_method("gt") print('Set proposal method: {:s}'.format("gt")) roidb = get_training_roidb(imdb) return roidb
def get_roidb(imdb_name): #imdb_name=voc_2007_trainval imdb = get_imdb(imdb_name)#imdb = pascal_voc(trainval, 2007) pascal_voc是imdb的子类 print('Loaded dataset `{:s}` for training'.format(imdb.name))#imdb.name= voc_2007_trainval imdb.set_proposal_method(cfg.TRAIN.PROPOSAL_METHOD) #TRAIN.PROPOSAL_METHOD='gt' print('Set proposal method: {:s}'.format(cfg.TRAIN.PROPOSAL_METHOD))#'gt' roidb = get_training_roidb(imdb) return roidb
def get_roidb(imdb_name): # 调用factory文件中的get_imdb()方法 imdb = get_imdb(imdb_name) # imdb为调用get_imdb返回的pascal voc类对象 print('Loaded dataset {:s}'.format(imdb.name)) imdb.set_proposal_method(cfg.TRAIN.PROPOSAL_METHOD) # gt print('Set proposal method: {:s}'.format(cfg.TRAIN.PROPOSAL_METHOD)) roidb = get_training_roidb(imdb) return roidb
def get_roidb(imdb_name): # 初始化了imdb,已经获取了一些基础配置 imdb = get_imdb(imdb_name) print('Loaded dataset `{:s}` for training'.format(imdb.name)) imdb.set_proposal_method("gt") print('Set proposal method: {:s}'.format("gt")) # 为imdb.roidb添加了一些配置,宽高,最大类别等 roidb = get_training_roidb(imdb) return roidb
def get_roidb(imdb_name): #本函数根据数据库名字 获取roidb imdb = get_imdb(imdb_name) #调用factory 的 imdb 然后根据 数据库 名字 调用 pascal_voc print('Loaded dataset `{:s}` for training'.format(imdb.name)) imdb.set_proposal_method(cfg.TRAIN.PROPOSAL_METHOD) #设置gt 的方法 print('Set proposal method: {:s}'.format(cfg.TRAIN.PROPOSAL_METHOD)) roidb = get_training_roidb(imdb) return imdb, roidb
def get_roidb(imdb_name): # 获取voc 原始数据集 imdb = get_imdb(imdb_name) print('Loaded dataset `{:s}` for training'.format(imdb.name)) imdb.set_proposal_method(cfg.TRAIN.PROPOSAL_METHOD) # print('Set proposal method: {:s}'.format(cfg.TRAIN.PROPOSAL_METHOD)) # 制作并获取目标区域的位置信息 roidb = get_training_roidb(imdb) return roidb
def GetRoidb(imdb_name): """ Note: we need to run get_training_roidb sort of funcs later for now, it only supports single roidb. """ imdb = get_imdb(imdb_name) roidb = imdb.roidb return imdb, roidb
def get_roidb(imdb_name): #实例化一个pascal_voc类对象 imdb = get_imdb(imdb_name) print('Loaded dataset `{:s}` for training'.format(imdb.name)) #为imbd.roidb_handler赋值为self.gt_roidb imdb.set_proposal_method("gt") print('Set proposal method: {:s}'.format("gt")) roidb = get_training_roidb(imdb) return roidb
def get_roidb(imdb_name): # 构造了两个类:数据集类pascal_voc和图片类imdb imdb = get_imdb(imdb_name) print('Loaded dataset `{:s}` for training'.format(imdb.name)) # 即选择真实物体groundtruth imdb.set_proposal_method("gt") print('Set proposal method: {:s}'.format("gt")) # 获得训练数据 roidb = get_training_roidb(imdb) return roidb
def combined_roidb(imdb_names, training=True): def get_training_roidb(imdb): if cfg.TRAIN.USE_FLIPPED: # USE_FLIPPED = True print('Appending horizontally-flipped training examples...') imdb.append_flipped_images() # 水平翻转gt_boxes print('done') print('Prapareing training data...') prepare_roidb(imdb) # roidb.prepare_roidb() # prepare_roidb对每张图片的roidb进行信息扩充,添加id,路径,宽高,box类别信息等 #ratio_index = rank_roidb_ratio(imdb) print('done') return imdb.roidb def get_roidb(imdb_name): # 调用factory文件中的get_imdb()方法 imdb = get_imdb(imdb_name) # imdb为调用get_imdb返回的pascal voc类对象 print('Loaded dataset {:s}'.format(imdb.name)) imdb.set_proposal_method(cfg.TRAIN.PROPOSAL_METHOD) # gt print('Set proposal method: {:s}'.format(cfg.TRAIN.PROPOSAL_METHOD)) roidb = get_training_roidb(imdb) return roidb # s = 'voc_2007_trainval' 调用get_roidb() roidbs = [get_roidb(s) for s in imdb_names.split('+')] roidb = roidbs[0] if len(roidbs) > 1: for r in roidbs[1:]: roidb.extend(r) tmp = get_imdb(imdb_names.split('+')[1]) imdb = datasets.imdb.imdb(imdb_names, tmp.classes) else: # 由于前面定义的imdb对象在get_roidb函数中,若返回该对象需再次定义 imdb = get_imdb(imdb_names) if training: roidb = filter_roidb(roidb) # 过滤不含box的roidb ratio_list, ratio_index = rank_roidb_ratio(roidb) # 返回从小到大排序的ratio_list以及对应的原图roidb像索引 return imdb, roidb, ratio_list, ratio_index
def combined_roidb(imdb_names): def get_roidb(imdb_name): # 初始化了imdb,已经获取了一些基础配置 imdb = get_imdb(imdb_name) print('Loaded dataset `{:s}` for training'.format(imdb.name)) imdb.set_proposal_method("gt") print('Set proposal method: {:s}'.format("gt")) # 为imdb.roidb添加了一些配置,宽高,最大类别等 roidb = get_training_roidb(imdb) return roidb roidbs = [get_roidb(s) for s in imdb_names.split('+')] roidb = roidbs[0] if len(roidbs) > 1: for r in roidbs[1:]: roidb.extend(r) tmp = get_imdb(imdb_names.split('+')[1]) imdb = imdb2(imdb_names, tmp.classes) else: imdb = get_imdb(imdb_names) return imdb, roidb
def get_roidb(imdb_name): imdb = get_imdb(imdb_name) print('imdb*******/n', imdb) print('Loaded dataset `{:s}` for training'.format(imdb_name)) imdb.set_proposal_method("gt") # 设置proposal方法 print('Set proposal method: gt') roidb = get_training_roidb(imdb) # 得到用于训练的roidb,定义在train.py,进行了水平翻转,以及为原始roidb添加了一些说明性的属性 return roidb
def combined_roidb(imdb_names): """ Combine multiple roidbs """ def get_roidb(imdb_name): imdb = get_imdb(imdb_name) print('Loaded dataset `{:s}` for training'.format(imdb.name)) imdb.set_proposal_method(cfg.TRAIN.PROPOSAL_METHOD) print('Set proposal method: {:s}'.format(cfg.TRAIN.PROPOSAL_METHOD)) roidb = get_training_roidb(imdb) return roidb roidbs = [get_roidb(s) for s in imdb_names.split('+')] roidb = roidbs[0] if len(roidbs) > 1: for r in roidbs[1:]: roidb.extend(r) tmp = get_imdb(imdb_names.split('+')[1]) imdb = lib.datasets.imdb.imdb(imdb_names, tmp.classes) else: imdb = get_imdb(imdb_names) return imdb, roidb
def get_roidb_limit_ram(imdb_name): """ Note: we need to run get_training_roidb sort of funcs later for now, it only supports single roidb. """ imdb = get_imdb(imdb_name) roidb = imdb.roidb assert isinstance(roidb, six.string_types), \ "for limit ram vision, roidb should be a path." return imdb, roidb
def load_db(db_name): """ TOR-related database """ def get_roidb(imdb_name): imdb = get_imdb(imdb_name) print('Loaded dataset `{:s}` for training'.format(imdb.name)) imdb.set_proposal_method("gt") print('Set proposal method: {:s}'.format("gt")) roidb = get_training_roidb(imdb) return roidb roidb = get_roidb(db_name) imdb = get_imdb(db_name) return imdb, roidb
def from_dets(imdb_name, output_dir, args): imdb = get_imdb(imdb_name) imdb.competition_mode(args.comp_mode) imdb.config['matlab_eval'] = args.matlab_eval with open(os.path.join(output_dir, 'detections.pkl'), 'rb') as f: dets = pickle.load(f) if args.apply_nms: print('Applying NMS to all detections') nms_dets = apply_nms(dets, cfg.TEST.NMS) else: nms_dets = dets print('Evaluating detections') imdb.evaluate_detections(nms_dets, output_dir)
def __init__(self, imdb_name, resize=True): imdb = get_imdb(imdb_name) # Ignore the background class!!! So ['gt_classes'] must minus 1. self.classes = [ np.zeros(imdb.num_classes - 1) for i in range(imdb.num_images) ] for i, anno in enumerate(imdb.gt_roidb()): np.put(self.classes[i], map(lambda x: x - 1, anno['gt_classes']), 1) # np.put(self.classes[i], random.choice(map(lambda x: x-1, anno['gt_classes'])), 1) self.images = [imdb.image_path_at(i) for i in range(imdb.num_images)] assert len(self.classes) == len(self.images) self._perm = np.random.permutation(np.arange(len(self.images))) self._cur = 0 self.resize = resize
def combined_roidb(imdb_names): def get_roidb(imdb_name): imdb = get_imdb(imdb_name) print 'Loaded dataset `{:s}` for training'.format(imdb.name) imdb.set_proposal_method(cfg.TRAIN.PROPOSAL_METHOD) print 'Set proposal method: {:s}'.format(cfg.TRAIN.PROPOSAL_METHOD) roidb = get_training_roidb(imdb) return roidb roidbs = [get_roidb(s) for s in imdb_names.split('+')] roidb = roidbs[0] if len(roidbs) > 1: for r in roidbs[1:]: roidb.extend(r) imdb = datasets.imdb.imdb(imdb_names) else: imdb = get_imdb(imdb_names) return imdb, roidb
print('Using config:') pprint.pprint(cfg) # if has model, get the name from it # if does not, then just use the initialization weights if args.model: filename = os.path.splitext(os.path.basename(args.model))[0] else: filename = os.path.splitext(os.path.basename(args.weight))[0] tag = args.tag tag = tag if tag else 'default' filename = tag + '/' + filename imdb = get_imdb(args.imdb_name) imdb.competition_mode(args.comp_mode) tfconfig = tf.ConfigProto(allow_soft_placement=True) tfconfig.gpu_options.allow_growth = True # init session sess = tf.Session(config=tfconfig) # load network if args.backbone == 'vgg16': net = vgg16_ssh() elif args.backbone == 'res50': net = resnetv1_ssh(num_layers=50) elif args.backbone == 'res101': net = resnetv1_ssh(num_layers=101) elif args.backbone == 'res152':
if last_snapshot_iter != self.solver.iter: self.snapshot() def get_training_roidb(imdb): """Returns a roidb (Region of Interest database) for use in training.""" if cfg.TRAIN.USE_FLIPPED: print 'Appending horizontally-flipped training examples...' imdb.append_flipped_images() print 'done' print 'Preparing training data...' rdl_roidb.prepare_roidb(imdb) print 'done' return imdb.roidb def train_net(solver_prototxt, roidb, output_dir, pretrained_model=None, max_iters=40000): """Train a Fast R-CNN network.""" sw = SolverWrapper(solver_prototxt, roidb, output_dir, pretrained_model=pretrained_model) print 'Solving...' sw.train_model(max_iters) print 'done solving' if __name__ == '__main__': from lib.datasets.factory import get_imdb a = train_net('models/VGG_CNN_M_1024/solver.prototxt', get_training_roidb(get_imdb('soton_ear')), output_dir=None) pass
import os.path sys.path.append(os.getcwd()) this_dir = os.path.dirname(__file__) from lib.fast_rcnn.train import get_training_roidb, train_net from lib.fast_rcnn.config import cfg_from_file, get_output_dir, get_log_dir from lib.datasets.factory import get_imdb from lib.networks.factory import get_network from lib.fast_rcnn.config import cfg if __name__ == '__main__': cfg_from_file('ctpn/text.yml') print('Using config:') pprint.pprint(cfg) imdb = get_imdb('voc_2007_trainval') print('Loaded dataset `{:s}` for training'.format(imdb.name)) roidb = get_training_roidb(imdb) output_dir = get_output_dir(imdb, None) log_dir = get_log_dir(imdb) print('Output will be saved to `{:s}`'.format(output_dir)) print('Logs will be saved to `{:s}`'.format(log_dir)) device_name = '/gpu:0' print(device_name) network = get_network('VGGnet_train') train_net(network, imdb,
print('Called with args:') print(args) if args.cfg_file is not None: cfg_from_file(args.cfg_file) if args.set_cfgs is not None: cfg_from_list(args.set_cfgs) print('Using config:') pprint.pprint(cfg) if not args.randomize: # fix the random seeds (numpy and caffe) for reproducibility np.random.seed(cfg.RNG_SEED) imdb = get_imdb(args.imdb_name) print 'Loaded dataset `{:s}` for training'.format(imdb.name) roidb = get_training_roidb(imdb) output_dir = get_output_dir(imdb, None) log_dir = get_log_dir(imdb) print 'Output will be saved to `{:s}`'.format(output_dir) print 'Logs will be saved to `{:s}`'.format(log_dir) device_name = '/gpu:{:d}'.format(args.gpu_id) print device_name network = get_network(args.network_name) print 'Use network `{:s}` in training'.format(args.network_name) train_net(network, imdb, roidb,
import os.path sys.path.append(os.getcwd()) this_dir = os.path.dirname(__file__) from lib.fast_rcnn.train import get_training_roidb, train_net from lib.fast_rcnn.config import cfg_from_file, get_output_dir, get_log_dir from lib.datasets.factory import get_imdb from lib.networks.factory import get_network from lib.fast_rcnn.config import cfg if __name__ == '__main__': cfg_from_file('ctpn/text.yml') print('Using config:') pprint.pprint(cfg) imdb = get_imdb('voc_2007_trainval') print('Loaded dataset `{:s}` for training'.format(imdb.name)) roidb = get_training_roidb(imdb) output_dir = get_output_dir(imdb, None) log_dir = get_log_dir(imdb) print('Output will be saved to `{:s}`'.format(output_dir)) print('Logs will be saved to `{:s}`'.format(log_dir)) device_name = '/gpu:0' print(device_name) network = get_network('VGGnet_train') train_net(network, imdb, roidb, output_dir=output_dir,