Esempio n. 1
0
def predict_3D_patches(model, patches, image, N_extra=0, logger=None):

    # Get box dim and image dim
    d = patches.dim
    i1, i2, i3 = image.shape[:3]

    # Prepare reconstruction volume. Predictions will be summed in this volume.
    recon = np.zeros(shape=(i1, i2, i3, model.n_classes), dtype=np.float32)

    # Predict on base patches + N extra randomly
    # sampled patches from the volume
    for patch, (i, k, v), status in patches.get_patches_from(image, N_extra):
        # Log the status of the generator
        print(status, end="\r", flush=True)

        # Predict on patch
        pred = model.predict(reshape_add_axis(patch, im_dims=3))

        # Add prediction to reconstructed volume
        recon[i:i+d, k:k+d, v:v+d] += pred.squeeze()
    print("")

    # Normalize
    recon /= np.sum(recon, axis=-1, keepdims=True)

    return recon
Esempio n. 2
0
def predict_3D_patches_binary(model, patches, image_id, N_extra=0, logger=None):
    # Get box dim and image dim
    d = patches.dim
    i1, i2, i3 = patches.im_dim

    # Prepare reconstruction volume. Predictions will be summed in this volume.
    recon = np.zeros(shape=(i1, i2, i3, 2), dtype=np.uint32)

    # Predict on base patches + N extra randomly
    # sampled patches from the volume
    for patch, (i, k, v), status in patches.get_patches_from(image_id, N_extra):
        # Log the status of the generator
        print(status, end="\r", flush=True)

        # Predict on patch
        pred = model.predict(reshape_add_axis(patch, im_dims=3)).squeeze()
        mask = pred > 0.5

        # Add prediction to reconstructed volume
        recon[i:i+d, k:k+d, v:v+d, 0] += ~mask
        recon[i:i+d, k:k+d, v:v+d, 1] += mask
    print("")

    total = np.sum(recon, axis=-1)
    return (recon[..., 1] > (0.20 * total)).astype(np.uint8)