andreped commited on
Commit
2abae3a
1 Parent(s): d21da4f

added GPU support and bumped tensorflow to v2.4

Browse files
Files changed (4) hide show
  1. .gitignore +2 -0
  2. livermask/livermask.py +29 -8
  3. requirements.txt +0 -0
  4. setup.py +4 -10
.gitignore CHANGED
@@ -2,3 +2,5 @@ venv/
2
  build/
3
  dist/
4
  livermask.egg-info/
 
 
 
2
  build/
3
  dist/
4
  livermask.egg-info/
5
+ *.h5
6
+ *.nii
livermask/livermask.py CHANGED
@@ -1,6 +1,5 @@
1
  import numpy as np
2
  import os, sys
3
- import h5py
4
  from tqdm import tqdm
5
  import nibabel as nib
6
  from nibabel.processing import resample_to_output, resample_from_to
@@ -12,6 +11,11 @@ from skimage.measure import label, regionprops
12
  import warnings
13
  import argparse
14
  import pkg_resources
 
 
 
 
 
15
 
16
 
17
  # mute some warnings
@@ -40,7 +44,7 @@ def get_model():
40
  md5 = "ef5a6dfb794b39bea03f5496a9a49d4d"
41
  gdown.cached_download(url, output, md5=md5) #, postprocess=gdown.extractall)
42
 
43
- def func(path, output):
44
 
45
  cwd = "/".join(os.path.realpath(__file__).replace("\\", "/").split("/")[:-1]) + "/"
46
 
@@ -122,20 +126,37 @@ def func(path, output):
122
 
123
 
124
  def main():
125
- # os.environ["CUDA_VISIBLE_DEVICES"] = "-1" # disable GPU
126
- version = pkg_resources.require("livermask")[0].version
127
-
128
  parser = argparse.ArgumentParser()
129
  parser.add_argument('--input', metavar='--i', type=str, nargs='?',
130
  help="set path of which image to use.")
131
  parser.add_argument('--output', metavar='--o', type=str, nargs='?',
132
  help="set path to store the output.")
133
- parser.add_argument('--cpu', metavar='--o', action='store_true',
134
  help="force using the CPU even if a GPU is available.")
135
- parser.add_argument('--version', metavar='--v',
136
- help='shows the current version of livermask.', version=version)
137
  ret = parser.parse_args(sys.argv[1:]); print(ret)
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  # fix paths
140
  ret.input = ret.input.replace("\\", "/")
141
  ret.output = ret.output.replace("\\", "/")
 
1
  import numpy as np
2
  import os, sys
 
3
  from tqdm import tqdm
4
  import nibabel as nib
5
  from nibabel.processing import resample_to_output, resample_from_to
 
11
  import warnings
12
  import argparse
13
  import pkg_resources
14
+ import tensorflow as tf
15
+
16
+
17
+ # due to this: https://github.com/tensorflow/tensorflow/issues/35029
18
+ os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'
19
 
20
 
21
  # mute some warnings
 
44
  md5 = "ef5a6dfb794b39bea03f5496a9a49d4d"
45
  gdown.cached_download(url, output, md5=md5) #, postprocess=gdown.extractall)
46
 
47
+ def func(path, output, cpu):
48
 
49
  cwd = "/".join(os.path.realpath(__file__).replace("\\", "/").split("/")[:-1]) + "/"
50
 
 
126
 
127
 
128
  def main():
 
 
 
129
  parser = argparse.ArgumentParser()
130
  parser.add_argument('--input', metavar='--i', type=str, nargs='?',
131
  help="set path of which image to use.")
132
  parser.add_argument('--output', metavar='--o', type=str, nargs='?',
133
  help="set path to store the output.")
134
+ parser.add_argument('--cpu', action='store_true',
135
  help="force using the CPU even if a GPU is available.")
 
 
136
  ret = parser.parse_args(sys.argv[1:]); print(ret)
137
 
138
+ if ret.cpu:
139
+ os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
140
+ if not tf.test.is_gpu_available():
141
+ tf.config.set_visible_devices([], 'GPU')
142
+ visible_devices = tf.config.get_visible_devices()
143
+ else:
144
+ gpus = tf.config.experimental.list_physical_devices('GPU')
145
+ try:
146
+ # Currently, memory growth needs to be the same across GPUs
147
+ for gpu in gpus:
148
+ tf.config.experimental.set_memory_growth(gpu, enable=True)
149
+ logical_gpus = tf.config.experimental.list_logical_devices('GPU')
150
+ print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
151
+ except RuntimeError as e:
152
+ # Memory growth must be set before GPUs have been initialized
153
+ print(e)
154
+
155
+ if not ret.input.endswith(".nii"):
156
+ raise ValueError("Image provided is not in the supported '.nii' format.")
157
+ if not ret.output.endswith(".nii"):
158
+ raise ValueError("Output name set is not in the supported '.nii' format.")
159
+
160
  # fix paths
161
  ret.input = ret.input.replace("\\", "/")
162
  ret.output = ret.output.replace("\\", "/")
requirements.txt CHANGED
Binary files a/requirements.txt and b/requirements.txt differ
 
setup.py CHANGED
@@ -3,6 +3,9 @@ import setuptools
3
  with open("README.md", "r") as f:
4
  long_description = f.read()
5
 
 
 
 
6
  setuptools.setup(
7
  name='livermask',
8
  version='1.0.0',
@@ -19,16 +22,7 @@ setuptools.setup(
19
  'livermask = livermask.livermask:main'
20
  ]
21
  },
22
- install_requires=[
23
- 'numpy'
24
- 'tensorflow==2.6',
25
- 'scipy',
26
- 'tqdm',
27
- 'nibabel',
28
- 'h5py',
29
- 'gdown',
30
- 'scikit-image'
31
- ],
32
  classifiers=[
33
  "Programming Language :: Python :: 3",
34
  "License :: OSI Approved :: MIT License",
 
3
  with open("README.md", "r") as f:
4
  long_description = f.read()
5
 
6
+ with open('misc/requirements_torch.txt', 'r', encoding='utf-16') as ff:
7
+ required = ff.read().splitlines()
8
+
9
  setuptools.setup(
10
  name='livermask',
11
  version='1.0.0',
 
22
  'livermask = livermask.livermask:main'
23
  ]
24
  },
25
+ install_requires=required,
 
 
 
 
 
 
 
 
 
26
  classifiers=[
27
  "Programming Language :: Python :: 3",
28
  "License :: OSI Approved :: MIT License",