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

merge master #3

Merged
merged 19 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Ignore the following files/folders during docker build

__pycache__/
docs/

.coverage
.readthedocs.yml
*.md
*.toml

!README.md

3 changes: 2 additions & 1 deletion .github/workflows/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ jobs:
cron-docker:
if: github.repository == 'Project-MONAI/MONAI'
container:
image: docker://projectmonai/monai:latest
image: localhost:5000/local_monai:dockerhub # use currently latest, locally available dockerhub image
options: "--gpus all"
runs-on: [self-hosted, linux, x64, common]
steps:
- name: Run tests report coverage
# The docker image process has done the compilation. BUILD_MONAI=1 may not be necessary.
run: |
cd /opt/monai
nvidia-smi
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/setupapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,17 @@ jobs:
ref: master
- name: docker_build
run: |
# build and run original docker image for local registry
docker build -t localhost:5000/local_monai:latest -f Dockerfile .
docker push localhost:5000/local_monai:latest
# build once more w/ tag "latest": remove flake package as it is not needed on hub.docker.com
sed -i '/flake/d' requirements-dev.txt
docker build -t projectmonai/monai:latest -f Dockerfile .
docker login -u projectmonai -p ${{ secrets.DOCKER_PW }}
# also push as tag "dockerhub" to local registry
docker image tag projectmonai/monai:latest localhost:5000/local_monai:dockerhub
docker push localhost:5000/local_monai:dockerhub
# distribute as always w/ tag "latest" to hub.docker.com
echo "${{ secrets.DOCKER_PW }}" | docker login -u projectmonai --password-stdin
docker push projectmonai/monai:latest
docker logout

Expand Down
11 changes: 10 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ _Pull request early_

We encourage you to create pull requests early. It helps us track the contributions under development, whether they are ready to be merged or not. Change your pull request's title to begin with `[WIP]` until it is ready for formal review.

Please note that, as per PyTorch, MONAI uses American English spelling. This means classes and variables should be: normali**z**e, visuali**z**e, colo~~u~~r, etc.

### Preparing pull requests
To ensure the code quality, MONAI relies on several linting tools ([flake8 and its plugins](https://gitlab.com/pycqa/flake8), [black](https://github.com/psf/black), [isort](https://github.com/timothycrosley/isort)),
static type analysis tools ([mypy](https://github.com/python/mypy), [pytype](https://github.com/google/pytype)), as well as a set of unit/integration tests.
Expand All @@ -58,7 +60,7 @@ pip install -U -r requirements-dev.txt # install the latest tools

License information: all source code files should start with this paragraph:
```
# Copyright 2020 MONAI Consortium
# Copyright 2020 - 2021 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand All @@ -71,6 +73,13 @@ License information: all source code files should start with this paragraph:

```

##### Exporting modules

If you intend for any variables/functions/classes to be available outside of the file with the edited functionality, then:

- Create or append to the `__all__` variable (in the file in which functionality has been added), and
- Add to the `__init__.py` file.

#### Unit testing
MONAI tests are located under `tests/`.

Expand Down
22 changes: 17 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 MONAI Consortium
# Copyright 2020 - 2021 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand All @@ -11,10 +11,11 @@

ARG PYTORCH_IMAGE=nvcr.io/nvidia/pytorch:20.10-py3

FROM ${PYTORCH_IMAGE} as base
FROM ${PYTORCH_IMAGE}

MAINTAINER MONAI Consortium <monai.miccai2019@gmail.com>

WORKDIR /opt/monai
ENV PATH=/opt/tools:$PATH

# install full deps
COPY requirements.txt requirements-min.txt requirements-dev.txt /tmp/
Expand All @@ -23,13 +24,24 @@ RUN cp /tmp/requirements.txt /tmp/req.bak \
&& python -m pip install --no-cache-dir --use-feature=2020-resolver -r /tmp/requirements-dev.txt

# compile ext and remove temp files
COPY . .
# TODO: remark for issue [revise the dockerfile #1276](https://github.com/Project-MONAI/MONAI/issues/1276)
# please specify exact files and folders to be copied -- else, basically always, the Docker build process cannot cache
# this or anything below it and always will build from at most here; one file change leads to no caching from here on...

COPY LICENSE setup.py setup.cfg versioneer.py runtests.sh .gitignore .gitattributes README.md MANIFEST.in ./
COPY tests ./tests
COPY monai ./monai
COPY .git ./.git
RUN BUILD_MONAI=1 FORCE_CUDA=1 python setup.py develop \
&& rm -rf build __pycache__

# NGC Client
WORKDIR /opt/tools
RUN wget -q https://ngc.nvidia.com/downloads/ngccli_cat_linux.zip && \
ARG NGC_CLI_URI="https://ngc.nvidia.com/downloads/ngccli_cat_linux.zip"
RUN wget -q ${NGC_CLI_URI} && \
unzip ngccli_cat_linux.zip && chmod u+x ngc && \
md5sum -c ngc.md5 && \
rm -rf ngccli_cat_linux.zip ngc.md5
# append /opt/tools to runtime path for NGC CLI to be accessible from all file system locations
ENV PATH=${PATH}:/opt/tools
WORKDIR /opt/monai
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# -- Project information -----------------------------------------------------
project = "MONAI"
copyright = "2020 MONAI Consortium"
copyright = "2020 - 2021 MONAI Consortium"
author = "MONAI Contributors"

# The full version, including alpha/beta/rc tags
Expand Down
18 changes: 18 additions & 0 deletions docs/source/losses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ Segmentation Losses
.. autoclass:: generalized_wasserstein_dice
:members:

`DiceCELoss`
~~~~~~~~~~~~
.. autoclass:: DiceCELoss
:members:

`FocalLoss`
~~~~~~~~~~~
.. autoclass:: FocalLoss
Expand All @@ -52,3 +57,16 @@ Segmentation Losses
~~~~~~~~~~~~~
.. autoclass:: TverskyLoss
:members:

Registration Losses
-------------------

`BendingEnergyLoss`
~~~~~~~~~~~~~~~~~~~
.. autoclass:: BendingEnergyLoss
:members:

`LocalNormalizedCrossCorrelationLoss`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. autoclass:: LocalNormalizedCrossCorrelationLoss
:members:
4 changes: 0 additions & 4 deletions docs/source/metrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,3 @@ Metrics

.. autoclass:: SurfaceDistanceMetric
:members:

`Occlusion sensitivity`
-----------------------
.. autofunction:: compute_occlusion_sensitivity
5 changes: 5 additions & 0 deletions docs/source/networks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ Layers
~~~~~~~~~~~~~~~~
.. autoclass:: GaussianFilter
:members:

`BilateralFilter`
~~~~~~~~~~~~~~~~~
.. autoclass:: BilateralFilter
:members:

`HilbertTransform`
~~~~~~~~~~~~~~~~~~
Expand Down
8 changes: 7 additions & 1 deletion docs/source/visualize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ Class activation map
--------------------

.. automodule:: monai.visualize.class_activation_maps
:members:
:members:

Occlusion sensitivity
---------------------

.. automodule:: monai.visualize.occlusion_sensitivity
:members:
4 changes: 2 additions & 2 deletions monai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 MONAI Consortium
# Copyright 2020 - 2021 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand All @@ -22,7 +22,7 @@
__revision_id__ = version_dict.get("full-revisionid", None)
del get_versions, version_dict

__copyright__ = "(c) 2020 MONAI Consortium"
__copyright__ = "(c) 2020 - 2021 MONAI Consortium"

__basedir__ = os.path.dirname(__file__)

Expand Down
6 changes: 3 additions & 3 deletions monai/apps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 MONAI Consortium
# Copyright 2020 - 2021 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand All @@ -9,5 +9,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .datasets import *
from .utils import *
from .datasets import CrossValidation, DecathlonDataset, MedNISTDataset
from .utils import check_hash, download_and_extract, download_url, extractall
2 changes: 1 addition & 1 deletion monai/apps/datasets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 MONAI Consortium
# Copyright 2020 - 2021 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down
2 changes: 1 addition & 1 deletion monai/apps/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 MONAI Consortium
# Copyright 2020 - 2021 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down
14 changes: 11 additions & 3 deletions monai/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 MONAI Consortium
# Copyright 2020 - 2021 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand All @@ -9,5 +9,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .deviceconfig import *
from .type_definitions import *
from .deviceconfig import (
USE_COMPILED,
get_gpu_info,
get_system_info,
print_config,
print_debug_info,
print_gpu_info,
print_system_info,
)
from .type_definitions import IndexSelection, KeysCollection
12 changes: 11 additions & 1 deletion monai/config/deviceconfig.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 MONAI Consortium
# Copyright 2020 - 2021 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -38,6 +38,16 @@
psutil, has_psutil = optional_import("psutil")
psutil_version = psutil.__version__ if has_psutil else "NOT INSTALLED or UNKNOWN VERSION."

__all__ = [
"print_config",
"get_system_info",
"print_system_info",
"get_gpu_info",
"print_gpu_info",
"print_debug_info",
"USE_COMPILED",
]


def get_config_values():
"""
Expand Down
4 changes: 3 additions & 1 deletion monai/config/type_definitions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 MONAI Consortium
# Copyright 2020 - 2021 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand All @@ -11,6 +11,8 @@

from typing import Collection, Hashable, Iterable, Union

__all__ = ["KeysCollection", "IndexSelection"]

"""Commonly used concepts
This module provides naming and type specifications for commonly used concepts
within the MONAI package. The intent is to explicitly identify information
Expand Down
7 changes: 6 additions & 1 deletion monai/csrc/ext.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 MONAI Consortium
Copyright 2020 - 2021 MONAI Consortium
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -12,11 +12,16 @@ limitations under the License.
*/

#include <torch/extension.h>

#include "filtering/filtering.h"
#include "lltm/lltm.h"
#include "resample/pushpull.h"
#include "utils/resample_utils.h"

PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
// filtering
m.def("bilateral_filter", &BilateralFilter, "Bilateral Filter");

// lltm
m.def("lltm_forward", &lltm_forward, "LLTM forward");
m.def("lltm_backward", &lltm_backward, "LLTM backward");
Expand Down
42 changes: 42 additions & 0 deletions monai/csrc/filtering/bilateral/bilateral.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2020 - 2021 MONAI Consortium
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#pragma once

#include <torch/extension.h>
#include "utils/common_utils.h"

torch::Tensor BilateralFilterCpu(torch::Tensor input, float spatial_sigma, float color_sigma);
torch::Tensor BilateralFilterPHLCpu(torch::Tensor input, float spatial_sigma, float color_sigma);

#ifdef WITH_CUDA
torch::Tensor BilateralFilterCuda(torch::Tensor input, float spatial_sigma, float color_sigma);
torch::Tensor BilateralFilterPHLCuda(torch::Tensor input, float spatial_sigma, float color_sigma);
#endif

torch::Tensor BilateralFilter(torch::Tensor input, float spatial_sigma, float color_sigma, bool usePHL) {
torch::Tensor (*filterFunction)(torch::Tensor, float, float);

#ifdef WITH_CUDA
if (torch::cuda::is_available() && input.is_cuda()) {
CHECK_CONTIGUOUS_CUDA(input);
filterFunction = usePHL ? &BilateralFilterPHLCuda : &BilateralFilterCuda;
} else {
filterFunction = usePHL ? &BilateralFilterPHLCpu : &BilateralFilterCpu;
}
#else
filterFunction = usePHL ? &BilateralFilterPHLCpu : &BilateralFilterCpu;
#endif

return filterFunction(input, spatial_sigma, color_sigma);
}
Loading