Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

ENH: Switch recommonmark to MyST-parser #787

Merged
merged 25 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
267d4e8
📝 Create basic for ML API
peterhessey Aug 5, 2022
806f261
📝 Add ML/configs base doc files
peterhessey Aug 5, 2022
0cbd7c7
📝 Finish ML/configs API
peterhessey Aug 8, 2022
f5c82cf
📝 Update augmentations
peterhessey Aug 8, 2022
ac0171a
📝 Add ML/dataset API docs
peterhessey Aug 8, 2022
e9fff6a
📝 Add rst skeleton for ML/models
peterhessey Aug 8, 2022
4fd8de4
📝 Fix docstring missing newlines
peterhessey Aug 8, 2022
6371548
Remove script
peterhessey Aug 8, 2022
27e7784
📝 Finish ML/models API docs
peterhessey Aug 8, 2022
6a1273f
📝 Start ML/SSL API. Fix some formatting issues
peterhessey Aug 9, 2022
562173b
📝 Correct whitespace issues in `:param`
peterhessey Aug 9, 2022
416e907
📝 Fix whitespace errors on `:return` statements
peterhessey Aug 9, 2022
a778dac
📝 Fix :return: statements
peterhessey Aug 9, 2022
33b557c
📝 Finish ML/SSL API
peterhessey Aug 9, 2022
7d4f466
📝 Add ML/utils API docs
peterhessey Aug 9, 2022
19ab5b2
📝 Add visualizer docs, fix `:raise` indents
peterhessey Aug 9, 2022
67169af
📝 Fix more issues with the `:raises:` formatting
peterhessey Aug 9, 2022
7619004
♻️ Restructuring folders
peterhessey Aug 9, 2022
bdc2a51
📝 Limit API `toctree` depth
peterhessey Aug 9, 2022
56c3a52
📝 Add primary InnerEye/ML files API to docs
peterhessey Aug 9, 2022
e9e5ee8
📝 Fix and add `InnerEye/ML/*.py` docs
peterhessey Aug 9, 2022
c1d84a8
⚰️ Remove weird `settings.json` change
peterhessey Aug 9, 2022
933bc7b
📌 Switch recommonmark to MyST-parser
peterhessey Aug 15, 2022
6e610b0
📌 Add myst-parser to `environment.yml`, lock env
peterhessey Aug 16, 2022
a9a5278
Fix conflicts merging main
peterhessey Aug 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
📝 Finish ML/configs API
  • Loading branch information
peterhessey committed Aug 8, 2022
commit 0cbd7c71cc2e4b70f99b374bbed48dfff2ea8289
14 changes: 10 additions & 4 deletions InnerEye/ML/configs/classification/CovidModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ class CovidModel(ScalarModelBase):
"""
Model to train a CovidDataset model from scratch or finetune from SSL-pretrained model.

For AML you need to provide the run_id of your SSL training job as a command line argument
--pretraining_run_recovery_id=id_of_your_ssl_model, this will download the checkpoints of the run to your
For AML you need to provide the run_id of your SSL training job as a command line argument:
``--pretraining_run_recovery_id=<id_of_your_ssl_model>``. This will download the checkpoints of the run to your
machine and load the corresponding pretrained model.

To recover from a particular checkpoint from your SSL run e.g. "recovery_epoch=499.ckpt" please use the
--name_of_checkpoint argument.
To recover from a particular checkpoint from your SSL run e.g. ``"recovery_epoch=499.ckpt"`` please use the
``--name_of_checkpoint`` argument.
"""
use_pretrained_model = param.Boolean(default=False, doc="If True, start training from a model pretrained with SSL."
"If False, start training a DenseNet model from scratch"
Expand Down Expand Up @@ -242,6 +242,7 @@ def generate_custom_report(self, report_dir: Path, model_proc: ModelProcessing)
Generate a custom report for the Covid model. This report will read the file model_output.csv generated for
the training, validation or test sets and compute both the multiclass accuracy and the accuracy for each of the
hierarchical tasks.

:param report_dir: Directory report is to be written to
:param model_proc: Whether this is a single or ensemble model (model_output.csv will be located in different
paths for single vs ensemble runs.)
Expand Down Expand Up @@ -364,6 +365,11 @@ def compute_binary_accuracy(model_outputs: pd.Series, labels: pd.Series) -> floa

class DicomPreparation:
def __call__(self, item: torch.Tensor) -> PIL.Image:
"""Call class as a function. This will act as a transformation function for the dataset.

:param item: tensor to transform.
:return: transformed data.
"""
# Item will be of dimension [C, Z, X, Y]
images = item.numpy()
assert images.shape[0] == 1 and images.shape[1] == 1
Expand Down
3 changes: 2 additions & 1 deletion InnerEye/ML/configs/other/fastmri_varnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ def get_fastmri_data_module(azure_dataset_id: str,
Creates a LightningDataModule that consumes data from the FastMRI challenge. The type of challenge
(single/multicoil) is determined from the name of the dataset in Azure blob storage. The mask type is set to
equispaced, with 4x acceleration.

:param azure_dataset_id: The name of the dataset (folder name in blob storage).
:param local_dataset: The local folder at which the dataset has been mounted or downloaded.
:param sample_rate: Fraction of slices of the training data split to use. Set to a value <1.0 for rapid prototyping.
:param test_path: The name of the folder inside the dataset that contains the test data.
:return: A LightningDataModule object.
:return: The FastMRI LightningDataModule object.
"""
if not azure_dataset_id:
raise ValueError("The azure_dataset_id argument must be provided.")
Expand Down
1 change: 1 addition & 0 deletions InnerEye/ML/configs/segmentation/HeadAndNeckBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self,
**kwargs: Any) -> None:
"""
Creates a new instance of the class.

:param ground_truth_ids: List of ground truth ids.
:param ground_truth_ids_display_names: Optional list of ground truth id display names. If
present then must be of the same length as ground_truth_ids.
Expand Down
1 change: 1 addition & 0 deletions InnerEye/ML/configs/segmentation/HelloWorld.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def get_parameter_search_hyperdrive_config(self, run_config: ScriptRunConfig) ->
https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-tune-hyperparameters
A reference is provided at https://docs.microsoft.com/en-us/python/api/azureml-train-core/azureml.train
.hyperdrive?view=azure-ml-py

:param run_config: The configuration for running an individual experiment.
:return: An Azure HyperDrive run configuration (configured PyTorch environment).
"""
Expand Down
1 change: 1 addition & 0 deletions InnerEye/ML/configs/segmentation/ProstatePaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ProstatePaper(ProstateBase):
def __init__(self, **kwargs: Any) -> None:
"""
Creates a new instance of the class.

:param kwargs: Additional arguments that will be passed through to the SegmentationModelBase constructor.
"""
ground_truth_ids = fg_classes
Expand Down
1 change: 1 addition & 0 deletions InnerEye/ML/lightning_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def get_data_module(self) -> LightningDataModule:
Because the method deals with data loaders, not loaded data, we cannot check automatically that cross validation
is handled correctly within the base class, i.e. if the cross validation split is not handled in the method then
nothing will fail, but each child run will be identical since they will each be given the full dataset.

:return: A LightningDataModule
"""
return None # type: ignore
Expand Down
5 changes: 5 additions & 0 deletions InnerEye/ML/model_config_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def get_parameter_search_hyperdrive_config(self, run_config: ScriptRunConfig) ->
Returns a configuration for AzureML Hyperdrive that should be used when running hyperparameter
tuning.
This is an abstract method that each specific model should override.

:param run_config: The AzureML estimator object that runs model training.
:return: A hyperdrive configuration object.
"""
Expand All @@ -66,6 +67,7 @@ def get_model_train_test_dataset_splits(self, dataset_df: pd.DataFrame) -> Datas
"""
Computes the training, validation and test splits for the model, from a dataframe that contains
the full dataset.

:param dataset_df: A dataframe that contains the full dataset that the model is using.
:return: An instance of DatasetSplits with dataframes for training, validation and testing.
"""
Expand All @@ -83,6 +85,7 @@ def create_and_set_torch_datasets(self, for_training: bool = True, for_inference
are False, the derived method *may* still create the corresponding datasets, but should not assume that
the relevant splits (train/test/val) are non-empty. If either or both is True, they *must* create the
corresponding datasets, and should be able to make the assumption.

:param for_training: whether to create the datasets required for training.
:param for_inference: whether to create the datasets required for inference.
"""
Expand All @@ -103,6 +106,8 @@ def get_torch_dataset_for_inference(self, mode: ModelExecutionMode) -> Any:
"""
Returns a torch Dataset for running the model in inference mode, on the given split of the full dataset.
The torch dataset must return data in the format required for running the model in inference mode.

:param mode: The mode of the model, either test, train or val.
:return: A torch Dataset object.
"""
if self._datasets_for_inference is None:
Expand Down
5 changes: 2 additions & 3 deletions InnerEye/ML/scalar_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,16 +542,15 @@ def compute_and_log_metrics(self,
data_split: ModelExecutionMode) -> None:
"""
Computes all the metrics for a given (logits, labels) pair, and writes them to the loggers.

:param logits: The model output before normalization.
:param targets: The expected model outputs.
:param subject_ids: The subject IDs for the present minibatch.
:param is_training: If True, write the metrics as training metrics, otherwise as validation metrics.
:param metrics: A dictionary mapping from names of prediction targets to a list of metric computers,
as returned by create_metric_computers.
:param metrics: A dictionary mapping from names of prediction targets to a list of metric computers, as returned by create_metric_computers.
:param logger: An object of type DataframeLogger which can be be used for logging within this function.
:param current_epoch: Current epoch number.
:param data_split: ModelExecutionMode object indicating if this is the train or validation split.
:return:
"""
per_subject_outputs: List[Tuple[str, str, torch.Tensor, torch.Tensor]] = []
for i, (prediction_target, metric_list) in enumerate(metrics.items()):
Expand Down
10 changes: 10 additions & 0 deletions docs/source/rst/api/ML/configs/classification/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Classification Configs
=============================

COVID Model
-----------

.. autoclass:: InnerEye.ML.configs.classification.CovidModel.CovidModel

.. autoclass:: InnerEye.ML.configs.classification.CovidModel.DicomPreparation
:special-members: __call__
10 changes: 10 additions & 0 deletions docs/source/rst/api/ML/configs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Configurations
==============

.. toctree::

classification/index
regression/index
segmentation/index
ssl/index
other/index
7 changes: 7 additions & 0 deletions docs/source/rst/api/ML/configs/other/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Other configs
==========================

FastMRT Varnet
----------------

.. automodule:: InnerEye.ML.configs.other.fastmri_varnet
7 changes: 7 additions & 0 deletions docs/source/rst/api/ML/configs/regression/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Regression Configs
===================

Dummy Regression
-----------------

.. automodule:: InnerEye.ML.configs.regression.DummyRegression
45 changes: 45 additions & 0 deletions docs/source/rst/api/ML/configs/segmentation/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Segmentation Configs
=====================

Basic Models
------------

.. automodule:: InnerEye.ML.configs.segmentation.BasicModel2Epochs

.. automodule:: InnerEye.ML.configs.segmentation.BasicModel2Epochs1Channel

.. automodule:: InnerEye.ML.configs.segmentation.BasicModel2EpochsMoreData

HelloWorld
------------

.. automodule:: InnerEye.ML.configs.segmentation.HelloWorld

Head and Neck
-------------

.. automodule:: InnerEye.ML.configs.segmentation.HeadAndNeckBase

.. automodule:: InnerEye.ML.configs.segmentation.HeadAndNeckPaper

Prostate
-------------

.. automodule:: InnerEye.ML.configs.segmentation.ProstateBase

.. automodule:: InnerEye.ML.configs.segmentation.ProstatePaper

Hippocampus
------------

.. automodule:: InnerEye.ML.configs.segmentation.Hippocampus

Lung
------------

.. automodule:: InnerEye.ML.configs.segmentation.Lung

Glioblastoma
------------

.. automodule:: InnerEye.ML.configs.segmentation.GbmBase
19 changes: 19 additions & 0 deletions docs/source/rst/api/ML/configs/ssl/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Self-Supervised Learning Configs
================================

CIFAR
-----

.. automodule:: InnerEye.ML.configs.ssl.CIFAR_classifier_configs

.. automodule:: InnerEye.ML.configs.ssl.CIFAR_SSL_configs

COVID
-----

.. automodule:: InnerEye.ML.configs.ssl.CovidContainers

Chest X-Rays
------------

.. automodule:: InnerEye.ML.configs.ssl.CXR_SSL_configs
Empty file.
4 changes: 2 additions & 2 deletions docs/source/rst/api/ML/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Machine learning

.. toctree::

configs
configs/index
augmentations/index
runner
augmentations/index.rst
photometric_normalization
pipelines