Skip to content

wrap repo as installable package #64

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/ci-install-pkg.yml
Original file line number Diff line number Diff line change
@@ -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__)"
24 changes: 24 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -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*
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```
Expand Down
6 changes: 6 additions & 0 deletions med3d/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
Empty file added med3d/datasets/__init__.py
Empty file.
File renamed without changes.
2 changes: 1 addition & 1 deletion model.py → med3d/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch
from torch import nn
from models import resnet
from med3d.models import resnet


def generate_model(opt):
Expand Down
Empty file added med3d/models/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
6 changes: 2 additions & 4 deletions test.py → med3d/test.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
5 changes: 2 additions & 3 deletions train.py → med3d/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Empty file added med3d/utils/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
61 changes: 61 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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',
],
)
2 changes: 0 additions & 2 deletions test_ci.py

This file was deleted.