beacon_aug/screenshot.py
def screenshot_pipeline(augPipeline, image, save_fig_path=None):
    ''' Visualize an augmentation pipeline by displaying the extreme case for all the parameters
    '''
    # get the flattened operator sequence avoiding hierarchical structure
    single_operation_ls = extract_single_operation(augPipeline)

    numOfOperation = len(single_operation_ls)
    fig, axs = plt.subplots(numOfOperation, 3,
                            figsize=(6, 2*numOfOperation),
                            constrained_layout=True)

    axs[0, 1].set_title("Lower Limit")
    axs[0, 2].set_title("Upper Limit")

    for i, single_operation in enumerate(single_operation_ls):
        # Extract the upper and lower limit
        transform_name = single_operation["transform"]['__class_fullname__'].split(".")[-1]
        # deep copy to avoid pointing save location in dict
        lowerAndUpper = [single_operation, deepcopy(single_operation)]
        limit_para_name = None
        # Extract all the limit parameters
        for para in single_operation["transform"]:
            if para == "p":   # change prob to 1 to make it always happen
                lowerAndUpper[0]["transform"][para] = 1
                lowerAndUpper[1]["transform"][para] = 1

            if "limit" in para:
                limit_para_name = para
                original_values = list(single_operation["transform"][para])
                lowerAndUpper[0]["transform"][para] = [original_values[0]]*2
                lowerAndUpper[1]["transform"][para] = [original_values[1]]*2

        # plot
        for lu in range(2):                          # lower or upper limit
            lu_transform = A.from_dict(lowerAndUpper[lu])
            axs[i, lu+1].imshow(lu_transform(image=image)["image"])
            axs[i, lu+1].axis("off")

        if limit_para_name:
            axs[i, 0].text(0.15, 0.5, transform_name+"\n" + limit_para_name+":" +
                           str(lowerAndUpper[0]["transform"][limit_para_name][0]) + "," +
                           str(lowerAndUpper[1]["transform"][limit_para_name][1]), dict(size=10))
        else:
            axs[i, 0].text(0.15, 0.5, transform_name, dict(size=10))
        axs[i, 0].axis("off")
    if save_fig_path:
        figname = os.path.join(save_fig_path, "aug_pipeline-screenshot.png")
        print("\n...screenshot figure save as : ", figname)
        plt.savefig(figname)
    return fig
 Visualize an augmentation pipeline by displaying the extreme case for all the parameters
    
Visualize an augmentation pipeline by displaying the extreme case for all the parameters
Visualize an augmentation pipeline by displaying the extreme case for all the parameters
def screenshot_pipeline(augPipeline, image, save_fig_path=None):
    single_operation_ls = extract_single_operation(augPipeline)
    numOfOperation = len(single_operation_ls)
    fig, axs = plt.subplots(numOfOperation, 3,
                            figsize=(6, 2*numOfOperation),
                            constrained_layout=True)
    axs[0, 1].set_title("Lower Limit")
    axs[0, 2].set_title("Upper Limit")
    for i, single_operation in enumerate(single_operation_ls):
        transform_name = single_operation["transform"]['__class_fullname__'].split(".")[-1]
        lowerAndUpper = [single_operation, deepcopy(single_operation)]
        limit_para_name = None
        for para in single_operation["transform"]:
            if para == "p":   
                lowerAndUpper[0]["transform"][para] = 1
                lowerAndUpper[1]["transform"][para] = 1
            if "limit" in para:
                limit_para_name = para
                original_values = list(single_operation["transform"][para])
                lowerAndUpper[0]["transform"][para] = [original_values[0]]*2
                lowerAndUpper[1]["transform"][para] = [original_values[1]]*2
        for lu in range(2):                          
            lu_transform = A.from_dict(lowerAndUpper[lu])
            axs[i, lu+1].imshow(lu_transform(image=image)["image"])
            axs[i, lu+1].axis("off")
        if limit_para_name:
            axs[i, 0].text(0.15, 0.5, transform_name+"\n" + limit_para_name+":" +
                           str(lowerAndUpper[0]["transform"][limit_para_name][0]) + "," +
                           str(lowerAndUpper[1]["transform"][limit_para_name][1]), dict(size=10))
        else:
            axs[i, 0].text(0.15, 0.5, transform_name, dict(size=10))
        axs[i, 0].axis("off")
    if save_fig_path:
        figname = os.path.join(save_fig_path, "aug_pipeline-screenshot.png")
        print("\n...screenshot figure save as : ", figname)
        plt.savefig(figname)
    return fig
def screenshot_pipeline ( augPipeline , image , save_fig_path = None ) : single_operation_ls = extract_single_operation ( augPipeline ) numOfOperation = len ( single_operation_ls ) fig , axs = plt . subplots ( numOfOperation , 3 , figsize = ( 6 , 2 * numOfOperation ) , constrained_layout = True ) axs [ 0 , 1 ] . set_title ( "Lower Limit" ) axs [ 0 , 2 ] . set_title ( "Upper Limit" ) for i , single_operation in enumerate ( single_operation_ls ) : transform_name = single_operation [ "transform" ] [ '__class_fullname__' ] . split ( "." ) [ - 1 ] lowerAndUpper = [ single_operation , deepcopy ( single_operation ) ] limit_para_name = None for para in single_operation [ "transform" ] : if para == "p" : lowerAndUpper [ 0 ] [ "transform" ] [ para ] = 1 lowerAndUpper [ 1 ] [ "transform" ] [ para ] = 1 if "limit" in para : limit_para_name = para original_values = list ( single_operation [ "transform" ] [ para ] ) lowerAndUpper [ 0 ] [ "transform" ] [ para ] = [ original_values [ 0 ] ] * 2 lowerAndUpper [ 1 ] [ "transform" ] [ para ] = [ original_values [ 1 ] ] * 2 for lu in range ( 2 ) : lu_transform = A . from_dict ( lowerAndUpper [ lu ] ) axs [ i , lu + 1 ] . imshow ( lu_transform ( image = image ) [ "image" ] ) axs [ i , lu + 1 ] . axis ( "off" ) if limit_para_name : axs [ i , 0 ] . text ( 0.15 , 0.5 , transform_name + "\n" + limit_para_name + ":" + str ( lowerAndUpper [ 0 ] [ "transform" ] [ limit_para_name ] [ 0 ] ) + "," + str ( lowerAndUpper [ 1 ] [ "transform" ] [ limit_para_name ] [ 1 ] ) , dict ( size = 10 ) ) else : axs [ i , 0 ] . text ( 0.15 , 0.5 , transform_name , dict ( size = 10 ) ) axs [ i , 0 ] . axis ( "off" ) if save_fig_path : figname = os . path . join ( save_fig_path , "aug_pipeline-screenshot.png" ) print ( "\n...screenshot figure save as : " , figname ) plt . savefig ( figname ) return fig
Visualize an augmentation pipeline by displaying the extreme case for all the parameters
Visualize an augmentation pipeline by displaying the extreme case for all the parameters
''' Visualize an augmentation pipeline by displaying the extreme case for all the parameters
    ''' # get the flattened operator sequence avoiding hierarchical structure # Extract the upper and lower limit # deep copy to avoid pointing save location in dict # Extract all the limit parameters # change prob to 1 to make it always happen # plot # lower or upper limit
augPipeline
image
save_fig_path