예제 #1
0
파일: train.py 프로젝트: YacobBY/bdcn
def main():
    args = parse_args()
    logger = log.get_logger(args.log)
    args.logger = logger
    logger.info('*' * 80)
    logger.info('the args are the below')
    logger.info('*' * 80)

    for x in args.__dict__:
        logger.info(x + ',' + str(args.__dict__[x]))

    logger.info(cfg.config[args.dataset])
    logger.info('*' * 80)
    os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu

    if not os.path.exists(args.param_dir):
        os.mkdir(args.param_dir)

    torch.manual_seed(long(time.time()))

    model = bdcn.BDCN(pretrain=args.pretrain, logger=logger)

    if args.complete_pretrain:
        model.load_state_dict(torch.load(args.complete_pretrain))

    logger.info(model)
    train(model, args)
예제 #2
0
def main():
    args = parse_args()

    # Choose the GPUs
    os.environ["CUDA_DEVICE_ORDER"] = 'PCI_BUS_ID'
    os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu

    logger = log.get_logger(args.log)
    args.logger = logger
    logger.info('*' * 80)
    logger.info('the args are the below')
    logger.info('*' * 80)

    for x in args.__dict__:
        logger.info(x + ',' + str(args.__dict__[x]))
    logger.info('*' * 80)

    if not os.path.exists(args.param_dir):
        os.mkdir(args.param_dir)

    torch.manual_seed(int(time.time()))
    model = bdcn.BDCN(pretrain=args.pretrain, logger=logger)

    if args.complete_pretrain:
        model.load_state_dict(torch.load(args.complete_pretrain))

    train(model, args)
예제 #3
0
def main():
    import time
    print(time.localtime())
    args = parse_args()
    os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu
    model = bdcn.BDCN()
    model.load_state_dict(torch.load('%s' % (args.model)))
    test(model, args)
예제 #4
0
def main():
    import time
    print time.localtime()
    args = parse_args()
    os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu
    model = bdcn.BDCN(rate=args.rate)
    model.load_state_dict(torch.load('%s' % (args.model)))
    # print model.fuse.weight.data, model.fuse.bias.data
    print model.fuse.weight.data
    test(model, args)
예제 #5
0
파일: test_ms.py 프로젝트: xavysp/BDCN_xsp
def main():
    import time
    print (time.localtime())
    args = parse_args()
    os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu
    device = torch.device('cpu' if torch.cuda.device_count() == 0 else 'cuda')

    model = bdcn.BDCN().to(device)
    model.load_state_dict(torch.load('%s' % (args.model), map_location=device))
    test(model, args, running_on=device)
예제 #6
0
def main():
    import time
    print(time.localtime())
    args = parse_args()
    os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu
    model = bdcn.BDCN()
    model.load_state_dict(
        torch.load('%s' % (params_dir[args.train_dataset]),
                   map_location=torch.device('cpu')))
    test(model, args)
예제 #7
0
def setup(opts):
    model = bdcn.BDCN()
    if torch.cuda.is_available():
        model.load_state_dict(torch.load(opts["checkpoint"]))
        model.cuda()
    else:
        model.load_state_dict(
            torch.load(opts["checkpoint"], map_location='cpu'))
    model.eval()

    return model
예제 #8
0
파일: test.py 프로젝트: xavysp/BDCN_xsp
def main():
    import time
    print(time.localtime())
    args = parse_args()

    os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu
    device = torch.device('cpu' if torch.cuda.device_count() == 0 else 'cuda')
    # model = bdcn.BDCN()
    model = bdcn.BDCN().to(device)
    model_dir = os.path.join('params', args.train_data, args.model)
    model.load_state_dict(torch.load('%s' % (model_dir), map_location=device))
    print("====== Checkpoint> ", model_dir, "==========")
    test(model, args, running_on=device)
예제 #9
0
파일: main.py 프로젝트: YacobBY/bdcn
def main():

    inputDir = ['images']
    args = parse_args()
    os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu
    logging.info('Loading model...')
    model = bdcn.BDCN()
    logging.info('Loading state...')
    model.load_state_dict(torch.load('%s' % (args.model)))
    logging.info('Start image processing...')

    for inputDir in inputDir:
        args.inputDir = inputDir
        args.cuda = True
        forwardAll(model, args)
예제 #10
0
def main():
    args = parse_args()

    # Choose the GPUs
    os.environ["CUDA_DEVICE_ORDER"] = 'PCI_BUS_ID'
    os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu

    model = bdcn.BDCN()
    if torch.cuda.is_available():
        map_location = lambda storage, loc: storage.cuda()
    else:
        map_location = 'cpu'

    model.load_state_dict(
        torch.load('%s' % (args.model), map_location=map_location))
    test(model, args)
def execute(gpu, cuda, trained_model, res_dir, data_root, test_lst):

    # Import model and use gpu
    os.environ['CUDA_VISIBLE_DEVICES'] = gpu
    model = bdcn.BDCN()

    #####  Using GPU  ####
    if cuda:
        model.load_state_dict(torch.load('%s' % (trained_model)))
    else:
        #### Using CPU   ####
        model.load_state_dict(
            torch.load('%s' % (trained_model),
                       map_location=torch.device('cpu')))

    # Call test function and detect edges
    test(model, cuda, res_dir, data_root, test_lst)
예제 #12
0
def main():
    args = parse_args()
    os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu
    logging.info('Loading model...')
    model = bdcn.BDCN()
    logging.info('Loading state...')
    model.load_state_dict(torch.load('%s' % (args.model)))
    logging.info('Start image processing...')

    inputDirs = [
        '/run/user/1000/gvfs/smb-share:server=192.168.0.253,share=data/Master/datasets/bsr_bsds500/BSR/BSDS500/data/images/test_png/'
        #'/run/user/1000/gvfs/smb-share:server=192.168.0.253,share=data/Master/datasets/test_dataset/hdr_fusion/flicker_synthetic/flicker_1'
    ]
    #baseDir = '/run/user/1000/gvfs/smb-share:server=192.168.0.253,share=data/Master/datasets/'
    #inputDirs = [
    #args.inputDir
    #os.path.join(baseDir, 'rgbd_dataset_freiburg1_desk/rgb/'),
    #os.path.join(baseDir, 'rgbd_dataset_freiburg1_desk2/rgb/'),
    #os.path.join(baseDir, 'rgbd_dataset_freiburg1_plant/rgb/'),
    #os.path.join(baseDir, 'rgbd_dataset_freiburg1_room/rgb/'),
    #os.path.join(baseDir, 'rgbd_dataset_freiburg1_rpy/rgb/'),
    #os.path.join(baseDir, 'rgbd_dataset_freiburg1_xyz/rgb/'),
    #os.path.join(baseDir, 'rgbd_dataset_freiburg2_desk/rgb/'),
    #os.path.join(baseDir, 'rgbd_dataset_freiburg2_xyz/rgb/'),
    #os.path.join(baseDir, 'rgbd_dataset_freiburg3_long_office_household/rgb/'),
    #]
    # baseDir = '/run/user/1000/gvfs/smb-share:server=192.168.0.253,share=data/Master/datasets/test_dataset'
    # inputDirs = [
    #     os.path.join(baseDir, 'hdr_fusion', 'flicker_synthetic', 'flicker_1'),
    #     os.path.join(baseDir, 'hdr_fusion', 'smooth_synthetic', 'flicker_2'),
    #     os.path.join(baseDir, 'nyu_depth_v2', 'basements', 'basement_001c'),
    #     os.path.join(baseDir, 'nyu_depth_v2', 'cafe', 'cafe_0001c'),
    #     os.path.join(baseDir, 'nyu_depth_v2', 'classrooms', 'classroom_0014'),
    #     os.path.join(baseDir, 'tum', 'rgbd_dataset_freiburg1_desk', 'rgb'),
    #     os.path.join(baseDir, 'tum', 'rgbd_dataset_freiburg1_xyz', 'rgb'),
    #     os.path.join(baseDir, 'tum', 'rgbd_dataset_freiburg2_xyz', 'rgb'),
    # ]

    for inputDir in inputDirs:
        args.inputDir = inputDir
        args.cuda = True
        forwardAll(model, args)
예제 #13
0
def main():
    args = parse_args()
    logger = log.get_logger(args.log)
    args.logger = logger
    logger.info('*' * 80)
    logger.info('the args are the below')
    logger.info('*' * 80)
    for x in args.__dict__:
        logger.info(x + ',' + str(args.__dict__[x]))
    logger.info(cfg.config[args.dataset])
    logger.info('*' * 80)
    os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu
    if not os.path.exists(args.param_dir):
        os.mkdir(args.param_dir)
    torch.manual_seed(long(time.time()))
    model = bdcn.BDCN(pretrain=args.pretrain, logger=logger)
    pytorch_total_params = sum(p.numel() for p in model.parameters()
                               if p.requires_grad)
    print('TOTAL TRAINABLE PARAMS: ' + str(pytorch_total_params))
    if args.complete_pretrain:
        model.load_state_dict(torch.load(args.complete_pretrain))
    logger.info(model)
    train(model, args)
예제 #14
0
파일: train.py 프로젝트: xavysp/BDCN_xsp
def main():
    args = parse_args()
    logger = log.get_logger(args.log)
    args.logger = logger
    print('*' * 80)
    print('the args are the below')
    logger.info('*' * 80)
    for x in args.__dict__:
        print(x + ',' + str(args.__dict__[x]))
    print(cfg.config[args.dataset])
    print('*' * 80)
    # os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
    os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu
    if not os.path.exists(args.param_dir):
        os.mkdir(args.param_dir)
    torch.manual_seed(int(time.time()))
    device = torch.device('cpu' if torch.cuda.device_count() == 0 else 'cuda')
    model = bdcn.BDCN(pretrain=args.pretrain, logger=logger).to(device)
    if args.complete_pretrain:
        model.load_state_dict(
            torch.load(args.complete_pretrain, map_location=device))
    logger.info(model)
    train(model, args, device=device)
예제 #15
0
    # print(os.path.join(test_root, nm))
    # data = cv2.resize(data, (data.shape[1]/2, data.shape[0]/2), interpolation=cv2.INTER_LINEAR)
    data = np.array(imagen, np.float32)
    data -= mean_bgr
    data = data.transpose((2, 0, 1))
    data = torch.from_numpy(data).float().unsqueeze(0)
    data = Variable(data)

    out = model(data)

    out = [torch.sigmoid(x).cpu().data.numpy()[0, 0] for x in out]
    img = out[-1]
    img = 255 * img
    #print(img)
    print('Overall Time use: ', time.time() - start_time)
    #a = np.reshape(out,weigh,heigh)
    #print(type(img))

    cv2.imshow("out", img)
    cv2.waitKey()


if __name__ == '__main__':
    model = bdcn.BDCN()
    model.load_state_dict(
        torch.load("bdcn_pretrained_on_bsds500.pth",
                   map_location=torch.device('cpu')))
    model.eval()
    #print(model)
    test(model)