Spaces:
Running
Running
Vemund Fredriksen
commited on
Commit
·
4719ce5
1
Parent(s):
0d8deb6
Implement as command line tool
Browse files- lungtumormask/__main__.py +20 -0
- lungtumormask/dataprocessing.py +1 -2
- setup.py +6 -1
lungtumormask/__main__.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
8 |
+
return string
|
9 |
+
else:
|
10 |
+
sys.exit(f'File not found: {string}')
|
11 |
+
|
12 |
+
def main():
|
13 |
+
parser = argparse.ArgumentParser()
|
14 |
+
parser.add_argument('input', metavar='input', type=path, help='Path to the input image, should be .nifti')
|
15 |
+
parser.add_argument('output', metavar='output', type=str, help='Filepath for output tumormask')
|
16 |
+
|
17 |
+
argsin = sys.argv[1:]
|
18 |
+
args = parser.parse_args(argsin)
|
19 |
+
|
20 |
+
mask.mask(args.input, args.output)
|
lungtumormask/dataprocessing.py
CHANGED
@@ -5,7 +5,6 @@ from monai.transforms.intensity.array import ThresholdIntensity
|
|
5 |
from monai.transforms.spatial.array import Resize, Spacing
|
6 |
from monai.transforms.utility.dictionary import ToTensord
|
7 |
import torch
|
8 |
-
from tqdm import tqdm
|
9 |
import numpy as np
|
10 |
from monai.transforms import (Compose, LoadImaged, ToNumpyd, ThresholdIntensityd, AddChanneld, NormalizeIntensityd, SpatialCropd, DivisiblePadd, Spacingd, SqueezeDimd)
|
11 |
|
@@ -39,7 +38,7 @@ def mask_lung(scan_path, batch_size=20):
|
|
39 |
timage_res = np.empty((np.append(0, tvolslices[0].shape)), dtype=np.uint8)
|
40 |
|
41 |
with torch.no_grad():
|
42 |
-
for X in
|
43 |
X = X.float().to(device)
|
44 |
prediction = model(X)
|
45 |
pls = torch.max(prediction, 1)[1].detach().cpu().numpy().astype(np.uint8)
|
|
|
5 |
from monai.transforms.spatial.array import Resize, Spacing
|
6 |
from monai.transforms.utility.dictionary import ToTensord
|
7 |
import torch
|
|
|
8 |
import numpy as np
|
9 |
from monai.transforms import (Compose, LoadImaged, ToNumpyd, ThresholdIntensityd, AddChanneld, NormalizeIntensityd, SpatialCropd, DivisiblePadd, Spacingd, SqueezeDimd)
|
10 |
|
|
|
38 |
timage_res = np.empty((np.append(0, tvolslices[0].shape)), dtype=np.uint8)
|
39 |
|
40 |
with torch.no_grad():
|
41 |
+
for X in dataloader_val:
|
42 |
X = X.float().to(device)
|
43 |
prediction = model(X)
|
44 |
pls = torch.max(prediction, 1)[1].detach().cpu().numpy().astype(np.uint8)
|
setup.py
CHANGED
@@ -7,5 +7,10 @@ setup(
|
|
7 |
author="Svein Ole M Sevle, Vemund Fredriksen",
|
8 |
url="https://github.com/VemundFredriksen/LungTumorMask",
|
9 |
license="MIT",
|
10 |
-
python_requires='>=3.6'
|
|
|
|
|
|
|
|
|
|
|
11 |
)
|
|
|
7 |
author="Svein Ole M Sevle, Vemund Fredriksen",
|
8 |
url="https://github.com/VemundFredriksen/LungTumorMask",
|
9 |
license="MIT",
|
10 |
+
python_requires='>=3.6',
|
11 |
+
entry_points={
|
12 |
+
'console_scripts': [
|
13 |
+
'lungtumormask = lungtumormask.__main__:main'
|
14 |
+
]
|
15 |
+
}
|
16 |
)
|