andreped commited on
Commit
95addbb
1 Parent(s): 9b6cb7b

improved download logic to catch incomplete downloads

Browse files
Files changed (1) hide show
  1. livermask/utils/utils.py +14 -1
livermask/utils/utils.py CHANGED
@@ -3,11 +3,24 @@ import logging as log
3
  import chainer
4
  from .unet3d import UNet3D
5
  from .fetch import download
 
 
6
 
7
 
8
  def get_model(output):
9
  url = "https://github.com/andreped/livermask/releases/download/trained-models-v1/model.h5"
10
- download(url, output)
 
 
 
 
 
 
 
 
 
 
 
11
 
12
 
13
  def get_vessel_model(output):
 
3
  import chainer
4
  from .unet3d import UNet3D
5
  from .fetch import download
6
+ import os
7
+ from tensorflow.python.keras.models import load_model
8
 
9
 
10
  def get_model(output):
11
  url = "https://github.com/andreped/livermask/releases/download/trained-models-v1/model.h5"
12
+
13
+ if os.path.exists(output):
14
+ try:
15
+ model = load_model(output, compile=False)
16
+ del model
17
+ except OSError as e:
18
+ print(e)
19
+ print("Model failed to load. Trying to delete old model and redownload. This might take a while...")
20
+ os.remove(output)
21
+ download(url, output)
22
+ else:
23
+ download(url, output)
24
 
25
 
26
  def get_vessel_model(output):