예제 #1
0
def train_bowl():
    global config
    torch.backends.cudnn.benchmark = True
    cleanup_mac_hidden_files(config.dataset_path)
    sample_count = len(os.listdir(config.dataset_path))
    idx = list(range(sample_count))
    random.seed(1)
    random.shuffle(idx)
    split = 0.95
    train_idx, val_idx = idx[:int(split *
                                  sample_count)], idx[int(split *
                                                          sample_count):]
    im_type = BorderImageType if not config.sigmoid else SigmoidBorderImageType
    im_val_type = PaddedImageType if not config.sigmoid else PaddedSigmoidImageType
    ds = CachingImageProvider(im_type, paths, fn_mapping)
    val_ds = CachingImageProvider(im_val_type, paths, fn_mapping)
    fold = args.fold
    train(ds,
          val_ds,
          fold,
          train_idx,
          val_idx,
          config,
          num_workers=num_workers,
          transforms=aug_victor(.97))
예제 #2
0
def train_roads():
	ds = ReadingImageProvider(RawImageType, paths, fn_mapping, image_suffix=image_suffix)

	folds = get_csv_folds('folds4.csv', ds.im_names)
	num_workers = 0 if os.name == 'nt' else 2
	for fold, (train_idx, val_idx) in enumerate(folds):
		if args.fold is not None and int(args.fold) != fold:
			continue
		train(ds, fold, train_idx, val_idx, config, num_workers=num_workers, transforms=get_flips_colors_augmentation())
예제 #3
0
def train_roads():
    ds = ReadingImageProvider(RawImageType, paths, fn_mapping, image_suffix=image_suffix)

    folds = get_csv_folds('folds4.csv', ds.im_names)
    num_workers = 0 if os.name == 'nt' else 2
    for fold, (train_idx, val_idx) in enumerate(folds):
        if args.fold is not None and int(args.fold) != fold:
            continue
        train(ds, fold, train_idx, val_idx, config, num_workers=num_workers, transforms=get_flips_colors_augmentation())
예제 #4
0
def train_stage0():
    """
    heat up weights for 5 epochs
    """
    ds = ReadingImageProvider(TiffImageType,
                              paths,
                              fn_mapping,
                              image_suffix='RGB')

    folds = get_folds(ds, 5)
    num_workers = 0 if os.name == 'nt' else 8
    train(ds,
          folds,
          config,
          num_workers=num_workers,
          transforms=augment_flips_color)
def train_bowl():
    torch.backends.cudnn.benchmark = True
    im_type = BorderImageType if not config.sigmoid else SigmoidBorderImageType
    im_val_type = PaddedImageType if not config.sigmoid else PaddedSigmoidImageType
    ds = CachingImageProvider(im_type, paths, fn_mapping)
    val_ds = CachingImageProvider(im_val_type, paths, fn_mapping)
    folds = get_csv_folds(ds, os.path.join(config.dataset_path, 'folds.csv'))
    for fold, (train_idx, val_idx) in enumerate(folds):
        if args.fold is not None and int(args.fold) != fold:
            continue
        train(ds,
              val_ds,
              fold,
              train_idx,
              val_idx,
              config,
              num_workers=num_workers,
              transforms=aug_victor(.97))
예제 #6
0
def train_roads(config,
                paths,
                fn_mapping,
                image_suffix,
                folds_file_loc,
                save_path,
                log_path,
                num_channels=3):
    #t0 = time.time()
    ds = ReadingImageProvider(RawImageType,
                              paths,
                              fn_mapping,
                              image_suffix=image_suffix,
                              num_channels=num_channels)
    print("len ds:", len(ds))
    print("folds_file_loc:", folds_file_loc)
    print("save_path:", save_path)
    folds = get_csv_folds(folds_file_loc, ds.im_names)
    #folds = get_csv_folds('folds4.csv', ds.im_names)
    num_workers = 0 if os.name == 'nt' else 2
    for fold, (train_idx, val_idx) in enumerate(folds):
        if args.fold is not None and int(args.fold) != fold:
            continue
        print("num workers:", num_workers)
        print("fold:", fold)
        #print ("(train_idx, val_idx):", (train_idx, val_idx))
        print("len(train_idx):", len(train_idx))
        print("len(val_idx):", len(val_idx))

        if config.num_channels == 3:
            transforms = get_flips_colors_augmentation()
        else:
            # can't do hsv rescaling with multiband imagery, so skip this part
            transforms = get_flips_shifts_augmentation()

        train(ds,
              fold,
              train_idx,
              val_idx,
              config,
              save_path,
              log_path,
              num_workers=num_workers,
              transforms=transforms)
예제 #7
0
def train_stage2(sal_map: bool, three=False):
    """
    train with other loss function
    three = True ===> use only RGB for training
    """
    im_type = TiffDemImageType
    if sal_map:
        im_type = SalImageType
    if three:
        im_type = TiffImageType
    ds = ReadingImageProvider(im_type, paths, fn_mapping, image_suffix='RGB')

    folds = get_folds(ds, 5)
    num_workers = 0 if os.name == 'nt' else 8
    train(ds,
          folds,
          config,
          num_workers=num_workers,
          transforms=augment_flips_color)
예제 #8
0
def train_stage1(sal_map: bool, three=False):
    """
    main training stage with dtm/dsm data
    three = True ===> use only RGB for training
    updates channels from warm start with only RGB to final number of channels in config.num_channels
    """
    im_type = TiffDemImageType
    if sal_map:
        im_type = SalImageType
    if three:
        im_type = TiffImageType
    ds = ReadingImageProvider(im_type, paths, fn_mapping, image_suffix='RGB')

    folds = get_folds(ds, 5)
    num_workers = 0 if os.name == 'nt' else 8
    train(ds,
          folds,
          config,
          num_workers=num_workers,
          transforms=augment_flips_color,
          num_channels_changed=not three)