diff --git a/.github/workflows/ci-install-pkg.yml b/.github/workflows/ci-install-pkg.yml new file mode 100644 index 0000000..931dc07 --- /dev/null +++ b/.github/workflows/ci-install-pkg.yml @@ -0,0 +1,56 @@ +name: Install package + +# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows +on: # Trigger the workflow on push or pull request, but only for the main branch + push: + branches: [master] + pull_request: {} + +jobs: + pkg-check: + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@master + - uses: actions/setup-python@v2 + with: + python-version: 3.7 + + - name: Check package + run: | + pip install check-manifest + check-manifest + python setup.py check --metadata --strict + + - name: Create package + run: | + pip install --upgrade setuptools wheel + python setup.py sdist bdist_wheel + + - name: Verify package + run: | + pip install twine==3.2 + twine check dist/* + + pkg-install: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-20.04] + python-version: [3.7] + + steps: + - uses: actions/checkout@master + - uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Create package + run: | + python setup.py sdist + + - name: Install package + run: | + pip install dist/* + cd .. & python -c "import med3d ; print(med3d.__version__)" diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..205ce24 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,24 @@ +# Manifest syntax https://docs.python.org/2/distutils/sourcedist.html +graft wheelhouse + +recursive-exclude __pycache__ *.py[cod] *.orig + +# Include the README and CHANGELOG +include *.md + +# Include the license file +include LICENSE + +# Include the Requirements +include requirements.txt + +exclude *.yml +recursive-include images *.gif *.png +recursive-include toy_data *.gz *.txt + +prune .git +prune .github +prune notebook* +prune temp* +prune test* +prune docs* diff --git a/README.md b/README.md index d02ea02..5945fde 100644 --- a/README.md +++ b/README.md @@ -97,12 +97,17 @@ We transferred the above pre-trained models to the multi-class segmentation task ``` MedicalNet is used to transfer the pre-trained model to other datasets (here the MRBrainS18 dataset is used as an example). MedicalNet/ - |--datasets/:Data preprocessing module - | |--brains18.py:MRBrainS18 data preprocessing script - | |--models/:Model construction module - | |--resnet.py:3D-ResNet network build script - |--utils/:tools - | |--logger.py:Logging script + |--med3d + | |--datasets/:Data preprocessing module + | | |--brains18.py:MRBrainS18 data preprocessing script + | |--models/:Model construction module + | | |--resnet.py:3D-ResNet network build script + | |--utils/:tools + | | |--logger.py:Logging script + | |--model.py: Network processing script + | |--setting.py: Parameter setting script + | |--train.py: MRBrainS18 training demo script + | |--test.py: MRBrainS18 testing demo script |--toy_data/:For CI test |--data/:Data storage module | |--MRBrainS18/:MRBrainS18 dataset @@ -111,10 +116,6 @@ MedicalNet/ | |--train.txt: training data lists | |--val.txt: validation data lists |--pretrain/:Pre-trained models storage module - |--model.py: Network processing script - |--setting.py: Parameter setting script - |--train.py: MRBrainS18 training demo script - |--test.py: MRBrainS18 testing demo script |--requirement.txt: Dependent library list |--README.md ``` diff --git a/med3d/__init__.py b/med3d/__init__.py new file mode 100644 index 0000000..0b99ef2 --- /dev/null +++ b/med3d/__init__.py @@ -0,0 +1,6 @@ +__version__ = "0.1.0" +__docs__ = "MedicalNet 3D" +__author__ = "Sihong Chen" +__author_email__ = "TBD" +__homepage__ = "https://github.com/Tencent/MedicalNet" +__license__ = "MIT" \ No newline at end of file diff --git a/med3d/datasets/__init__.py b/med3d/datasets/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/datasets/brains18.py b/med3d/datasets/brains18.py similarity index 100% rename from datasets/brains18.py rename to med3d/datasets/brains18.py diff --git a/model.py b/med3d/model.py similarity index 99% rename from model.py rename to med3d/model.py index 258e6a2..97282e3 100644 --- a/model.py +++ b/med3d/model.py @@ -1,6 +1,6 @@ import torch from torch import nn -from models import resnet +from med3d.models import resnet def generate_model(opt): diff --git a/med3d/models/__init__.py b/med3d/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/models/resnet.py b/med3d/models/resnet.py similarity index 100% rename from models/resnet.py rename to med3d/models/resnet.py diff --git a/setting.py b/med3d/setting.py similarity index 100% rename from setting.py rename to med3d/setting.py diff --git a/test.py b/med3d/test.py similarity index 96% rename from test.py rename to med3d/test.py index dc93f50..03f3074 100644 --- a/test.py +++ b/med3d/test.py @@ -1,15 +1,13 @@ from setting import parse_opts -from datasets.brains18 import BrainS18Dataset +from med3d.datasets.brains18 import BrainS18Dataset from model import generate_model import torch -import numpy as np from torch.utils.data import DataLoader import torch.nn.functional as F from scipy import ndimage import nibabel as nib -import sys import os -from utils.file_process import load_lines +from med3d.utils.file_process import load_lines import numpy as np diff --git a/train.py b/med3d/train.py similarity index 98% rename from train.py rename to med3d/train.py index 89dd924..deea97a 100644 --- a/train.py +++ b/med3d/train.py @@ -4,16 +4,15 @@ ''' from setting import parse_opts -from datasets.brains18 import BrainS18Dataset +from med3d.datasets.brains18 import BrainS18Dataset from model import generate_model import torch import numpy as np from torch import nn from torch import optim -from torch.optim import lr_scheduler from torch.utils.data import DataLoader import time -from utils.logger import log +from med3d.utils.logger import log from scipy import ndimage import os diff --git a/med3d/utils/__init__.py b/med3d/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/utils/file_process.py b/med3d/utils/file_process.py similarity index 100% rename from utils/file_process.py rename to med3d/utils/file_process.py diff --git a/utils/logger.py b/med3d/utils/logger.py similarity index 100% rename from utils/logger.py rename to med3d/utils/logger.py diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..0af89c6 --- /dev/null +++ b/setup.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python + +import os + +# Always prefer setuptools over distutils +from setuptools import find_packages, setup + +# https://packaging.python.org/guides/single-sourcing-package-version/ +# http://blog.ionelmc.ro/2014/05/25/python-packaging/ +import med3d + +_PATH_ROOT = os.path.dirname(__file__) + + +def _load_requirements(path_dir=_PATH_ROOT, comment_char='#'): + with open(os.path.join(path_dir, 'requirements.txt')) as file: + lines = [ln.strip() for ln in file.readlines()] + reqs = [ln[:ln.index(comment_char)] if comment_char in ln else ln for ln in lines] + return reqs + + +# https://packaging.python.org/discussions/install-requires-vs-requirements / +# keep the meta-data here for simplicity in reading this file... it's not obvious +# what happens and to non-engineers they won't know to look in init ... +# the goal of the project is simplicity for researchers, don't want to add too much +# engineer specific practices +setup( + name='MedicalNet', + version=med3d.__version__, + description=med3d.__docs__, + author=med3d.__author__, + author_email=med3d.__author_email__, + url=med3d.__homepage__, + license=med3d.__license__, + packages=find_packages(exclude=['tests', 'docs']), + long_description_content_type='text/markdown', + include_package_data=True, + zip_safe=False, + keywords=['deep learning', 'pytorch', 'AI'], + python_requires='>=3.6', + setup_requires=[], + install_requires=_load_requirements(_PATH_ROOT), + classifiers=[ + 'Environment :: Console', + 'Natural Language :: English', + # How mature is this project? Common values are + # 3 - Alpha, 4 - Beta, 5 - Production/Stable + 'Development Status :: 3 - Alpha', + # Indicate who your project is intended for + 'Intended Audience :: Developers', + 'Topic :: Scientific/Engineering :: Artificial Intelligence', + 'Topic :: Scientific/Engineering :: Image Recognition', + 'Topic :: Scientific/Engineering :: Information Analysis', + # Pick your license as you wish + # 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + # Specify the Python versions you support here. In particular, ensure + # that you indicate whether you support Python 2, Python 3 or both. + 'Programming Language :: Python :: 3', + ], +) diff --git a/test_ci.py b/test_ci.py deleted file mode 100644 index 098f4cc..0000000 --- a/test_ci.py +++ /dev/null @@ -1,2 +0,0 @@ -if __name__ == "__main__": - print("test successful!") \ No newline at end of file