Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shepp logan phantom #202

Merged
merged 32 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
185a4f5
Add sensitivity map simulator
georgeyiasemis Apr 19, 2022
c7fe150
Add test and minor fix
georgeyiasemis Apr 19, 2022
c7b8453
Minor edits, fake uses simulate_sensitivity_maps now
georgeyiasemis Apr 20, 2022
be3def9
Add Shepp Logan dataset
georgeyiasemis Apr 21, 2022
8acaaa1
Minor fix
georgeyiasemis Apr 21, 2022
3f38442
Add tests
georgeyiasemis Apr 21, 2022
6a5bca3
Add datasets configs, minor SheppLogan datasets changes, and now wo…
georgeyiasemis May 4, 2022
7f82116
Minor test fix
georgeyiasemis May 4, 2022
80f9a51
now doesn't require --data-root arg, edit dataset config attributes …
georgeyiasemis May 4, 2022
45cea32
Minor fix
georgeyiasemis May 4, 2022
a16b9b1
Docs update
georgeyiasemis May 4, 2022
e078276
Update docs to comply with new train/predict changes
georgeyiasemis May 5, 2022
1e77c45
Minor fix
georgeyiasemis May 5, 2022
ef44f8c
Update calgary campinas projects to comply with new train/predict cha…
georgeyiasemis May 5, 2022
2835876
Minor fix
georgeyiasemis May 5, 2022
9b9d3dd
Update SPIE project
georgeyiasemis May 6, 2022
fa3b163
Use inference.crop and inference.batch_size in direct predict
georgeyiasemis May 9, 2022
a51e66d
Update CVPR project
georgeyiasemis May 9, 2022
2d62c79
Black fix
georgeyiasemis May 9, 2022
f58305e
Update calgary campinas readme
georgeyiasemis May 9, 2022
8333840
Toy cfg for shepplogan dataset
georgeyiasemis May 9, 2022
fce0224
Minor fix
georgeyiasemis May 9, 2022
402812a
Add usage example for shepplogan dataset
georgeyiasemis May 9, 2022
b7cec6a
Add usage example for shepplogan dataset
georgeyiasemis May 9, 2022
263351e
codacy fixes
georgeyiasemis May 11, 2022
ce44c71
codacy fixes
georgeyiasemis May 11, 2022
6a1766d
codacy fixes
georgeyiasemis May 11, 2022
85adbd7
Minor fix
georgeyiasemis May 11, 2022
1148afd
Minor fix
georgeyiasemis May 11, 2022
f278334
Minor fix
georgeyiasemis May 11, 2022
8ba3952
Codacy complains
georgeyiasemis May 11, 2022
11d203d
Update datasets.py
georgeyiasemis May 11, 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
21 changes: 14 additions & 7 deletions direct/cli/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ def register_parser(parser: argparse._SubParsersAction):
Examples:
---------
Run on single machine:
$ direct predict <data_root> <output_directory> --cfg <cfg_path_or_url> --checkpoint <checkpoint_path_or_url>
--num-gpus <num_gpus> [--other-flag-args <other_flags>]
$ direct predict <output_directory> --cfg <cfg_path_or_url> --checkpoint <checkpoint_path_or_url> \
--num-gpus <num_gpus> [--data-root <data_root>] [--other-flag-args <other_flags>]

Run on multiple machines:
(machine0)$ direct predict <data_root> <output_directory> --cfg <cfg_path_or_url> --checkpoint
<checkpoint_path_or_url> --machine-rank 0 --num-machines 2 --dist-url <URL> [--other-flag-args <other_flags>]
(machine1)$ direct predict <data_root> <output_directory> --cfg <cfg_path_or_url> --checkpoint
<checkpoint_path_or_url> --machine-rank 1 --num-machines 2 --dist-url <URL> [--other-flag-args <other_flags>]
(machine0)$ direct predict <output_directory> --cfg <cfg_path_or_url> --checkpoint \
<checkpoint_path_or_url> --machine-rank 0 --num-machines 2 [--data-root <data_root>] \
[--dist-url <URL> --other-flag-args <other_flags>]
(machine1)$ direct predict <output_directory> --cfg <cfg_path_or_url> --checkpoint \
<checkpoint_path_or_url> --machine-rank 1 --num-machines 2 [--data-root <data_root>] \
[--dist-url <URL> --other-flag-args <other_flags>]
"""
common_parser = Args(add_help=False)
predict_parser = parser.add_parser(
Expand All @@ -33,8 +35,13 @@ def register_parser(parser: argparse._SubParsersAction):
epilog=epilog,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
predict_parser.add_argument("data_root", type=pathlib.Path, help="Path to the inference data directory.")
predict_parser.add_argument("output_directory", type=pathlib.Path, help="Path to the output directory.")
predict_parser.add_argument(
"--data-root",
type=pathlib.Path,
help="Path to the inference data directory (if required by inference dataset).",
required=False,
)
predict_parser.add_argument(
"--cfg",
dest="cfg_file",
Expand Down
13 changes: 7 additions & 6 deletions direct/cli/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def register_parser(parser: argparse._SubParsersAction):
Examples:
---------
Run on single machine:
$ direct train training_set validation_set experiment_dir --num-gpus 8 --cfg cfg.yaml
$ direct train experiment_dir --num-gpus 8 --cfg cfg.yaml [--training-root training_set --validation-root validation_set]
Run on multiple machines:
(machine0)$ direct train training_set validation_set experiment_dir --machine-rank 0 --num-machines 2 --dist-url <URL> [--other-flags]
(machine1)$ direct train training_set validation_set experiment_dir --machine-rank 1 --num-machines 2 --dist-url <URL> [--other-flags]
(machine0)$ direct train experiment_dir --machine-rank 0 --num-machines 2 --dist-url <URL> [--training-root training_set --validation-root validation_set] [--other-flags]
(machine1)$ direct train experiment_dir --machine-rank 1 --num-machines 2 --dist-url <URL> [--training-root training_set --validation-root validation_set] [--other-flags]
"""
common_parser = Args(add_help=False)
train_parser = parser.add_parser(
Expand All @@ -28,14 +28,15 @@ def register_parser(parser: argparse._SubParsersAction):
epilog=epilog,
formatter_class=argparse.RawDescriptionHelpFormatter,
)

train_parser.add_argument("training_root", type=pathlib.Path, help="Path to the training data.")
train_parser.add_argument("validation_root", type=pathlib.Path, help="Path to the validation data.")
train_parser.add_argument(
"experiment_dir",
type=pathlib.Path,
help="Path to the experiment directory.",
)
train_parser.add_argument("--training-root", type=pathlib.Path, help="Path to the training data.", required=False)
train_parser.add_argument(
"--validation-root", type=pathlib.Path, help="Path to the validation data.", required=False
)
train_parser.add_argument(
"--cfg",
dest="cfg_file",
Expand Down
10 changes: 7 additions & 3 deletions direct/cli/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# coding=utf-8
# Copyright (c) DIRECT Contributors

import argparse
import pathlib
import sys

from direct.types import FileOrUrl, PathOrString
from direct.utils.io import check_is_valid_url


Expand All @@ -14,12 +16,14 @@ def is_file(path):
raise argparse.ArgumentTypeError(f"{path} is not a valid file or url.")


def file_or_url(path):
def file_or_url(path: PathOrString) -> FileOrUrl:
if check_is_valid_url(path):
return path
return FileOrUrl(path)

path = pathlib.Path(path)
if path.is_file():
return path
return FileOrUrl(path)

raise argparse.ArgumentTypeError(f"{path} is not a valid file or url.")


Expand Down
24 changes: 16 additions & 8 deletions direct/common/subsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ def mask_func(self, shape, return_acs=False, seed=None):
The mask selects a subset of columns from the input k-space data. If the k-space data has N
columns, the mask picks out:

#. :math:`N_{\text{low\_freqs}} = (N \times \text{center_fraction})` columns in the center corresponding to low-frequencies. # pylint: disable=line-too-long
#. The other columns are selected uniformly at random with a probability equal to: :math:`\text{prob} = (N / \text{acceleration} - N_{\text{low\_freqs}}) / (N - N_{\text{low\_freqs}})`. This ensures that the expected number of columns selected is equal to (N / acceleration) # pylint: disable=line-too-long
#. :math:`N_{\text{low freqs}} = (N \times \text{center_fraction})` columns in the center corresponding
to low-frequencies.
#. The other columns are selected uniformly at random with a probability equal to:
:math:`\text{prob} = (N / \text{acceleration} - N_{\text{low freqs}}) / (N - N_{\text{low freqs}})`.
This ensures that the expected number of columns selected is equal to (N / acceleration).

It is possible to use multiple center_fractions and accelerations, in which case one possible
(center_fraction, acceleration) is chosen uniformly at random each time the MaskFunc object is
Expand Down Expand Up @@ -204,15 +207,18 @@ def mask_func(self, shape, return_acs=False, seed=None):
FastMRIEquispacedMaskFunc creates a sub-sampling mask of a given shape. The mask selects a subset of columns
from the input k-space data. If the k-space data has N columns, the mask picks out:

#. :math:`N_{\text{low\_freqs}} = (N \times \text{center_fraction})` columns in the center corresponding to low-frequencies. # pylint: disable=line-too-long
#. The other columns are selected with equal spacing at a proportion that reaches the desired acceleration rate taking into consideration the number of low frequencies. This ensures that the expected number of columns selected is equal to :math:`\frac{N}{\text{acceleration}}`. # pylint: disable=line-too-long
#. :math:`N_{\text{low freqs}} = (N \times \text{center_fraction})` columns in the center corresponding
to low-frequencies.
#. The other columns are selected with equal spacing at a proportion that reaches the desired acceleration
rate taking into consideration the number of low frequencies. This ensures that the expected number of
columns selected is equal to :math:`\frac{N}{\text{acceleration}}`.

It is possible to use multiple center_fractions and accelerations, in which case one possible
(center_fraction, acceleration) is chosen uniformly at random each time the EquispacedMaskFunc object is called.

Note that this function may not give equispaced samples (documented in https://github.com/facebookresearch/fastMRI/issues/54),
which will require modifications to standard GRAPPA approaches. Nonetheless, this aspect of the function has
been preserved to match the public multicoil data.
Note that this function may not give equispaced samples (documented in
https://github.com/facebookresearch/fastMRI/issues/54), which will require modifications to standard GRAPPA
approaches. Nonetheless, this aspect of the function has been preserved to match the public multicoil data.

Parameters
----------
Expand Down Expand Up @@ -374,7 +380,9 @@ class CIRCUSMaskFunc(BaseMaskFunc):
References
----------

.. [1] Liu J, Saloner D. Accelerated MRI with CIRcular Cartesian UnderSampling (CIRCUS): a variable density Cartesian sampling strategy for compressed sensing and parallel imaging. Quant Imaging Med Surg. 2014 Feb;4(1):57-67. doi: 10.3978/j.issn.2223-4292.2014.02.01. PMID: 24649436; PMCID: PMC3947985.
.. [1] Liu J, Saloner D. Accelerated MRI with CIRcular Cartesian UnderSampling (CIRCUS): a variable density
Cartesian sampling strategy for compressed sensing and parallel imaging. Quant Imaging Med Surg.
2014 Feb;4(1):57-67. doi: 10.3978/j.issn.2223-4292.2014.02.01. PMID: 24649436; PMCID: PMC3947985.
"""

def __init__(
Expand Down
Loading