Esempio n. 1
0
def make_predictions():

    test_ids = next(os.walk(TRAIN_PATH))[1]
    X_test = np.zeros((len(test_ids), IMG_HEIGHT, IMG_WIDTH, 1),
                      dtype=np.uint8)
    sizes_test = []
    print('Getting and resizing test images ... ')
    sys.stdout.flush()

    for n, id_ in tqdm(enumerate(test_ids), total=len(test_ids)):
        path = TRAIN_PATH + id_
        img = imread(path + '/images/' + id_ + '.png')
        rgb = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        img_rgb = cv2.resize(rgb, (IMG_HEIGHT, IMG_WIDTH), 1)
        im_gray = np.expand_dims(img_rgb, axis=-1)
        X_test[n] = im_gray
    print('Done!')
    unet = Unet()
    model = unet.build_model(IMG_HEIGHT=IMG_HEIGHT, IMG_WIDTH=IMG_WIDTH)
    checkpoint_path = "model_weights.h5"
    # model.save_weights(checkpoint_path)
    model.load_weights(checkpoint_path)
    predict_masks_X = model.predict(X_test)
    return predict_masks_X
Esempio n. 2
0
IMG_HEIGHT = 128
IMG_CHANNELS = 3
TRAIN_PATH = '.\data\stage1_train/'
X, Y = preprocess_data.get_X_Y(IMG_HEIGHT=IMG_HEIGHT, IMG_WIDTH=IMG_WIDTH, TRAIN_PATH = TRAIN_PATH)
X_train, X_test, Y_train, Y_test = preprocess_data.split_data(X, Y)
img_avg = np.zeros((Y.shape[0], IMG_HEIGHT, IMG_WIDTH, 1), dtype=np.bool)
img_objects = np.zeros((len(Y), 1), dtype=np.int)
for i in range(len(Y)):
    img_avg += np.asarray(Y[i])
    img_objects[i] =  len(np.where(Y[i] > 0))

img_avg = img_avg/ len(Y)
print(img_objects)

unet = Unet()
model = unet.build_model(IMG_HEIGHT=IMG_HEIGHT, IMG_WIDTH=IMG_WIDTH)

checkpoint_path = "model_weights.h5"
model.load_weights(checkpoint_path)

# Predict on train, val and test
preds_train = model.predict(X_train[:int(X_train.shape[0]*0.9)], verbose=1)
preds_val = model.predict(X_train[int(X_train.shape[0]*0.9):], verbose=1)
preds_test = model.predict(X_test, verbose=1)
print(preds_test, type(preds_test), preds_test.shape)
# Threshold predictions
preds_train_t = (preds_train > 0.5).astype(np.uint8)
preds_val_t = (preds_val > 0.5).astype(np.uint8)
preds_test_t = (preds_test > 0.5).astype(np.uint8)
print(preds_train_t, preds_val_t, preds_test_t)
# Create list of upsampled test masks