text_plain_output_1.png
from skimage.io import imread

from skimage.transform import resize

from tqdm import tqdm

import numpy as np

import os

import random

TRAIN_PATH = '../input/train/'
TEST_PATH = '../input/test/'
seed = 42
random.seed = seed
np.random.seed = seed
tot_num = 5635
IMG_HEIGHT = 128
IMG_WIDTH = 128
files = os.listdir(TRAIN_PATH)
masks_list = []
imgs_list = []
for f in files:
    if 'mask' in f:
        masks_list.append(f)
    else:
        imgs_list.append(f)
masks_list = sorted(masks_list)
imgs_list = sorted(imgs_list)

Y_train_one = []
X_train_one = []
Y_train_zero = []
X_train_zero = []
for i, file in tqdm(enumerate(imgs_list), total=len(imgs_list)):
    img_path = file
    mask_path = img_path[:-4] + '_mask.tif'
    mask = imread(TRAIN_PATH + mask_path)
    mask = resize(mask, (IMG_HEIGHT, IMG_WIDTH), mode='constant', preserve_range=True)
    img = imread(TRAIN_PATH + img_path)
    img = resize(img, (IMG_HEIGHT, IMG_WIDTH), mode='constant', preserve_range=True)
    if mask.any() == False:
        Y_train_zero.append(mask)
        X_train_zero.append(img)
    else:
        Y_train_one.append(mask)
        X_train_one.append(img)