Skip to content

Commit f75618b

Browse files
authored
Merge pull request #8 from andreped/workflow
Workflows to produce binaries
2 parents e9cc27a + a481adc commit f75618b

File tree

5 files changed

+94
-27
lines changed

5 files changed

+94
-27
lines changed

.github/workflows/CI-build.yaml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Build and upload wheels
2+
3+
on:
4+
push:
5+
branches:
6+
- '*'
7+
pull_request:
8+
branches:
9+
- '*'
10+
11+
jobs:
12+
build:
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
os: [windows-2019, ubuntu-18.04, macos-10.15]
17+
python-version: [3.6, 3.7, 3.8, 3.9]
18+
19+
steps:
20+
- uses: actions/checkout@v1
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v2
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
26+
- name: Install dependencies
27+
run: |
28+
pip install wheel setuptools
29+
pip install -r requirements.txt
30+
31+
- name: Build wheel
32+
run: python setup.py bdist_wheel
33+
34+
- name: Install software
35+
run: pip install --find-links=${{github.workspace}}/dist/ SimpleCRF
36+
37+
- name: Test import
38+
run: python -c "import denseCRF, maxflow"
39+
40+
- name: Install deps for demos
41+
run: pip install SimpleITK pillow matplotlib
42+
43+
- name: Test maxflow demo
44+
run: cd ${{github.workspace}}/examples && python demo_maxflow.py 0
45+
46+
- name: Test denseCRF demo
47+
run: cd ${{github.workspace}}/examples && python demo_densecrf.py 1
48+
49+
- name: Test denseCRF 3D demo
50+
run: cd ${{github.workspace}}/examples && python demo_densecrf.py 1
51+
52+
- name: Upload Python wheel
53+
uses: actions/upload-artifact@v2
54+
with:
55+
name: Python wheel
56+
path: ${{github.workspace}}/dist/SimpleCRF-*.whl
57+
if-no-files-found: error

examples/demo_densecrf.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import numpy as np
33
from PIL import Image
44
import matplotlib.pyplot as plt
5+
import sys
56

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

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

107110
if __name__ == "__main__":
108111
print("example list")
109112
print(" 0 -- Dense CRF example for a binary segmentation")
110113
print(" 1 -- Dense CRF example for a multi-class segmentation")
111-
print("please enter the index of an example:")
112-
method = input()
113-
method = "{0:}".format(method)
114+
if len(sys.argv) == 1:
115+
raise ValueError("Please, provide an argument.")
116+
method = sys.argv[1]
114117
if(method == '0'):
115118
demo_densecrf1()
116119
elif(method == '1'):
117120
demo_densecrf2()
118121
else:
119-
print("invalid number : {0:}".format(method))
122+
raise ValueError("Invalid number: " + method)

examples/demo_densecrf3d.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numpy as np
44
from PIL import Image
55
import matplotlib.pyplot as plt
6+
import sys
67

78
def densecrf3d(I, P, param):
89
"""
@@ -91,14 +92,12 @@ def demo_densecrf3d_2():
9192
print("example list")
9293
print(" 0 -- 3D Dense CRF example for single-modal segmentation")
9394
print(" 1 -- 3D Dense CRF example for multi-modal segmentation")
94-
print("please enter the index of an example:")
95-
method = input()
96-
method = "{0:}".format(method)
95+
if len(sys.argv) == 1:
96+
raise ValueError("Please, provide an argument.")
97+
method = sys.argv[1]
9798
if(method == '0'):
9899
demo_densecrf3d_1()
99100
elif(method == '1'):
100101
demo_densecrf3d_2()
101102
else:
102-
print("invalid number : {0:}".format(method))
103-
104-
103+
raise ValueError("Invalid number: " + method)

examples/demo_maxflow.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
21
import numpy as np
32
import SimpleITK as sitk
43
import maxflow
54
from PIL import Image
65
import matplotlib.pyplot as plt
6+
import sys
77

88
def maxflow2d(I, P, param):
99
"""
@@ -96,10 +96,11 @@ def demo_maxflow():
9696
param = (lamda, sigma)
9797
lab = maxflow2d(Iq, Prob, param)
9898

99+
fig = plt.figure()
99100
plt.subplot(1,3,1); plt.axis('off'); plt.imshow(I); plt.title('input image')
100101
plt.subplot(1,3,2); plt.axis('off'); plt.imshow(fP); plt.title('initial \n segmentation')
101102
plt.subplot(1,3,3); plt.axis('off'); plt.imshow(lab); plt.title('CRF result')
102-
plt.show()
103+
fig.savefig('./demo_result.png')
103104

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

125+
fig = plt.figure()
124126
plt.subplot(1,3,1); plt.axis('off'); plt.imshow(I); plt.title('input image')
125127
plt.subplot(1,3,2); plt.axis('off'); plt.imshow(fP); plt.title('initial \n segmentation')
126128
plt.subplot(1,3,3); plt.axis('off'); plt.imshow(lab); plt.title('CRF result')
127-
plt.show()
129+
fig.savefig('./demo_result.png')
128130

129131
def demo_maxflow3d():
130132
img_name = "../data/2013_12_1_img.nii.gz"
@@ -188,9 +190,9 @@ def test_interactive_max_flow3d():
188190
print(" 1 -- 2D max flow with interactions")
189191
print(" 2 -- 3D max flow without interactions")
190192
print(" 3 -- 3D max flow with interactions")
191-
print("please enter the index of an example:")
192-
method = input()
193-
method = "{0:}".format(method)
193+
if len(sys.argv) == 1:
194+
raise ValueError("Please, provide an argument.")
195+
method = sys.argv[1]
194196
if(method == '0'):
195197
demo_maxflow()
196198
elif(method == '1'):
@@ -200,4 +202,4 @@ def test_interactive_max_flow3d():
200202
elif(method == '3'):
201203
test_interactive_max_flow3d()
202204
else:
203-
print("invalid number : {0:}".format(method))
205+
raise ValueError("Invalid number: " + method)

setup.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def finalize_options(self):
2525
'maxflow_python/util.cpp',
2626
'dependency/maxflow-v3.0/graph.cpp',
2727
'dependency/maxflow-v3.0/maxflow.cpp',
28-
maxflow_source])
28+
maxflow_source],
29+
py_limited_api=False)
2930

3031
module_name2 = 'denseCRF'
3132
densecrf_source = "densecrf_python/wrap2D_py{0:}.cpp".format(py_version)
@@ -45,7 +46,8 @@ def finalize_options(self):
4546
'./dependency/densecrf/src/util.cpp',
4647
'./dependency/densecrf/external/liblbfgs/lib/lbfgs.c',
4748
densecrf_source,
48-
])
49+
],
50+
py_limited_api=False)
4951

5052
module_name3 = 'denseCRF3D'
5153
densecrf_source = "densecrf_python/wrap3D_py{0:}.cpp".format(py_version)
@@ -65,13 +67,14 @@ def finalize_options(self):
6567
'./dependency/densecrf3d/src/util.cpp',
6668
'./dependency/densecrf/external/liblbfgs/lib/lbfgs.c',
6769
densecrf_source,
68-
])
70+
],
71+
py_limited_api=False)
6972

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

7376
# Get the long description
74-
if(sys.version[0] == '2'):
77+
if (sys.version[0] == '2'):
7578
import io
7679
with io.open('README.md', 'r', encoding='utf-8') as f:
7780
long_description = f.read()
@@ -92,13 +95,16 @@ def finalize_options(self):
9295
ext_modules = [module1, module2, module3],
9396
classifiers=[
9497
'License :: OSI Approved :: BSD License',
95-
'Programming Language :: Python',
96-
'Programming Language :: Python :: 2',
97-
'Programming Language :: Python :: 3',
98+
'Programming Language :: Python :: 3 :: Only',
99+
'Programming Language :: Python :: 3.6',
100+
'Programming Language :: Python :: 3.7',
101+
'Programming Language :: Python :: 3.8',
102+
'Programming Language :: Python :: 3.9',
103+
'Programming Language :: Python :: 3.10',
98104
],
99105
python_requires = '>=3.6',
100106
cmdclass={'build_ext': build_ext},)
101107

102108

103-
# to build, run python stup.py build or python setup.py build_ext --inplace
109+
# to build, run python setup.py build or python setup.py build_ext --inplace
104110
# to install, run python setup.py install

0 commit comments

Comments
 (0)