Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
811b0d7
Improve code quality (#158, #166)
jonasteuwen Jan 10, 2022
43543b5
Adds citation button (#169)
wdika Jan 10, 2022
d874e8d
Update model_zoo.rst
georgeyiasemis Jan 12, 2022
ce060aa
Fix linter errors (#170)
georgeyiasemis Jan 19, 2022
94798c3
Delete README.md
georgeyiasemis Jan 19, 2022
0d21936
Update README.rst
georgeyiasemis Jan 19, 2022
a851dd6
Merged MRI models engine to MRIModelEngine
georgeyiasemis Jan 26, 2022
db27833
Minor fix
georgeyiasemis Jan 26, 2022
7f112c9
Func to get size of objiect
georgeyiasemis Jan 26, 2022
ea86805
- Fix typo
jonasteuwen Jan 27, 2022
4d6956f
- Remove process_output from base class
jonasteuwen Jan 27, 2022
0834a7e
First attempt to rewriting validation process (will not pass CI)
jonasteuwen Jan 27, 2022
5aded01
Rewrite validation process (will not pass CI)
jonasteuwen Jan 27, 2022
0723e7b
Improve validation
jonasteuwen Jan 28, 2022
fe5851d
Improve validation
jonasteuwen Jan 28, 2022
abedab2
Log metric output
jonasteuwen Jan 29, 2022
7c62208
Improve metric log output
jonasteuwen Jan 29, 2022
3e3b7f3
Replace ISMRMD with xml parser
jonasteuwen Jan 29, 2022
7f6a440
Make sure the metric is cloned
jonasteuwen Jan 29, 2022
8fe7471
Refactoring
jonasteuwen Jan 29, 2022
88565bf
Refactoring
jonasteuwen Jan 29, 2022
c951370
Refactoring
jonasteuwen Jan 29, 2022
94c2713
Fix roll test
jonasteuwen Jan 30, 2022
d4d8aba
Remove `is_validation_process`
jonasteuwen Jan 30, 2022
ab82e36
Move ismrmrd dependency to dev dependencies
jonasteuwen Jan 30, 2022
ee2145e
Install extras for tox
jonasteuwen Jan 30, 2022
960529a
Make compatible tests for new updates
georgeyiasemis Feb 2, 2022
5f874f3
Minor fix
georgeyiasemis Feb 2, 2022
ee47f0b
Fix pytest warning
georgeyiasemis Feb 2, 2022
46a0e12
Fix pylint errors
georgeyiasemis Feb 2, 2022
2029b5e
Update black.yml
georgeyiasemis Feb 2, 2022
cf66660
Update black.yml
georgeyiasemis Feb 2, 2022
2585e0e
Update black.yml
georgeyiasemis Feb 2, 2022
67e728b
Black 22.1.0 fixes
georgeyiasemis Feb 2, 2022
d3c4c01
Merge branch 'fix-high-memory-consumption' of github.com:NKI-AI/direc…
georgeyiasemis Feb 2, 2022
b9ebfad
Black 22.1.0 fixes
georgeyiasemis Feb 2, 2022
fcad676
Updated docs, fixed `write_output_to_h5` to work with new predict fun…
georgeyiasemis Feb 2, 2022
f709840
Update `utils`
georgeyiasemis Feb 3, 2022
f555c27
Add test
georgeyiasemis Feb 3, 2022
8cae7e9
Update rim_engine.py
georgeyiasemis Feb 3, 2022
795e071
Minor fix
georgeyiasemis Feb 4, 2022
9794c71
Disable tensorboard warnings
georgeyiasemis Feb 4, 2022
b84f126
Remove whitespace
georgeyiasemis Feb 4, 2022
3ff935d
Update train.py
georgeyiasemis Feb 4, 2022
5855120
Update varnet_engine.py
georgeyiasemis Feb 4, 2022
60508f8
Test engine.train
georgeyiasemis Feb 4, 2022
0667fae
Test engine.train
georgeyiasemis Feb 4, 2022
5331319
Refine test
georgeyiasemis Feb 4, 2022
23f1f11
Fix typo and unused import
georgeyiasemis Feb 4, 2022
6c2f019
Add crop option for inference
georgeyiasemis Feb 4, 2022
8ad9d64
Codacy pseudonumber complains
georgeyiasemis Feb 4, 2022
11e1be5
Update setup.py
georgeyiasemis Feb 6, 2022
b66bdef
Minor documentation fix
georgeyiasemis Feb 9, 2022
0ecf279
Update writers.py
georgeyiasemis Feb 9, 2022
4a48546
Update mri_models.py
georgeyiasemis Feb 9, 2022
fe5a1f9
Edit `set_all_seeds`
georgeyiasemis Feb 9, 2022
4cf9193
Update subsample.py
georgeyiasemis Feb 10, 2022
abd686e
Minor fix
georgeyiasemis Feb 10, 2022
aa8c5fe
Fix/supress codacy warnings
georgeyiasemis Feb 10, 2022
5761b73
Fix/supress codacy warnings
georgeyiasemis Feb 10, 2022
ac68344
Fix/supress codacy warnings
georgeyiasemis Feb 10, 2022
3bf2648
Lazy formatting
georgeyiasemis Feb 10, 2022
8968c55
Lazy formatting
georgeyiasemis Feb 10, 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
2 changes: 1 addition & 1 deletion .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: psf/black@stable
- uses: psf/black@22.1.0
17 changes: 17 additions & 0 deletions .prospector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pep257:
disable:
- D203 # Conflict with numpydocs
- D213 # Conflict with numpydocs
- D212 # Conflict with numpydocs

pep8:
disable:
- E501 # Handled by black
- W605 # Conflict with numpydocs - invalid escape sequence

pylint:
disable:
- import-outside-toplevel
options:
max-args: 20

27 changes: 27 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: Yiasemis
given-names: George
email: g.yiasemis@nki.nl
orcid: https://orcid.org/0000-0002-1348-8987
- family-names: Moriakov
given-names: Nikita
email: n.moriakov@nki.nl
orcid: https://orcid.org/0000-0002-7127-1006
- family-names: Karkalousos
given-names: Dimitrios
email: d.karkalousos@amsterdamumc.nl
orcid: https://orcid.org/0000-0001-5983-0322
- family-names: Caan
given-names: Matthan
email: m.w.a.caan@amsterdamumc.nl
orcid: https://orcid.org/0000-0002-5162-8880
- family-names: Teuwen
given-names: Jonas
email: j.teuwen@nki.nl
orcid: https://orcid.org/0000-0002-1825-1428
title: "DIRECT: Deep Image REConstruction Toolkit"
url: "https://github.com/NKI-AI/direct"
version: 1.0.0
date-released: 2022-07-01
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
:target: https://github.com/NKI-AI/direct/actions/workflows/black.yml
:alt: black

.. image:: https://api.codacy.com/project/badge/Grade/1c55d497dead4df69d6f256da51c98b7
:target: https://app.codacy.com/gh/NKI-AI/direct?utm_source=github.com&utm_medium=referral&utm_content=NKI-AI/direct&utm_campaign=Badge_Grade_Settings
:alt: codacy

.. image:: https://codecov.io/gh/NKI-AI/direct/branch/main/graph/badge.svg?token=STYAUFCKJY
:target: https://codecov.io/gh/NKI-AI/direct
:alt: codecov
Expand Down
10 changes: 10 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
coverage:
range: 50..90 # coverage lower than 50 is red, higher than 90 green, between color code

status:
project: # settings affecting project coverage
default:
target: auto # auto % coverage target
threshold: 1% # allow for 1% reduction of coverage without failing

# do not run coverage on patch nor changes
patch: false
2 changes: 1 addition & 1 deletion direct/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Copyright (c) DIRECT Contributors

__author__ = """direct contributors"""
__version__ = "1.0.0"
__version__ = "1.0.1-dev0"
41 changes: 20 additions & 21 deletions direct/checkpointer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# coding=utf-8
# Copyright (c) DIRECT Contributors
"""Checkpointer module. Handles all logic related to checkpointing."""
"""Checkpointer module.

Handles all logic related to checkpointing.
"""
import datetime
import logging
import pathlib
Expand Down Expand Up @@ -31,7 +34,10 @@


class Checkpointer:
"""Main Checkpointer module. Handles writing and restoring from checkpoints of modules and submodels."""
"""Main Checkpointer module.

Handles writing and restoring from checkpoints of modules and submodules.
"""

def __init__(
self,
Expand Down Expand Up @@ -110,8 +116,7 @@ def load_from_path(
checkpointable_objects: Optional[Dict[str, nn.Module]] = None,
only_models: bool = False,
) -> Dict:
"""
Load a checkpoint from a path
"""Load a checkpoint from a path.

Parameters
----------
Expand All @@ -129,7 +134,6 @@ def load_from_path(
checkpoint = self._load_checkpoint(checkpoint_path)
checkpointable_objects = self.checkpointables if not checkpointable_objects else checkpointable_objects

# TODO: Model and other checkpointable objects should be treated on the same footing
self.logger.info("Loading model...")
self._load_model(self.model, checkpoint["model"])

Expand All @@ -138,17 +142,17 @@ def load_from_path(
continue

if key not in checkpoint:
self.logger.warning(f"Requested to load {key}, but this was not stored.")
self.logger.warning("Requested to load %s, but this was not stored.", key)
continue

if key.endswith("__") and key.startswith("__"):
continue

self.logger.info(f"Loading {key}...")
self.logger.info("Loading %s...", key)
obj = self.checkpointables[key]
state_dict = checkpoint.pop(key)
if re.match(self.model_regex, key):
self.logger.debug(f"key {key} matches regex {self.model_regex}.")
self.logger.debug("key %s matches regex %s.", key, self.model_regex)
self._load_model(obj, state_dict) # type: ignore
else:
obj.load_state_dict(state_dict) # type: ignore
Expand All @@ -162,7 +166,7 @@ def _load_model(self, obj, state_dict):
if incompatible.missing_keys:
raise NotImplementedError
if incompatible.unexpected_keys:
self.logger.warning(f"Unexpected keys provided which cannot be loaded: {incompatible.unexpected_keys}.")
self.logger.warning("Unexpected keys provided which cannot be loaded: %s.", incompatible.unexpected_keys)

def load_models_from_file(self, checkpoint_path: PathOrString) -> None:
_ = self.load_from_path(checkpoint_path, only_models=True)
Expand All @@ -182,12 +186,12 @@ def save(self, iteration: int, **kwargs: Dict[str, str]) -> None:
elif isinstance(obj, get_args(HasStateDict)):
data[key] = obj.state_dict() # type: ignore
else:
self.logger.warning(f"Value of key {key} has no state_dict.")
self.logger.warning("Value of key %s has no state_dict.", key)

data.update(kwargs)

checkpoint_path = self.save_directory / f"model_{iteration}.pt"
self.logger.info(f"Saving checkpoint to: {checkpoint_path}.")
self.logger.info("Saving checkpoint to: %s.", checkpoint_path)

data["__datetime__"] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

Expand All @@ -199,8 +203,7 @@ def save(self, iteration: int, **kwargs: Dict[str, str]) -> None:
f.write(str(iteration)) # type: ignore

def _load_checkpoint(self, checkpoint_path: PathOrString) -> Dict:
"""
Load a checkpoint from path or string
"""Load a checkpoint from path or string.

Parameters
----------
Expand All @@ -212,25 +215,21 @@ def _load_checkpoint(self, checkpoint_path: PathOrString) -> Dict:
"""
# Check if the path is an URL
if check_is_valid_url(str(checkpoint_path)):
self.logger.info(f"Initializing from remote checkpoint {checkpoint_path}...")
self.logger.info("Initializing from remote checkpoint %s...", checkpoint_path)
checkpoint_path = self._download_or_load_from_cache(checkpoint_path)
self.logger.info(f"Loading downloaded checkpoint {checkpoint_path}.")
self.logger.info("Loading downloaded checkpoint %s.", checkpoint_path)

checkpoint_path = pathlib.Path(checkpoint_path)
if not checkpoint_path.exists():
raise FileNotFoundError(f"Requested to load {checkpoint_path}, but does not exist.")

self.logger.info(f"Loaded checkpoint path: {checkpoint_path}.")
self.logger.info("Loaded checkpoint path: %s.", checkpoint_path)

try:
checkpoint = torch.load(checkpoint_path, map_location=torch.device("cpu"))

except UnpicklingError as exc:
self.logger.exception(
f"Tried to load {checkpoint_path}, but was unable to unpickle: {exc}.",
checkpoint_path=checkpoint_path,
exc=exc,
)
self.logger.exception("Tried to load %s, but was unable to unpickle: %s.", checkpoint_path, exc)
raise

return checkpoint
Expand Down
9 changes: 5 additions & 4 deletions direct/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# coding=utf-8
# Copyright (c) DIRECT Contributors
"""DIRECT Command-line interface. This is the file which builds the main parser."""
"""DIRECT Command-line interface.

This is the file which builds the main parser.
"""

import argparse


def main():
"""
Console script for direct.
"""
"""Console script for direct."""
# From https://stackoverflow.com/questions/17073688/how-to-use-argparse-subparsers-correctly
root_parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)

Expand Down
2 changes: 1 addition & 1 deletion direct/cli/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def register_parser(parser: argparse._SubParsersAction):
"""Register wsi commands to a root parser."""

epilog = f"""
epilog = """
Examples:
---------
Run on single machine:
Expand Down
5 changes: 2 additions & 3 deletions direct/cli/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright (c) DIRECT Contributors
import argparse
import os

from direct.cli.utils import is_file
from direct.utils.io import upload_to_s3

Expand All @@ -19,9 +20,7 @@ def upload_from_argparse(args: argparse.Namespace): # pragma: no cover


class BaseArgs(argparse.ArgumentParser): # pragma: no cover
"""
Defines global default arguments.
"""
"""Defines global default arguments."""

def __init__(self, epilog=None, add_help=True, **overrides):
"""
Expand Down
Loading