Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
608ec83
added gitignore file
andreped Feb 1, 2022
0afe5ad
added initial build file
andreped Feb 1, 2022
a357837
accept all branches for push and PR
andreped Feb 1, 2022
c62de3f
forgot numpy dependency
andreped Feb 1, 2022
2445d81
forgot '-r'
andreped Feb 1, 2022
6f65307
removed ls prompt
andreped Feb 1, 2022
fcafd3d
build works. Install from wheel instead
andreped Feb 1, 2022
18fec3c
wildcard have to be handled differently on windows. Added potential fix
andreped Feb 1, 2022
ba2671a
Build works for all OSs. Added demo tests in the build
andreped Feb 1, 2022
a2f1efb
Added install of deps for maxflow demo, and disabled the two other de…
andreped Feb 1, 2022
701108b
modified maxflow example to use argv instead
andreped Feb 1, 2022
0ee36d9
added argv to demo run in build
andreped Feb 1, 2022
eadf106
used 'cd' before running program
andreped Feb 1, 2022
12733a0
maxflow script successfully runs on the cloud. Added more tests using…
andreped Feb 1, 2022
c046824
off by one
andreped Feb 1, 2022
001d529
build works - at least on ubuntu. Added the same argv solution for th…
andreped Feb 1, 2022
e1fe454
simple test to see how G-A works with matrix
andreped Feb 1, 2022
a7da841
typo
andreped Feb 1, 2022
c6a5567
strategy matrix needed
andreped Feb 1, 2022
4e863a9
windows and macos seems to hang after successive runs? Tried only run…
andreped Feb 1, 2022
0a2c972
removed demo as demos dont work on the cloud for different reasons
andreped Feb 1, 2022
1ec80e6
build any python 3.x
andreped Feb 1, 2022
1473d30
added import test
andreped Feb 1, 2022
e48b283
added python limited api to have forward compatibility
andreped Feb 1, 2022
64ed8c0
build for python 3.6 (with abi3)
andreped Feb 1, 2022
a3b83fc
separate build workflows for each OS
andreped Feb 1, 2022
08ed3b3
OS dependent name for each build
andreped Feb 1, 2022
38bb1d8
added remaining abi3 stuff
andreped Feb 1, 2022
1e99d25
removed gitignore file
andreped Feb 1, 2022
45f37bb
try uninstalling SimpleCRF before installing through wheel
andreped Feb 1, 2022
d923ef8
removed abi3 stuff that did not seem to work. Added builds for specif…
andreped Feb 1, 2022
816bb6b
fix for python 3.10
andreped Feb 1, 2022
ceb0842
removed config file as no longer needed as abi3 solution didnt work
andreped Feb 1, 2022
8d36948
added unit test for windows
andreped Feb 1, 2022
5b6d9c8
skip test for python 3
andreped Feb 1, 2022
2896a25
fixed if statement
andreped Feb 1, 2022
8c6415e
another typo
andreped Feb 1, 2022
48846b8
removed py3.10 for now
andreped Feb 1, 2022
545eb02
typo
andreped Feb 1, 2022
fe313ae
added demo tests again for all OSs, and temporarily removed build for…
andreped Feb 1, 2022
d01f100
swapped plt.show with plt.savefig
andreped Feb 1, 2022
77dce9e
all three demos are now run for each build, but only for python 3.10 …
andreped Feb 1, 2022
4de3ffd
removed redundant step and did some refactoring
andreped Feb 1, 2022
c44eda1
wrong argv
andreped Feb 1, 2022
a481adc
one build to rule them all
andreped Feb 1, 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
57 changes: 57 additions & 0 deletions .github/workflows/CI-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Build and upload wheels

on:
push:
branches:
- '*'
pull_request:
branches:
- '*'

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-2019, ubuntu-18.04, macos-10.15]
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip install wheel setuptools
pip install -r requirements.txt

- name: Build wheel
run: python setup.py bdist_wheel

- name: Install software
run: pip install --find-links=${{github.workspace}}/dist/ SimpleCRF

- name: Test import
run: python -c "import denseCRF, maxflow"

- name: Install deps for demos
run: pip install SimpleITK pillow matplotlib

- name: Test maxflow demo
run: cd ${{github.workspace}}/examples && python demo_maxflow.py 0

- name: Test denseCRF demo
run: cd ${{github.workspace}}/examples && python demo_densecrf.py 1

- name: Test denseCRF 3D demo
run: cd ${{github.workspace}}/examples && python demo_densecrf.py 1

- name: Upload Python wheel
uses: actions/upload-artifact@v2
with:
name: Python wheel
path: ${{github.workspace}}/dist/SimpleCRF-*.whl
if-no-files-found: error
15 changes: 9 additions & 6 deletions examples/demo_densecrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
import sys

def densecrf(I, P, param):
"""
Expand Down Expand Up @@ -72,10 +73,11 @@ def demo_densecrf1():
param = (w1, alpha, beta, w2, gamma, it)
lab = densecrf(Iq, prob, param)
lab = Image.fromarray(lab*255)
fig = plt.figure()
plt.subplot(1,3,1); plt.axis('off'); plt.imshow(I); plt.title('input image')
plt.subplot(1,3,2); plt.axis('off'); plt.imshow(L); plt.title('initial label')
plt.subplot(1,3,3); plt.axis('off'); plt.imshow(lab); plt.title('after dense CRF')
plt.show()
fig.savefig('./demo_result.png')

def demo_densecrf2():
I = Image.open('../dependency/densecrf/examples/im3.ppm')
Expand All @@ -99,21 +101,22 @@ def demo_densecrf2():
lab = densecrf(Iq, prob, param)
lab = colorize_label_map(lab, color_list)
lab = Image.fromarray(lab)
fig = plt.figure()
plt.subplot(1,3,1); plt.axis('off'); plt.imshow(I); plt.title('input image')
plt.subplot(1,3,2); plt.axis('off'); plt.imshow(L); plt.title('initial label')
plt.subplot(1,3,3); plt.axis('off'); plt.imshow(lab); plt.title('after dense CRF')
plt.show()
fig.savefig('./demo_result.png')

if __name__ == "__main__":
print("example list")
print(" 0 -- Dense CRF example for a binary segmentation")
print(" 1 -- Dense CRF example for a multi-class segmentation")
print("please enter the index of an example:")
method = input()
method = "{0:}".format(method)
if len(sys.argv) == 1:
raise ValueError("Please, provide an argument.")
method = sys.argv[1]
if(method == '0'):
demo_densecrf1()
elif(method == '1'):
demo_densecrf2()
else:
print("invalid number : {0:}".format(method))
raise ValueError("Invalid number: " + method)
11 changes: 5 additions & 6 deletions examples/demo_densecrf3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
import sys

def densecrf3d(I, P, param):
"""
Expand Down Expand Up @@ -91,14 +92,12 @@ def demo_densecrf3d_2():
print("example list")
print(" 0 -- 3D Dense CRF example for single-modal segmentation")
print(" 1 -- 3D Dense CRF example for multi-modal segmentation")
print("please enter the index of an example:")
method = input()
method = "{0:}".format(method)
if len(sys.argv) == 1:
raise ValueError("Please, provide an argument.")
method = sys.argv[1]
if(method == '0'):
demo_densecrf3d_1()
elif(method == '1'):
demo_densecrf3d_2()
else:
print("invalid number : {0:}".format(method))


raise ValueError("Invalid number: " + method)
16 changes: 9 additions & 7 deletions examples/demo_maxflow.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

import numpy as np
import SimpleITK as sitk
import maxflow
from PIL import Image
import matplotlib.pyplot as plt
import sys

def maxflow2d(I, P, param):
"""
Expand Down Expand Up @@ -96,10 +96,11 @@ def demo_maxflow():
param = (lamda, sigma)
lab = maxflow2d(Iq, Prob, param)

fig = plt.figure()
plt.subplot(1,3,1); plt.axis('off'); plt.imshow(I); plt.title('input image')
plt.subplot(1,3,2); plt.axis('off'); plt.imshow(fP); plt.title('initial \n segmentation')
plt.subplot(1,3,3); plt.axis('off'); plt.imshow(lab); plt.title('CRF result')
plt.show()
fig.savefig('./demo_result.png')

def demo_interactive_maxflow():
I = Image.open('../data/brain.png')
Expand All @@ -121,10 +122,11 @@ def demo_interactive_maxflow():
param = (lamda, sigma)
lab = interactive_maxflow2d(Iq, Prob, Seed, param)

fig = plt.figure()
plt.subplot(1,3,1); plt.axis('off'); plt.imshow(I); plt.title('input image')
plt.subplot(1,3,2); plt.axis('off'); plt.imshow(fP); plt.title('initial \n segmentation')
plt.subplot(1,3,3); plt.axis('off'); plt.imshow(lab); plt.title('CRF result')
plt.show()
fig.savefig('./demo_result.png')

def demo_maxflow3d():
img_name = "../data/2013_12_1_img.nii.gz"
Expand Down Expand Up @@ -188,9 +190,9 @@ def test_interactive_max_flow3d():
print(" 1 -- 2D max flow with interactions")
print(" 2 -- 3D max flow without interactions")
print(" 3 -- 3D max flow with interactions")
print("please enter the index of an example:")
method = input()
method = "{0:}".format(method)
if len(sys.argv) == 1:
raise ValueError("Please, provide an argument.")
method = sys.argv[1]
if(method == '0'):
demo_maxflow()
elif(method == '1'):
Expand All @@ -200,4 +202,4 @@ def test_interactive_max_flow3d():
elif(method == '3'):
test_interactive_max_flow3d()
else:
print("invalid number : {0:}".format(method))
raise ValueError("Invalid number: " + method)
22 changes: 14 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def finalize_options(self):
'maxflow_python/util.cpp',
'dependency/maxflow-v3.0/graph.cpp',
'dependency/maxflow-v3.0/maxflow.cpp',
maxflow_source])
maxflow_source],
py_limited_api=False)

module_name2 = 'denseCRF'
densecrf_source = "densecrf_python/wrap2D_py{0:}.cpp".format(py_version)
Expand All @@ -45,7 +46,8 @@ def finalize_options(self):
'./dependency/densecrf/src/util.cpp',
'./dependency/densecrf/external/liblbfgs/lib/lbfgs.c',
densecrf_source,
])
],
py_limited_api=False)

module_name3 = 'denseCRF3D'
densecrf_source = "densecrf_python/wrap3D_py{0:}.cpp".format(py_version)
Expand All @@ -65,13 +67,14 @@ def finalize_options(self):
'./dependency/densecrf3d/src/util.cpp',
'./dependency/densecrf/external/liblbfgs/lib/lbfgs.c',
densecrf_source,
])
],
py_limited_api=False)

# Get the summary
description = 'An open-source toolkit for conditional random field (CRF) and dense CRF'

# Get the long description
if(sys.version[0] == '2'):
if (sys.version[0] == '2'):
import io
with io.open('README.md', 'r', encoding='utf-8') as f:
long_description = f.read()
Expand All @@ -92,13 +95,16 @@ def finalize_options(self):
ext_modules = [module1, module2, module3],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you increase the version to the next version, say 0.2.1.2?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it is necessary to make a new patch release, as no real changes to the library itself were made. The binaries should be identical to if you were to install this yourself (or at least that was the goal). If you want to make a new patch release, I gues you can do so, if you'd like, but I don't see it is as a necessity for this PR. But up to you :]

classifiers=[
'License :: OSI Approved :: BSD License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know Python 2 is deprecated, but unsure if anyone is using it still. I hope it is safe to remove python 2 from build here for this version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are numerous dependencies here which do not support Python 2. Today, most libraries only support Python >= 3.6.

Python 2 is also no longer developed or maintained, so I would certaintly remove support for it in 2022. However, there might be some that still use older versions of Python 3. Up to you and the SimpleCRF team if this is something you want.

'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
],
python_requires = '>=3.6',
cmdclass={'build_ext': build_ext},)


# to build, run python stup.py build or python setup.py build_ext --inplace
# to build, run python setup.py build or python setup.py build_ext --inplace
# to install, run python setup.py install