andreped commited on
Commit
6faad95
1 Parent(s): 46b1a17

Moved chainer imports inside functions [no ci]

Browse files
livermask/utils/process.py CHANGED
@@ -13,14 +13,11 @@ import argparse
13
  import pkg_resources
14
  import tensorflow as tf
15
  import logging as log
16
- import chainer
17
  import math
18
- from .unet3d import UNet3D
19
  from .yaml_utils import Config
20
  import yaml
21
  from tensorflow.keras import backend as K
22
  from numba import cuda
23
- from .utils import load_vessel_model
24
  import multiprocessing as mp
25
 
26
 
@@ -139,6 +136,11 @@ def liver_segmenter(params):
139
 
140
 
141
  def vessel_segmenter(curr, output, cpu, verbose, multiple_flag, liver_mask, name_vessel, extension):
 
 
 
 
 
142
  # check if cupy is available, if not, set cpu=True
143
  try:
144
  import cupy
@@ -157,7 +159,6 @@ def vessel_segmenter(curr, output, cpu, verbose, multiple_flag, liver_mask, name
157
  nib_volume = nib.load(curr)
158
  new_spacing = [1., 1., 1.]
159
  resampled_volume = resample_to_output(nib_volume, new_spacing, order=1)
160
- # resampled_volume = nib_volume
161
  org = resampled_volume.get_data().astype('float32')
162
 
163
  # HU clipping
 
13
  import pkg_resources
14
  import tensorflow as tf
15
  import logging as log
 
16
  import math
 
17
  from .yaml_utils import Config
18
  import yaml
19
  from tensorflow.keras import backend as K
20
  from numba import cuda
 
21
  import multiprocessing as mp
22
 
23
 
 
136
 
137
 
138
  def vessel_segmenter(curr, output, cpu, verbose, multiple_flag, liver_mask, name_vessel, extension):
139
+ # only import chainer stuff inside here, to avoid unnecessary imports
140
+ import chainer
141
+ from .unet3d import UNet3D
142
+ from .utils import load_vessel_model
143
+
144
  # check if cupy is available, if not, set cpu=True
145
  try:
146
  import cupy
 
159
  nib_volume = nib.load(curr)
160
  new_spacing = [1., 1., 1.]
161
  resampled_volume = resample_to_output(nib_volume, new_spacing, order=1)
 
162
  org = resampled_volume.get_data().astype('float32')
163
 
164
  # HU clipping
livermask/utils/utils.py CHANGED
@@ -1,6 +1,5 @@
1
  import gdown
2
  import logging as log
3
- import chainer
4
  from .unet3d import UNet3D
5
  from .fetch import download
6
  import os
@@ -29,6 +28,7 @@ def get_vessel_model(output):
29
 
30
 
31
  def load_vessel_model(path, cpu):
 
32
  unet = UNet3D(num_of_label=2)
33
  chainer.serializers.load_npz(path, unet)
34
  if not cpu:
 
1
  import gdown
2
  import logging as log
 
3
  from .unet3d import UNet3D
4
  from .fetch import download
5
  import os
 
28
 
29
 
30
  def load_vessel_model(path, cpu):
31
+ import chainer
32
  unet = UNet3D(num_of_label=2)
33
  chainer.serializers.load_npz(path, unet)
34
  if not cpu: