mapreader.spot_text.runner_base
Classes
Module Contents
- class mapreader.spot_text.runner_base.Runner
- run_all(patch_df=None, return_dataframe=False, min_ioa=0.7)
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
min_ioa (float, optional) – The minimum intersection over area to consider two polygons the same, by default 0.7
- 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, min_ioa=0.7)
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
min_ioa (float, optional) – The minimum intersection over area to consider two polygons the same, by default 0.7
- 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, min_ioa=0.7)
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
min_ioa (float, optional) – The minimum intersection over area to consider two polygons the same, by default 0.7
- Returns:
The predictions for the image or the outputs from the model if return_outputs is True.
- Return type:
dict or pd.DataFrame
- convert_to_parent_pixel_bounds(patch_df=None, return_dataframe=False, deduplicate=False, min_ioa=0.7)
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
deduplicate (bool, optional) – Whether to deduplicate the parent predictions, by default False. Depending on size of parent images, this can be slow.
min_ioa (float, optional) – The minimum intersection over area to consider two polygons the same, by default 0.7 This is only used if deduplicate is True.
- 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)
Save the georeferenced predictions to a GeoJSON file.
- Parameters:
save_path (str | pathlib.Path, optional) – Path to save the GeoJSON file
- Return type:
None
- show(image_id, figsize=(10, 10), border_color='r', text_color='b', image_width_resolution=None, return_fig=False)
Show the predictions on an image.
- Parameters:
image_id (str) – The image ID to show the predictions on.
figsize (tuple | None, optional) – The size of the figure, by default (10, 10)
border_color (str | None, optional) – The color of the border of the polygons, by default “r”
text_color (str | None, optional) – The color of the text, by default “b”
image_width_resolution (int | None, optional) – The maximum resolution of the image width, by default None
return_fig (bool, optional) – Whether to return the figure, by default False
- Returns:
The matplotlib figure if return_fig is True.
- Return type:
fig
- Raises:
ValueError – If the image ID is not found in the patch or parent predictions.