mapreader.spot_text.deepsolo_runner
Module Contents
Classes
- class mapreader.spot_text.deepsolo_runner.DeepSoloRunner(patch_df=None, parent_df=None, cfg_file='./DeepSolo/configs/R_50/IC15/finetune_150k_tt_mlt_13_15_textocr.yaml', weights_file='./ic15_res50_finetune_synth-tt-mlt-13-15-textocr.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='./deepsolo_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)
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.