Enabled to disable multiprocessing for inference + disabled mp for app
Browse files- demo/app.py +1 -1
- livermask/utils/process.py +10 -7
- livermask/utils/run.py +2 -2
demo/app.py
CHANGED
@@ -29,7 +29,7 @@ def nifti_to_glb(path):
|
|
29 |
def run_model(input_path):
|
30 |
from livermask.utils.run import run_analysis
|
31 |
|
32 |
-
run_analysis(cpu=True, extension='.nii', path=input_path, output='prediction', verbose=True, vessels=False, name="./model.h5")
|
33 |
|
34 |
#cmd_docker = ["python3", "-m", "livermask.livermask", "--input", input_path, "--output", "prediction", "--verbose"]
|
35 |
#sp.check_call(cmd_docker, shell=True) # @FIXME: shell=True here is not optimal -> starts a shell after calling script
|
|
|
29 |
def run_model(input_path):
|
30 |
from livermask.utils.run import run_analysis
|
31 |
|
32 |
+
run_analysis(cpu=True, extension='.nii', path=input_path, output='prediction', verbose=True, vessels=False, name="./model.h5", mp_enabled=False)
|
33 |
|
34 |
#cmd_docker = ["python3", "-m", "livermask.livermask", "--input", input_path, "--output", "prediction", "--verbose"]
|
35 |
#sp.check_call(cmd_docker, shell=True) # @FIXME: shell=True here is not optimal -> starts a shell after calling script
|
livermask/utils/process.py
CHANGED
@@ -37,13 +37,16 @@ def intensity_normalization(volume, intensity_clipping_range):
|
|
37 |
return result
|
38 |
|
39 |
|
40 |
-
def liver_segmenter_wrapper(curr, output, cpu, verbose, multiple_flag, name, extension):
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
47 |
return ret
|
48 |
|
49 |
|
|
|
37 |
return result
|
38 |
|
39 |
|
40 |
+
def liver_segmenter_wrapper(curr, output, cpu, verbose, multiple_flag, name, extension, mp_enabled=True):
|
41 |
+
if mp_enabled:
|
42 |
+
# run inference in a different process
|
43 |
+
mp.set_start_method('spawn', force=True)
|
44 |
+
with mp.Pool(processes=1, maxtasksperchild=1) as p: # , initializer=initializer)
|
45 |
+
result = p.map_async(liver_segmenter, ((curr, output, cpu, verbose, multiple_flag, name, extension),))
|
46 |
+
log.info("getting result from process...")
|
47 |
+
ret = result.get()[0]
|
48 |
+
else:
|
49 |
+
ret = liver_segmenter(params=(curr, output, cpu, verbose, multiple_flag, name, extension))
|
50 |
return ret
|
51 |
|
52 |
|
livermask/utils/run.py
CHANGED
@@ -24,7 +24,7 @@ import logging as log
|
|
24 |
from .utils import get_model, get_vessel_model
|
25 |
|
26 |
|
27 |
-
def run_analysis(path, output, cpu, verbose, vessels, extension, name=None, name_vessel=None):
|
28 |
# fix paths (necessary if called as a package and not CLI)
|
29 |
path = path.replace("\\", "/")
|
30 |
output = output.replace("\\", "/")
|
@@ -74,7 +74,7 @@ def run_analysis(path, output, cpu, verbose, vessels, extension, name=None, name
|
|
74 |
# check if current file is a nifti file, if not, skip
|
75 |
if curr.endswith(".nii") or curr.endswith(".nii.gz"):
|
76 |
# perform liver parenchyma segmentation, launch it in separate process to properly clear memory
|
77 |
-
pred = liver_segmenter_wrapper(curr, output, cpu, verbose, multiple_flag, name, extension)
|
78 |
|
79 |
if vessels:
|
80 |
# perform liver vessel segmentation
|
|
|
24 |
from .utils import get_model, get_vessel_model
|
25 |
|
26 |
|
27 |
+
def run_analysis(path, output, cpu, verbose, vessels, extension, name=None, name_vessel=None, mp_enabled=True):
|
28 |
# fix paths (necessary if called as a package and not CLI)
|
29 |
path = path.replace("\\", "/")
|
30 |
output = output.replace("\\", "/")
|
|
|
74 |
# check if current file is a nifti file, if not, skip
|
75 |
if curr.endswith(".nii") or curr.endswith(".nii.gz"):
|
76 |
# perform liver parenchyma segmentation, launch it in separate process to properly clear memory
|
77 |
+
pred = liver_segmenter_wrapper(curr, output, cpu, verbose, multiple_flag, name, extension, mp_enabled)
|
78 |
|
79 |
if vessels:
|
80 |
# perform liver vessel segmentation
|