mapreader.spot_text.dptext_detr_runner

Module Contents

Classes

DPTextDETRRunner

class mapreader.spot_text.dptext_detr_runner.DPTextDETRRunner(patch_df=None, parent_df=None, cfg_file='./DPText-DETR/configs/DPText_DETR/ArT/R_50_poly.yaml', weights_file='./art_final.pth', device='cpu')
Parameters:
  • patch_df (pandas.DataFrame)

  • parent_df (pandas.DataFrame)

  • cfg_file (str | pathlib.Path)

  • weights_file (str | pathlib.Path)

  • device (str)

run_all(patch_df=None, return_dataframe=False)

Run the model on all images in the patch dataframe.

Parameters:
  • patch_df (pd.DataFrame, optional) – Dataframe containing patch information, by default None.

  • return_dataframe (bool, optional) – Whether to return the predictions as a pandas DataFrame, by default False

Returns:

A dictionary of predictions for each patch image or a DataFrame if as_dataframe is True.

Return type:

dict or pd.DataFrame

run_on_images(img_paths, return_dataframe=False)

Run the model on a list of images.

Parameters:
  • img_paths (str, pathlib.Path or list) – A list of image paths to run the model on.

  • return_dataframe (bool, optional) – Whether to return the predictions as a pandas DataFrame, by default False

Returns:

A dictionary of predictions for each image or a DataFrame if as_dataframe is True.

Return type:

dict or pd.DataFrame

run_on_image(img_path, return_outputs=False, return_dataframe=False)

Run the model on a single image.

Parameters:
  • img_path (str or pathlib.Path) – The path to the image to run the model on.

  • return_outputs (bool, optional) – Whether to return the outputs direct from the model, by default False

  • return_dataframe (bool, optional) – Whether to return the predictions as a pandas DataFrame, by default False

Returns:

The predictions for the image or the outputs from the model if return_outputs is True.

Return type:

dict or pd.DataFrame

get_patch_predictions(outputs, return_dataframe=False)

Post process the model outputs to get patch predictions.

Parameters:
  • outputs (dict) – The outputs from the model.

  • return_dataframe (bool, optional) – Whether to return the predictions as a pandas DataFrame, by default False

Returns:

A dictionary containing the patch predictions or a DataFrame if as_dataframe is True.

Return type:

dict or pd.DataFrame

convert_to_parent_pixel_bounds(patch_df=None, return_dataframe=False)

Convert the patch predictions to parent predictions by converting pixel bounds.

Parameters:
  • patch_df (pd.DataFrame, optional) – Dataframe containing patch information, by default None

  • return_dataframe (bool, optional) – Whether to return the predictions as a pandas DataFrame, by default False

Returns:

A dictionary of predictions for each parent image or a DataFrame if as_dataframe is True.

Return type:

dict or pd.DataFrame

Raises:

ValueError – If patch_df is not available.

convert_to_coords(parent_df=None, return_dataframe=False)

Convert the parent predictions to georeferenced predictions by converting pixel bounds to coordinates.

Parameters:
  • parent_df (pd.DataFrame, optional) – Dataframe containing parent image information, by default None

  • return_dataframe (bool, optional) – Whether to return the predictions as a pandas DataFrame, by default False

Returns:

A dictionary of predictions for each parent image or a DataFrame if as_dataframe is True.

Return type:

dict or pd.DataFrame

Raises:

ValueError – If parent_df is not available.

save_to_geojson(save_path='./dptext-detr_text_outputs.geojson')

Save the georeferenced predictions to a GeoJSON file.

Parameters:

save_path (str | pathlib.Path, optional) – Path to save the GeoJSON file, by default “./deepsolo_text_outputs.geojson”

Return type:

None

show(image_id, figsize=(10, 10), border_color='r', text_color='b', image_width_resolution=None, return_fig=False)
Parameters:
  • image_id (str)

  • figsize (tuple | None)

  • border_color (str | None)

  • text_color (str | None)

  • image_width_resolution (int | None)

  • return_fig (bool)

Return type:

None