Exemple #1
0
depths_df = pd.read_csv('../train.csv')
file_list = list(depths_df['id'].values)

#remove images from train with only few pixels in mask
mask_paths = [train_path + '/masks/' + str(file) + '.png' for file in file_list]
num_pixels = [[mask,(cv2.imread(mask)[:,:,0:1] > 128).sum()] for mask in mask_paths]
idx = np.argsort(np.array(num_pixels)[:,1].astype(int))
cutoff = 10
removed_images = [path.split('/')[-1][:-4] for path, nb_pixels in num_pixels if int(nb_pixels) < cutoff and int(nb_pixels) != 0]

#redo file list
file_list = [file for file in file_list if file not in removed_images]

#redo mask list
mask_paths = [train_path + '/masks/' + str(file) + '.png' for file in file_list]
mask_class = [get_mask_type(np.transpose(cv2.imread(mask), (2, 0, 1))[0,:, :]/255) for mask in mask_paths]

#test files
test_file_list = glob.glob(os.path.join(test_path, 'images', '*.png'))
test_file_list = [f.split('/')[-1].split('\\')[-1][:-4] for f in test_file_list] 

#five fold generator
fold = StratifiedKFold(n_splits = 10, shuffle = True, random_state = 42)
folds = list(fold.split(file_list,mask_class))

train_idx = folds[0][0]
val_idx = folds[0][1]

#20 % train/val split
file_list_val = list(map(file_list.__getitem__,val_idx))
file_list_train = list(map(file_list.__getitem__,train_idx))
Exemple #2
0
idx = np.argsort(np.array(num_pixels)[:, 1].astype(int))
cutoff = 10
removed_images = [
    path.split('/')[-1][:-4] for path, nb_pixels in num_pixels
    if int(nb_pixels) < cutoff and int(nb_pixels) != 0
]

#redo file list
file_list = [file for file in file_list if file not in removed_images]

#redo mask list
mask_paths = [
    train_path + '/masks/' + str(file) + '.png' for file in file_list
]
mask_class = [
    get_mask_type(np.transpose(cv2.imread(mask), (2, 0, 1))[0, :, :] / 255)
    for mask in mask_paths
]

#test files
test_file_list = glob.glob(os.path.join(test_path, 'images', '*.png'))
test_file_list = [
    f.split('/')[-1].split('\\')[-1][:-4] for f in test_file_list
]

#five fold generator
fold = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)

train_loss_save = {}
val_loss_save = {}
val_iou_save = {}