Exemplo n.º 1
0
def main(
    root="data",
    image_type="train_frames_rgb",
    shape_root="data",
    output_format=".tif",
    shape_type="geojson_buildings",
    shape_name="vegas.geojson",
    mode="standard",
    extension=".tif",
    storage="train_masks_rgb",
):
    """
    Takes as input the a tile and returns chips.
    ==========================================
    :width: Desired width of each chip.
    :height: Desired height of each chip.
    :out_path: Desired output file storage folder.
    :in_path: Folder where the input tile is stored.
    :input_filename: Name of the input tile
    :output_filename: Desired output file pattern
    ===========================================
    """
    prefix = common.get_local_image_path(root, image_type)
    prefix_storage = common.get_local_image_path(root, storage)

    if mode == "append":
        out_path = common.get_local_image_path(shape_root, shape_type,
                                               shape_name)
        in_path = common.get_local_image_path(shape_root, shape_type)
        vector.execute_geojson_to_shape(in_path, out_path)

    shapes = get_shapes(shape_root, shape_type, shape_name)

    remaining = [
        common.\
        get_local_image_path(root, image_type, f)
        for f in common.get_remaining(output_format,
                                      extension, storage,
                                      prefix, prefix_storage,)
    ]

    counter = 0

    for f in remaining:

        print(f)
        print(counter)

        counter += 1
        mask, trans, meta = get_mask(f, shapes)
        f_name = os.path.splitext(os.path.basename(f))[0] + output_format

        try:
            write_mask(mask, meta, root, storage, f_name)
        except Exception as e:
            print(e)
            continue
Exemplo n.º 2
0
def create_custom_gen(
    train_frame,
    train_mask,
    val_frame,
    val_mask,
    img_type,
    rescale,
    shear_range,
    zoom_range,
    horizontal_flip,
    batch_size,
    class_mode,
    target_size,
    mask_color,
    data_format,
    custom,
    channels,
):
    """
    ---------------------------------------------
    Input: N/A
    Output: Tensorboard directory path
    ---------------------------------------------
    """
    img_list, frame_root, mask_root = get_data_list(img_type, train_frame,
                                                    train_mask, val_frame,
                                                    val_mask)
    c = 0

    while True:

        img = get_data_store(batch_size, target_size, channels)
        mask = get_data_store(batch_size, target_size, 1)

        for i in range(c, c + batch_size):

            img_path = common.get_local_image_path(frame_root, img_type,
                                                   img_list[i])
            mask_path = common.get_local_image_path(mask_root, img_type,
                                                    img_list[i])

            train_img = prep_train(img_path, rescale, target_size)
            mask_img = prep_mask(mask_path, target_size)

            img[i - c] = train_img
            mask[i - c] = mask_img

        c += batch_size

        if c + batch_size >= len(img_list):
            c = 0
            random.shuffle(img_list)

        yield img, mask
Exemplo n.º 3
0
def check_folders(paths, extension):
    """
    ---------------------------------------------
    Input: None
    Output: None
    Run the test harness for evaluating a model
    ---------------------------------------------
    """
    # Get the filepaths

    # Make sure train and test folders have the same data-sets
    for args in [(paths[0], paths[1]), (paths[2], paths[3])]:
        check_input_directories(*args)

    for folder in paths:
        new_folder = folder.split("/")[1].split("_")[0]
        try:
            os.makedirs(common.get_local_image_path(folder, new_folder))
        except FileExistsError as e:
            print("Directory exists so not making a new one...")
            continue

    for folder in paths:
        for f in os.listdir(folder):
            if f.endswith(extension):
                new = folder.split("/")[1].split("_")[0]
                dest = os.path.join(folder, new)
                source = os.path.join(folder, f)
                os.rename(source, os.path.join(dest, f))
Exemplo n.º 4
0
def main(test=1,
         channels = 8, 
         img_type = "val", 
         model_name = "run_2.h5", 
         target_width = 640,
         target_height = 640,
         root = "data"):
    """
    Takes as input the a tile and returns chips.
    ==========================================
    :width: Desired width of each chip.
    :height: Desired height of each chip.
    :out_path: Desired output file storage folder.
    :in_path: Folder where the input tile is stored.
    :input_filename: Name of the input tile
    :output_filename: Desired output file pattern
    ===========================================
    """
    target_size = (target_width, target_height)
    
    track = {"iou": iou, "dice_coef": dice_coef, 
            "iou_thresholded": iou_thresholded}
    
    results=os.path.join("train", "results")
    model=os.path.join(results, model_name)
    masks_path = os.path.join(root, "{}_masks".format(img_type))
    frames_path = os.path.join(root, "{}_frames".format(img_type))
    outputs_path = os.path.join(root, "{}_outputs".format(img_type))

    frames = raster.list_images(frames_path, img_type)
    masks = raster.list_images(masks_path, img_type)

    tests = [common.get_local_image_path(frames_path, img_type, f) for f in frames]
    outputs = [common.get_local_image_path(outputs_path, img_type, f) for f in frames]
    masks = [common.get_local_image_path(masks_path, img_type, f) for f in masks if f in frames]

    if test == 1:
        tests = tests[20:22]
        masks = masks[20:22]
        outputs = outputs[20:22]
    
    run_pred(model, track, tests, masks, outputs, target_size, channels)
Exemplo n.º 5
0
def get_shapes(shape_root, shape_type, shape_name):
    """
    ------------------------
    Input: 
    Output:
    ------------------------
    """
    shp = common.get_local_image_path(shape_root, shape_type, shape_name)
    shape = vector.open_shape_file(shp)
    shapes = vector.get_shapes(shape)

    return shapes
Exemplo n.º 6
0
def get_paths(train_frames, train_masks, val_frames, val_masks):
    """
    ---------------------------------------------
    Input: Keras history project
    Output: Display diagnostic learning curves
    ---------------------------------------------
    """
    paths = []

    for folder in [train_frames, train_masks, val_frames, val_masks]:
        paths.append(common.get_local_image_path("data", folder))

    return paths
Exemplo n.º 7
0
def write_mask(
    mask,
    meta,
    root,
    image_type,
    image_name,
):
    """
    ------------------------
    Input: 
    Output:
    ------------------------
    """
    file_from = common.get_local_image_path(root, image_type, image_name)
    raster.write_image(file_from, mask, meta)
Exemplo n.º 8
0
def main():

    root = get_root_folder()
    image_type = get_image_type(root)
    source = common.get_s3_paths(root, image_type)

    common.make_folders(root, source)
    images = get_image_keys(source)

    existing = [
        common.get_local_image_path(root, destination, img)
        for img in common.list_local_images(root, image_type)
    ]

    images = [img for img in images if img not in existing]
    get_images(images, existing)
Exemplo n.º 9
0
def main(root="data",
         image_type="frames",
         train_split=0.75,
         train_target="train_frames",
         val_target="val_frames"):
    """
    Takes as input the a tile and returns chips.
    ==========================================
    :width: Desired width of each chip.
    :height: Desired height of each chip.
    :out_path: Desired output file storage folder.
    :in_path: Folder where the input tile is stored.
    :input_filename: Name of the input tile
    :output_filename: Desired output file pattern
    ===========================================
    """
    train_target = os.path.join(root, train_target)
    val_target = os.path.join(root, val_target)

    if not os.path.exists(train_target):
        os.makedirs(train_target)

    if not os.path.exists(val_target):
        os.makedirs(val_target)

    prefix = common.get_local_image_path(root, image_type)
    files = [
        os.path.join(prefix, f)
        for f in common.list_local_images(root, image_type)
    ]

    files = shuffle_files(files)
    train_frames, val_frames = get_train_val(files, train_split)
    train_dest, val_dest = get_dest_files(train_target, val_target,
                                          train_frames, val_frames)

    add_frames(train_frames, train_dest)
    add_frames(val_frames, val_dest)