示例#1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--weights', default="YOLO_small.ckpt", type=str)
    parser.add_argument('--data_dir', default="data", type=str)
    parser.add_argument('--threshold', default=0.2, type=float)
    parser.add_argument('--iou_threshold', default=0.5, type=float)
    parser.add_argument('--gpu', default='', type=str)
    args = parser.parse_args()

    if args.gpu is not None:
        cfg.GPU = args.gpu

    if args.weights is not None:
        update_config_paths(args.data_dir, args.weights)

    os.environ['CUDA_VISIBLE_DEVICES'] = cfg.GPU

    yolo = YOLONet()
    pascal = pascal_voc('train', True)
    pascal_test = pascal_voc('test', True)

    solver = Solver(yolo, pascal, pascal_test)

    print('Start training ...')
    solver.train()
    print('Done training.')
示例#2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--weights', default="D:\\reference\\5-dataset\\YOLO_small.ckpt", type=str)  # 预训练的数据集
    parser.add_argument('--data_dir', default="D:\\reference\\5-dataset", type=str)  # voc数据集文件夹pascal_voc所在路径
    parser.add_argument('--threshold', default=0.2, type=float)  #  格子有目标的置信度阈值
    parser.add_argument('--iou_threshold', default=0.5, type=float)
    parser.add_argument('--gpu', default='0', type=str)
    args = parser.parse_args()

    if args.gpu is not None:
        cfg.GPU = args.gpu

    if args.data_dir != cfg.DATA_PATH:
        update_config_paths(args.data_dir, args.weights)

    os.environ['CUDA_VISIBLE_DEVICES'] = cfg.GPU  # 获取系统环境变量

    yolo = YOLONet()
    pascal = pascal_voc('train')

    solver = Solver(yolo, pascal)

    print('Start training ...')
    solver.train()
    print('Done training.')
def main():  #自定义参数
    parser = argparse.ArgumentParser()
    parser.add_argument('--weights', default="YOLO_small.ckpt",
                        type=str)  #定义权重文件
    parser.add_argument('--data_dir', default="data", type=str)  #定义数据文件夹
    parser.add_argument('--threshold', default=0.2, type=float)  #阈值
    parser.add_argument('--iou_threshold', default=0.5, type=float)  #IOU阈值
    parser.add_argument('--gpu', default='', type=str)  #是否用gpu训练
    args = parser.parse_args()

    if args.gpu is not None:  #是否用gpu训练
        cfg.GPU = args.gpu

    if args.data_dir != cfg.DATA_PATH:
        update_config_paths(args.data_dir, args.weights)

    os.environ['CUDA_VISIBLE_DEVICES'] = cfg.GPU

    yolo = YOLONet()  #Yolo网络
    pascal = pascal_voc('train')  #获得训练的数据, 包含了经过水平翻转后的训练实例

    solver = Solver(yolo, pascal)  #准备训练的环境,包括设置优化器,学习率等内容

    print('Start training ...')
    solver.train()  #start training
    print('done!!!')
示例#4
0
def main():
    # 创建一个解析器对象,并告诉它将会有些什么参数。当程序运行时,该解析器就可以用于处理命令行参数。
    parser = argparse.ArgumentParser()  # 定义参数
    parser.add_argument('--weights', default="YOLO_small.ckpt",
                        type=str)  # 权重文件名
    parser.add_argument('--data_dir', default="data", type=str)  # 数据集路径
    parser.add_argument('--threshold', default=0.2, type=float)
    parser.add_argument('--iou_threshold', default=0.5, type=float)
    parser.add_argument('--gpu', default='', type=str)
    # 定义了所有参数之后,你就可以给 parse_args() 传递一组参数字符串来解析命令行。默认情况下,参数是从 sys.argv[1:] 中获取
    # parse_args() 的返回值是一个命名空间,包含传递给命令的参数。该对象将参数保存其属性
    args = parser.parse_args()

    # 判断是否是使用gpu
    if args.gpu is not None:
        cfg.GPU = args.gpu

    # 设定数据集路径,以及检查点文件路径
    if args.data_dir != cfg.DATA_PATH:
        update_config_paths(args.data_dir, args.weights)

    # 设置环境变量
    os.environ['CUDA_VISIBLE_DEVICES'] = cfg.GPU

    yolo = YOLONet()  # 创建YOLO网络对象
    pascal = pascal_voc('train')  # 数据集对象

    solver = Solver(yolo, pascal)  # 求解器对象

    print('Start training ...')
    solver.train()  # 开始训练
    print('Done training.')
示例#5
0
def generate_GTbox_labels(rebuild=False, save=True):

    voc_test = pascal_voc(phase='test', rebuild=rebuild)
    result_dir = './result'
    if not os.path.exists(result_dir):
        os.mkdir(result_dir)
    labels_info = voc_test.gt_labels
    nums = len(labels_info)
    # print(nums)
    GT_box = []
    GT_labels = []
    if save:
        for i, info in enumerate(labels_info):
            # print(info['imname'])
            lab = info['label'][..., 1:]
            response = info['label'][..., 0]
            index = np.nonzero(response)
            # convert to (ymin,xmin,ymax,xmax)
            xmin = lab[..., 0] - 0.5 * lab[..., 2]
            ymin = lab[..., 1] - 0.5 * lab[..., 3]
            xmax = lab[..., 0] + 0.5 * lab[..., 2]
            ymax = lab[..., 1] + 0.5 * lab[..., 3]
            bboxes = np.stack([ymin, xmin, ymax, xmax], axis=-1)[index]
            GT_box.append(bboxes)
            # print(GT_box)
            classes = np.argmax(lab[..., 4:], axis=-1)[index]
            GT_labels.append(classes)
            #print(GT_box,GT_labels,sep='\n')
            r = '\r>>>>>>Generate:{:4d}/{}'.format(i + 1, nums)
            print(r, end='', flush=True)

        np.save(os.path.join(result_dir, 'GT_box.npy'), GT_box)
        np.save(os.path.join(result_dir, 'GT_labels.npy'), GT_labels)
    return voc_test
示例#6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--data_dir', default="data", type=str)
    parser.add_argument('--weights', default="YOLO_small.ckpt", type=str)
    parser.add_argument('--threshold', default=0.2, type=float)
    parser.add_argument('--iou_threshold', default=0.5, type=float)
    parser.add_argument('--gpu', default='', type=str)
    args = parser.parse_args()

    if args.gpu is not None:
        cfg.GPU = args.gpu
        os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" 
        os.environ['CUDA_VISIBLE_DEVICES'] = cfg.GPU

    if args.data_dir != cfg.DATA_PATH:
        update_config_paths(args.data_dir, args.weights)

    yolo = YOLONet(True)
    data = pascal_voc('train')

    solver = Solver(yolo, data)

    print('Start training ...')
    solver.train()
    print('Done training.')
示例#7
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--weights', default="YOLO_small.ckpt", type=str)
    parser.add_argument('--data_dir', default="data", type=str)
    parser.add_argument('--threshold', default=0.2, type=float)
    parser.add_argument('--iou_threshold', default=0.5, type=float)
    parser.add_argument('--gpu', default='', type=str)
    args = parser.parse_args()

    if args.gpu is not None:
        cfg.GPU = args.gpu

    if args.data_dir != cfg.DATA_PATH:
        update_config_paths(args.data_dir, args.weights)

    os.environ['CUDA_VISIBLE_DEVICES'] = cfg.GPU

    yolo = YOLONet()
    pascal = pascal_voc('train')

    solver = Solver(yolo, pascal)

    print('Start training ...')
    solver.train()
    print('Done training.')
示例#8
0
文件: train.py 项目: FenHua/yolo
def main():
    parser = argparse.ArgumentParser()  # 创建一个解析器对象,并告诉它将会有些什么参数
    # 当程序运行时,该解析器就可以用于处理命令行参数
    '''定义参数'''
    parser.add_argument('--weights', default="YOLO_small.ckpt",
                        type=str)  # 权重文件名
    parser.add_argument('--data_dir', default="data", type=str)  # 数据集目录
    parser.add_argument('--threshold', default=0.2, type=float)  # 目标存在阈值
    parser.add_argument('--iou_threshold', default=0.5, type=float)
    parser.add_argument('--gpu', default='', type=str)
    # 定义了所有参数之后,就可以给parse_args()传递一组参数字符串来解析命令行
    # 默认情况下参数从sys.argv[1:]中获取
    args = parser.parse_args()  #将命令行中的参数保存相应的属性
    if args.gpu is not None:
        cfg.GPU = args.gpu  # 判断是否使用GPU
    if args.data_dir != cfg.DATA_PATH:
        # 检查当前数据集路径,并进行更新
        update_config_paths(args.data_dir, args.weights)
    os.environ['CUDA_VISIBLE_DEVICES'] = cfg.GPU  # 设置环境变量
    yolo = YOLONet()  #创建yolo
    pascal = pascal_voc('train')  #数据集
    solver = Solver(yolo, pascal)  # 求解器
    print('Start training ...')
    solver.train()
    print('Done training.')
示例#9
0
def main():

    modelNet = cnnLstmNet()
    pascal = pascal_voc('train')
    solver = Solver(modelNet, pascal)

    print('开始训练...')
    solver.train()
    print('训练结束....')
示例#10
0
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('--weights', default="YOLO_small.ckpt", type=str)
    parser.add_argument('--gpu', default=None, type=int)
    args = parser.parse_args()

    cfg.WEIGHTS_FILE = os.path.join(cfg.WEIGHTS_DIR, args.weights)
    if args.gpu is not None:
        cfg.GPU = str(args.gpu)

    yolo = YOLONet('train')
    pascal = pascal_voc('train')
    solver = Solver(yolo, pascal)
    solver.train()
示例#11
0
def main(args):

    if args.gpu is not None:
        cfg.GPU = args.gpu

    if args.data_dir != cfg.DATA_PATH:
        update_config_paths(args.data_dir, args.weights)

    os.environ['CUDA_VISIBLE_DEVICES'] = cfg.GPU

    yolo = YOLONet()
    pascal = pascal_voc('train')

    solver = Solver(yolo, pascal)

    print('Start training ...')
    solver.train()
    print('Done training.')
示例#12
0
def main():
    tf.reset_default_graph()
    parser = argparse.ArgumentParser()
    parser.add_argument('--weights', default="YOLO_small.ckpt", type=str)
    parser.add_argument('--data_dir', default="data", type=str)
    parser.add_argument('--threshold', default=0.2, type=float)
    parser.add_argument('--iou_threshold', default=0.5, type=float)
    parser.add_argument('--gpu', default='0', type=str)
    args = parser.parse_args()

    os.environ['CUDA_VISIBLE_DEVICES'] = "0"

    yolo = Yolo()
    pascal = pascal_voc('test')

    solver = Solver(yolo, pascal)

    print('Start testing ...')
    solver.train()
    print('Done testing.')
示例#13
0
def main():
    #command line interface
    parser = argparse.ArgumentParser()
    parser.add_argument('-threshold', default=cfg.THRESHOLD, type=float)
    parser.add_argument('-iou_threshold',
                        default=cfg.IOU_THRESHOLD,
                        type=float)
    parser.add_argument('-gpu', default='0', type=str)
    args = parser.parse_args()

    if args.gpu is not None:
        cfg.GPU = args.gpu

    os.environ['CUDA_VISIBLE_DEVICES'] = cfg.GPU

    trainer = Trainer(YOLO(), pascal_voc('train'))

    print('Start training ...')
    trainer.train()
    print('Done training.')
示例#14
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--weights', default="YOLO_small.ckpt", type=str)
    parser.add_argument('--gpu', default='0', type=str)
    args = parser.parse_args()

    if args.gpu is not None:
        cfg.GPU = args.gpu

    if args.weights is not None:
        cfg.WEIGHTS = args.weights

    os.environ['CUDA_VISIBLE_DEVICES'] = cfg.GPU

    yolo = YOLONet()
    pascal = pascal_voc()

    solver = Solver(yolo, pascal)

    print('Start training ...')
    solver.train()
    print('Done training.')
示例#15
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--weights', default="YOLO_small.ckpt", type=str)
    parser.add_argument('--data_dir', default="data", type=str)
    parser.add_argument('--threshold', default=0.2, type=float)
    parser.add_argument('--iou_threshold', default=0.5, type=float)
    parser.add_argument('--gpu', default='', type=str)
    args = parser.parse_args()

    if args.gpu is not None:
        cfg.GPU = args.gpu

    if args.data_dir != cfg.DATA_PATH:
        update_config_paths(args.data_dir, args.weights)

    yolo = YOLONet()
    pascal = pascal_voc('train')
    solver = Solver(yolo, pascal)

    print('Start training ...')
    solver.train()
    print('Done training.')
示例#16
0
def main():

    if not os.path.exists(cfg.OUTPUT_dir):
        os.makedirs(cfg.OUTPUT_dir)
    if not os.path.exists(cfg.TRAIN_process_save_txt_dir):
        os.makedirs(cfg.TRAIN_process_save_txt_dir)
    if not os.path.exists(cfg.WEIGHTS_output_dir):
        os.makedirs(cfg.WEIGHTS_output_dir)


#    if args.data_dir != cfg.DATA_PATH:
#        update_config_paths(args.data_dir, args.weights)

    os.environ['CUDA_VISIBLE_DEVICES'] = cfg.GPU

    yolo = YOLONet()
    pascal = pascal_voc('train', rebuild=False)

    solver = Solver(yolo, pascal)

    print('Start training ...')
    solver.train()
    print('Done training.')
示例#17
0
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument('--weights', default=None, type=str)
    parser.add_argument('--gpu', default=None, type=int)
    args = parser.parse_args()

    if args.weights is not None:
        cfg.WEIGHTS_FILE = os.path.join(cfg.WEIGHTS_DIR, args.weights)
    if args.gpu is not None:
        cfg.GPU = str(args.gpu)

    cfg.GPU = '1'
    cfg.WEIGHTS_FILE = os.path.join(cfg.WEIGHTS_DIR, 'YOLO_small.ckpt')
    # cfg.DISPLAY_ITER = 1

    os.environ['CUDA_VISIBLE_DEVICES'] = cfg.GPU

    yolo = YOLONet('train')
    pascal = pascal_voc('train')

    solver = Solver(yolo, pascal)

    solver.train()
示例#18
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--weights', default="/home/jiahuei/Documents/Woh/pothole-detection/data/pascal_voc/output/2018_07_06_20_14/save.ckpt-6000", type=str)
    parser.add_argument('--data_dir', default="data", type=str)
    parser.add_argument('--threshold', default=0.2, type=float)
    parser.add_argument('--iou_threshold', default=0.5, type=float)
    parser.add_argument('--gpu', default='0', type=str)
    args = parser.parse_args()
    #if args.gpu is not None:
    #    cfg.GPU = args.gpu
    
    if args.data_dir != cfg.DATA_PATH:
        update_config_paths(args.data_dir, args.weights)

    os.environ['CUDA_VISIBLE_DEVICES'] = '0'

    yolo = YOLONet()
    pascal = pascal_voc('train')

    solver = Solver(yolo, pascal)

    print('Start training ...')
    solver.train()
    print('Done training.')
示例#19
0
# -*- coding: utf-8 -*-

import tensorflow as tf
import tensorflow.keras as keras
import config as cfg
from YOLOv1_beta_1 import YOLOv1Net
from utils.pascal_voc import pascal_voc

# 需要首先下载数据集

pascal = pascal_voc('train')

def get_train_data_by_batch():
    while 1:
        for i in range(0, len(pascal.gt_labels), 64):
            images, labels = pascal.get()
            yield (images, labels)


def lr_scheduler(epoch):
    lr = 1e-4
    if(epoch <= 75):
        lr = 1e-2
    elif(75 < epoch and epoch <= 105):
        lr = 1e-3
    elif(105 < epoch and epoch <= 135):
        lr = 1e-4
    return lr


                sess.run(
                    tf.assign(
                        self._variables_to_fix['vgg_16' + '/fc6/weights:0'],
                        tf.reshape(
                            fc6_conv, self._variables_to_fix[
                                'vgg_16' + '/fc6/weights:0'].get_shape())))
                sess.run(
                    tf.assign(
                        self._variables_to_fix['vgg_16' + '/fc7/weights:0'],
                        tf.reshape(
                            fc7_conv, self._variables_to_fix[
                                'vgg_16' + '/fc7/weights:0'].get_shape())))

if __name__ == '__main__':
    os.environ['CUDA_VISIBLE_DEVICES'] = cfg.GPU_ID

    backbone = 'resnet'
    net = network.Net()
    rpn_loss_obj = RPN_loss(net.rois_output['rois_bbx'], net.all_anchors, net.gt_boxes, \
                        net.rois_output['rois_cls'], net.labels, net.anchor_obj)
    predict_loss = Predict_loss(net._predictions["cls_score"], net._proposal_targets['labels'],\
                                net._predictions['bbox_pred'], net._proposal_targets['bbox_targets'],\
                                net._proposal_targets['bbox_inside_weights'], net._proposal_targets['bbox_outside_weights'])

    train_data = pascl.pascal_voc(cfg.train_imdb_name, 'train', fliped=True)
    val_data = pascl.pascal_voc(cfg.test_imdb_name, 'test', fliped=False)
    solver = Solver(net, train_data, val_data, rpn_loss_obj, predict_loss)
    print('start training')
    solver.train_model(backbone)
示例#21
0
                            if not R['dec_id'][jmax]:
                                tp[d] = 1.
                                R['dec_id'][jmax] = 1
                            else:
                                fp[d] = 1.
                    else:
                        fp[d] = 1.
            fp = np.cumsum(fp)
            tp = np.cumsum(tp)
            rec = tp / float(num_cls_obj)
            prec = tp / np.maximum(tp + fp, np.finfo(np.float64).eps)
            ap.append(self.val_data.voc_ap(rec, prec))
            print(np.mean(ap))
        return sum(ap) / (self.net.num_classes - 1.0)

    def get_var_list(self, global_variables, ckpt_variables):
        variables_to_restore = []
        for key in global_variables:
            if key.name.split(':')[0] in ckpt_variables:
                variables_to_restore.append(key)
        return variables_to_restore

if __name__ == '__main__':
    os.environ['CUDA_VISIBLE_DEVICES'] = cfg.GPU_ID
    net = network.Net(is_training=False, backbone='resnet')
    # net = network.Net(is_training=False, backbone='vgg16')
    val_data = pascl.pascal_voc(cfg.test_imdb_name, 'test', fliped=False)
    test = Val(net, val_data)
    print('start training')
    test.test_model()