Spaces:
Sleeping
Sleeping
Merge pull request #18 from andreped/lungmask-fix
Browse filesFixed lungmask filtering + set batch size through args + bump v1.2.1 [no ci]
- .github/workflows/build.yml +1 -1
- .gitignore +2 -0
- lungtumormask/__main__.py +7 -3
- lungtumormask/dataprocessing.py +3 -3
- lungtumormask/mask.py +2 -2
- setup.py +1 -1
.github/workflows/build.yml
CHANGED
@@ -68,4 +68,4 @@ jobs:
|
|
68 |
run: lungtumormask --help
|
69 |
|
70 |
- name: Test inference
|
71 |
-
run: lungtumormask samples/lung_001.nii.gz mask_001.nii.gz --threshold 0.3 --lung-filter --radius 3
|
|
|
68 |
run: lungtumormask --help
|
69 |
|
70 |
- name: Test inference
|
71 |
+
run: lungtumormask samples/lung_001.nii.gz mask_001.nii.gz --threshold 0.3 --lung-filter --radius 3 --batch-size 8
|
.gitignore
CHANGED
@@ -3,3 +3,5 @@
|
|
3 |
*.nii.gz
|
4 |
*__pycache__/
|
5 |
*.egg-info
|
|
|
|
|
|
3 |
*.nii.gz
|
4 |
*__pycache__/
|
5 |
*.egg-info
|
6 |
+
dist/
|
7 |
+
build/
|
lungtumormask/__main__.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import sys
|
2 |
import argparse
|
3 |
import os
|
4 |
-
from lungtumormask import mask
|
5 |
|
6 |
def path(string):
|
7 |
if os.path.exists(string):
|
@@ -18,8 +17,13 @@ def main():
|
|
18 |
help='which threshold to use for assigning voxel-wise classes.')
|
19 |
parser.add_argument('--radius', metavar='radius', type=int, default=1,
|
20 |
help='which radius to use for morphological post-processing segmentation smoothing.')
|
|
|
|
|
21 |
|
22 |
argsin = sys.argv[1:]
|
23 |
args = parser.parse_args(argsin)
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
1 |
import sys
|
2 |
import argparse
|
3 |
import os
|
|
|
4 |
|
5 |
def path(string):
|
6 |
if os.path.exists(string):
|
|
|
17 |
help='which threshold to use for assigning voxel-wise classes.')
|
18 |
parser.add_argument('--radius', metavar='radius', type=int, default=1,
|
19 |
help='which radius to use for morphological post-processing segmentation smoothing.')
|
20 |
+
parser.add_argument('--batch-size', metavar='batch-size', type=int, default=5,
|
21 |
+
help='which batch size to use for lungmask inference.')
|
22 |
|
23 |
argsin = sys.argv[1:]
|
24 |
args = parser.parse_args(argsin)
|
25 |
+
|
26 |
+
# import method here to enable faster testing
|
27 |
+
from lungtumormask import mask
|
28 |
+
|
29 |
+
mask.mask(args.input, args.output, args.lung_filter, args.threshold, args.radius, args.batch_size)
|
lungtumormask/dataprocessing.py
CHANGED
@@ -126,7 +126,7 @@ def process_lung_scan(scan_dict, extremes):
|
|
126 |
|
127 |
return normalized_image, affine
|
128 |
|
129 |
-
def preprocess(image_path):
|
130 |
preprocess_dump = {}
|
131 |
|
132 |
scan_dict = {
|
@@ -139,8 +139,8 @@ def preprocess(image_path):
|
|
139 |
preprocess_dump['org_affine'] = im['image_meta_dict']['affine']
|
140 |
|
141 |
print("Segmenting lungs...")
|
142 |
-
masked_lungs = mask_lung(image_path,
|
143 |
-
preprocess_dump['lungmask'] = masked_lungs
|
144 |
right_lung_extreme = calculate_extremes(masked_lungs[0], 1)
|
145 |
preprocess_dump['right_extremes'] = right_lung_extreme
|
146 |
right_lung_processed = process_lung_scan(scan_dict, right_lung_extreme)
|
|
|
126 |
|
127 |
return normalized_image, affine
|
128 |
|
129 |
+
def preprocess(image_path, batch_size):
|
130 |
preprocess_dump = {}
|
131 |
|
132 |
scan_dict = {
|
|
|
139 |
preprocess_dump['org_affine'] = im['image_meta_dict']['affine']
|
140 |
|
141 |
print("Segmenting lungs...")
|
142 |
+
masked_lungs = mask_lung(image_path, batch_size=batch_size)
|
143 |
+
preprocess_dump['lungmask'] = masked_lungs[0] # first output is binary segmentation of lungs
|
144 |
right_lung_extreme = calculate_extremes(masked_lungs[0], 1)
|
145 |
preprocess_dump['right_extremes'] = right_lung_extreme
|
146 |
right_lung_processed = process_lung_scan(scan_dict, right_lung_extreme)
|
lungtumormask/mask.py
CHANGED
@@ -15,12 +15,12 @@ def load_model():
|
|
15 |
model.eval()
|
16 |
return model
|
17 |
|
18 |
-
def mask(image_path, save_path, lung_filter, threshold, radius):
|
19 |
print("Loading model...")
|
20 |
model = load_model()
|
21 |
|
22 |
print("Preprocessing image...")
|
23 |
-
preprocess_dump = preprocess(image_path)
|
24 |
|
25 |
print("Looking for tumors...")
|
26 |
left = model(preprocess_dump['left_lung']).squeeze(0).squeeze(0).detach().numpy()
|
|
|
15 |
model.eval()
|
16 |
return model
|
17 |
|
18 |
+
def mask(image_path, save_path, lung_filter, threshold, radius, batch_size):
|
19 |
print("Loading model...")
|
20 |
model = load_model()
|
21 |
|
22 |
print("Preprocessing image...")
|
23 |
+
preprocess_dump = preprocess(image_path, batch_size)
|
24 |
|
25 |
print("Looking for tumors...")
|
26 |
left = model(preprocess_dump['left_lung']).squeeze(0).squeeze(0).detach().numpy()
|
setup.py
CHANGED
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
|
|
3 |
setup(
|
4 |
name="lungtumormask",
|
5 |
packages=find_packages(),
|
6 |
-
version='1.2.
|
7 |
author="Svein Ole M Sevle, Vemund Fredriksen, and André Pedersen",
|
8 |
url="https://github.com/VemundFredriksen/LungTumorMask",
|
9 |
license="MIT",
|
|
|
3 |
setup(
|
4 |
name="lungtumormask",
|
5 |
packages=find_packages(),
|
6 |
+
version='1.2.1',
|
7 |
author="Svein Ole M Sevle, Vemund Fredriksen, and André Pedersen",
|
8 |
url="https://github.com/VemundFredriksen/LungTumorMask",
|
9 |
license="MIT",
|