From 867b83ae6b499a9a9fbd534382da753ff4986ad8 Mon Sep 17 00:00:00 2001 From: Rosie Wood Date: Tue, 23 Apr 2024 10:07:44 +0100 Subject: [PATCH] update file saving docs --- docs/source/User-guide/Classify/Infer.rst | 42 +++++++++++----------- docs/source/User-guide/Classify/Train.rst | 43 ++++++++++++----------- 2 files changed, 44 insertions(+), 41 deletions(-) diff --git a/docs/source/User-guide/Classify/Infer.rst b/docs/source/User-guide/Classify/Infer.rst index 6fe73dd6..26cf496e 100644 --- a/docs/source/User-guide/Classify/Infer.rst +++ b/docs/source/User-guide/Classify/Infer.rst @@ -124,46 +124,48 @@ As with the "test" dataset, to see a sample of your predictions, use: my_classifier.show_inference_sample_results(label="railspace", set_name="infer") -Add predictions to metadata and save -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -To add your predictions to your patch metadata (saved in ``patch_df.csv``), you will need to add your predictions and confidence values to your ``infer`` dataset's dataframe. +Save predictions +~~~~~~~~~~~~~~~~~ -This dataframe is saved as the datasets ``patch_df`` attribute. -To view it, use: +To save your predictions, use the ``.save_predictions()`` method. +e.g. to save your predictions on the "infer" dataset: .. code-block:: python - infer.patch_df + my_classifier.save_predictions(set_name="infer") -To add your predictions and confidence values to this dataframe use: -.. code-block:: python +Add predictions to metadata and save +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To add your predictions to your patch metadata (saved in ``patch_df.csv``), you will need to load your predictions as metadata in the ``MapImages`` object. + +To do this, you will need to create a new ``MapImages`` object and load in your patches and parent images: - import numpy as np +.. code-block:: python - infer.patch_df['predicted_label'] = my_classifier.pred_label - infer.patch_df['pred'] = my_classifier.pred_label_indices - infer.patch_df['conf'] = np.array(my_classifier.pred_conf).max(axis=1) + from mapreader import load_patches -If you view your dataframe again (by running ``infer.patch_df`` as above), you will see your predictions and confidence values have been added as columns. + my_maps = load_patches(patch_paths = "./path/to/patches/*png", parent_paths="./path/to/parents/*png") -From here, you can either save your results using: +You can then add your predictions to the metadata using the ``.add_metadata()`` method: .. code-block:: python - infer.patch_df.to_csv("predictions_patch_df.csv", sep=",") + my_maps.add_metadata("path_to_predictions_patch_df.csv", tree_level='patch') # add dataframe as metadata -Or, you can use the ``MapImages`` object to create some visualizations of your results: +For example, to load the predictions for the "infer" dataset: .. code-block:: python - from mapreader import load_patches + #EXAMPLE + my_maps.add_metadata("./infer_predictions_patch_df.csv", tree_level='patch') - my_maps = load_patches(patch_paths = "./path/to/patches/*png", parent_paths="./path/to/parents/*png") +From here, you can use the ``.show_parent()`` method to visualize your predictions on the parent images as shown in the :doc:`Load ` user guide: + +.. code-block:: python - infer_df = infer.patch_df.reset_index(names="image_id") # ensure image_id is one of the columns - my_maps.add_metadata(infer_df, tree_level='patch') # add dataframe as metadata my_maps.add_shape() parent_list = my_maps.list_parents() diff --git a/docs/source/User-guide/Classify/Train.rst b/docs/source/User-guide/Classify/Train.rst index c5ce46a3..110668a8 100644 --- a/docs/source/User-guide/Classify/Train.rst +++ b/docs/source/User-guide/Classify/Train.rst @@ -631,46 +631,47 @@ As with the "test" dataset, to see a sample of your predictions, use: my_classifier.show_inference_sample_results(label="railspace", set_name="infer") -Add predictions to metadata and save -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Save predictions +~~~~~~~~~~~~~~~~~ -To add your predictions to your patch metadata (saved in ``patch_df.csv``), you will need to add your predictions and confidence values to your ``infer`` dataset's dataframe. - -This dataframe is saved as the datasets ``patch_df`` attribute. -To view it, use: +To save your predictions, use the ``.save_predictions()`` method. +e.g. to save your predictions on the "infer" dataset: .. code-block:: python - infer.patch_df + my_classifier.save_predictions(set_name="infer") -To add your predictions and confidence values to this dataframe use: -.. code-block:: python +Add predictions to metadata and save +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To add your predictions to your patch metadata (saved in ``patch_df.csv``), you will need to load your predictions as metadata in the ``MapImages`` object. + +To do this, you will need to create a new ``MapImages`` object and load in your patches and parent images: - import numpy as np +.. code-block:: python - infer.patch_df['predicted_label'] = my_classifier.pred_label - infer.patch_df['pred'] = my_classifier.pred_label_indices - infer.patch_df['conf'] = np.array(my_classifier.pred_conf).max(axis=1) + from mapreader import load_patches -If you view your dataframe again (by running ``infer.patch_df`` as above), you will see your predictions and confidence values have been added as columns. + my_maps = load_patches(patch_paths = "./path/to/patches/*png", parent_paths="./path/to/parents/*png") -From here, you can either save your results using: +You can then add your predictions to the metadata using the ``.add_metadata()`` method: .. code-block:: python - infer.patch_df.to_csv("predictions_patch_df.csv", sep=",") + my_maps.add_metadata("path_to_predictions_patch_df.csv", tree_level='patch') # add dataframe as metadata -Or, you can use the ``MapImages`` object to create some visualizations of your results: +For example, to load the predictions for the "infer" dataset: .. code-block:: python - from mapreader import load_patches + #EXAMPLE + my_maps.add_metadata("./infer_predictions_patch_df.csv", tree_level='patch') - my_maps = load_patches(patch_paths = "./path/to/patches/*png", parent_paths="./path/to/parents/*png") +From here, you can use the ``.show_parent()`` method to visualize your predictions on the parent images as shown in the :doc:`Load ` user guide: + +.. code-block:: python - infer_df = infer.patch_df.reset_index(names="image_id") # ensure image_id is one of the columns - my_maps.add_metadata(infer_df, tree_level='patch') # add dataframe as metadata my_maps.add_shape() parent_list = my_maps.list_parents()