def generate_distance_matrix_model(input_model,
                                   base_model,
                                   metric="l2",
                                   db_path=None,
                                   ds_name=None,
                                   dtype="float",
                                   **kwargs):
    name_ = "distance_matrix_{}__{}".format(metric, base_model["name"])
    model = {
        "type": "computer",
        "name": name_,
        "computer_func_name": metric,
        "computer_func_params": {
            "base_model": base_model,
            "library_func_kwargs": {
                **kwargs
            }
        },
        "dtype": dtype,
        "chunk_size": -1,
        # computer assumes input as
        "input_model": input_model,
    }
    add_output_model(model, db_path, ds_name)
    return model
def generate_KNeighbors_accuracy_model(input_model, base_descriptors_model, true_classes_model, n_nearest, db_path=None,
                                       ds_name=None, dtype="float",
                                       **kwargs):
    """
        compute accuracy directly from descriptors through KNeighbors
        metric like ADC will be unoptimized
    """
    name_ = "accuracy_KNeighbors_{}_{}".format(n_nearest, base_descriptors_model["name"])
    model = {
        "type": "computer",
        "name": name_,
        "computer_func_name": "accuracy_KNeighbors",
        "computer_func_params": {
            "base_model": base_descriptors_model,
            "true_classes_model": true_classes_model,
            "n_nearest": n_nearest,
            "library_func_kwargs": {
                **kwargs
            }
        },
        "dtype": dtype,
        "chunk_size": -1,
        "input_model": input_model,  # descriptors_model
    }
    add_output_model(model, db_path, ds_name)
    return model
def generate_pq_model(input_model,
                      n_quantizers,
                      n_clusters,
                      db_path=None,
                      ds_name=None,
                      dtype="float",
                      **kwargs):
    name_ = "pq_{}_{}__{}".format(n_quantizers, n_clusters,
                                  input_model["name"])
    model = {
        "type": "computer",
        "name": name_,
        "computer_func_name": "pq",
        "computer_func_params": {
            "n_quantizers": n_quantizers,
            "n_clusters": n_clusters,
            "library_func_kwargs": {
                **kwargs
            }
        },
        "dtype": dtype,
        "chunk_size": -1,
        #computer assumes input as
        "input_model": input_model,
    }
    add_output_model(model, db_path, ds_name)
    return model
def generate_rgbapilimage_to_rgbpilimage_model(input_model,
                                               db_path=None,
                                               ds_name=None,
                                               dtype="float"):
    name_ = "rgbapilimage_to_rgbpilimage"
    model = {
        "type": "computer",
        "name": name_,
        "computer_func_name": "rgbapilimage_to_rgbpilimage",
        "dtype": dtype,
        "input_model": input_model,
    }
    add_output_model(model, db_path, ds_name)
    return model
def generate_jpeg_to_matrix_model(input_model,
                                  db_path=None,
                                  ds_name=None,
                                  dtype="float"):
    name_ = "jpeg_to_matrix"
    model = {
        "type": "computer",
        "name": name_,
        "computer_func_name": "jpeg_to_matrix",
        "dtype": dtype,
        "input_model": input_model,
    }
    add_output_model(model, db_path, ds_name)
    return model
def generate_pilimage_to_resizedpilimage_model(input_model,
                                               size,
                                               db_path=None,
                                               ds_name=None,
                                               dtype="float"):
    name_ = "pilimage_to_resizedpilimage"
    model = {
        "type": "computer",
        "name": name_,
        "computer_func_name": name_,
        "computer_func_params": {
            "size": size
        },
        "dtype": dtype,
        "input_model": input_model,
    }
    add_output_model(model, db_path, ds_name)
    return model
def generate_accuracy_model(input_model, true_classes_model, db_path=None, ds_name=None, dtype="float",
                            **kwargs):
    name_ = "accuracy__{}".format(input_model["name"])
    model = {
        "type": "computer",
        "name": name_,
        "computer_func_name": "accuracy",
        "computer_func_params": {
            "true_classes_model": true_classes_model,
            "library_func_kwargs": {
                **kwargs
            }
        },
        "dtype": dtype,
        "chunk_size": -1,
        "input_model": input_model,  # classification_model
    }
    add_output_model(model, db_path, ds_name)
    return model
Example #8
0
def generate_normalization_model(input_model,
                                 norm="l2",
                                 db_path=None,
                                 ds_name=None,
                                 dtype="float"):
    name_ = "{}__{}".format(norm, input_model["name"])
    model = {
        "type": "computer",
        "name": name_,
        "computer_func_name": "normalize",
        "computer_func_params": {
            "norm": norm,
            "library_func_kwargs": {}
        },
        "dtype": dtype,
        "input_model": input_model,
        "chunk_size": -1
    }
    add_output_model(model, db_path, ds_name)
    return model
Example #9
0
def generate_pqcode_model(input_model,
                          quantization_model,
                          db_path=None,
                          ds_name=None,
                          dtype="int"):
    name_ = "pqcode__{}".format(quantization_model["name"])
    model = {
        "type": "computer",
        "name": name_,
        "computer_func_name": "pqcode",
        "computer_func_params": {
            "quantization_model": quantization_model,
            "library_func_kwargs": {}
        },
        "dtype": dtype,
        "input_model": input_model,
        "chunk_size": 30
    }
    add_output_model(model, db_path, ds_name)
    return model
def generate_tiling_model(input_model, image_model, downsample, db_path=None, ds_name=None, dtype="int",
                          **kwargs):
    name_ = "openslide_tiler__{}".format(input_model["name"])
    model = {
        "type": "computer",
        "name": name_,
        "computer_func_name": "openslide_tiler",
        "computer_func_params": {
            "image_model": image_model,
            "downsample": downsample,
            # "tiles_rects_model": tiles_rects_model,
            "library_func_kwargs": {
                **kwargs
            }
        },
        "dtype": dtype,
        # tiles_rects как output у tiles_rects_model либо просто inmemory
        "input_model": input_model
    }
    add_output_model(model, db_path, ds_name)
    return model
def generate_rect_tiles_model(rect_size, tile_size, tile_step, db_path=None, ds_name=None,
                         dtype="int",
                         **kwargs):
    name_ = "rects_{}_{}_{}_{}_{}_{}".format(*rect_size, *tile_size, *tile_step)
    model = {
        "type": "computer",
        "name": name_,
        "computer_func_name": "rect_tiles",
        "computer_func_params": {
            "rect_size": rect_size,
            "tile_size": tile_size,
            "tile_step": tile_step,
            "library_func_kwargs": {
                **kwargs
            }
        },
        "dtype": dtype,
        # "input_model": input_model,
    }
    add_output_model(model, db_path, ds_name)
    return model
Example #12
0
def generate_vgg16_model(input_model,
                         layer_name,
                         chunk_size=30,
                         db_path=None,
                         ds_name=None,
                         dtype="float"):
    name_ = "vgg16_{}".format(layer_name)
    model = {
        "type": "computer",
        "name": name_,
        "computer_func_name": "vgg16",
        "computer_func_params": {
            "layer_name": layer_name,
            "library_func_kwargs": {}
        },
        "dtype": dtype,
        "input_model": input_model,
        "chunk_size": chunk_size
    }
    add_output_model(model, db_path, ds_name)
    return model
Example #13
0
def generate_histogram_model(input_model,
                             n_bins,
                             density,
                             db_path=None,
                             ds_name=None,
                             dtype="float"):
    name_ = "histogram_{}".format(n_bins)
    model = {
        "type": "computer",
        "name": name_,
        "computer_func_name": "histogram",
        "computer_func_params": {
            "n_bins": n_bins,
            "density": density,
            "library_func_kwargs": {}
        },
        "dtype": dtype,
        "input_model": input_model,
    }
    add_output_model(model, db_path, ds_name)
    return model
def generate_nearest_indices_model(input_model,
                                   n_nearest=-1,
                                   db_path=None,
                                   ds_name=None,
                                   dtype="float",
                                   **kwargs):
    name_ = "argsort__{}".format(input_model["name"])
    model = {
        "type": "computer",
        "name": name_,
        "computer_func_name": "argsort",
        "computer_func_params": {
            "n_nearest": n_nearest,
            "library_func_kwargs": {
                **kwargs
            }
        },
        "dtype": dtype,
        "chunk_size": -1,
        "input_model": input_model,
    }
    add_output_model(model, db_path, ds_name)
    return model
Example #15
0
def generate_lbp_model(input_model,
                       P,
                       R,
                       method,
                       db_path=None,
                       ds_name=None,
                       dtype="float"):
    name_ = "lbp_{}_{}_{}".format(P, R, method)
    model = {
        "type": "computer",
        "name": name_,
        "computer_func_name": "lbp",
        "computer_func_params": {
            "library_func_kwargs": {
                "P": P,
                "R": R,
                "method": method
            }
        },
        "dtype": dtype,
        "input_model": input_model,
    }
    add_output_model(model, db_path, ds_name)
    return model