andreped commited on
Commit
9b6cb7b
1 Parent(s): 23437a1

added github release download for parenchyma model

Browse files
livermask/utils/fetch.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ from datetime import datetime
4
+ from email.utils import parsedate_to_datetime, formatdate
5
+
6
+
7
+ # taken from: https://lenon.dev/blog/downloading-and-caching-large-files-using-python/
8
+ def download(url, destination_file):
9
+ headers = {}
10
+
11
+ if os.path.exists(destination_file):
12
+ mtime = os.path.getmtime(destination_file)
13
+ headers["if-modified-since"] = formatdate(mtime, usegmt=True)
14
+
15
+ response = requests.get(url, headers=headers, stream=True)
16
+ response.raise_for_status()
17
+
18
+ if response.status_code == requests.codes.not_modified:
19
+ return
20
+
21
+ if response.status_code == requests.codes.ok:
22
+ with open(destination_file, "wb") as f:
23
+ for chunk in response.iter_content(chunk_size=1048576):
24
+ f.write(chunk)
25
+
26
+ last_modified = response.headers.get("last-modified")
27
+ if last_modified:
28
+ new_mtime = parsedate_to_datetime(last_modified).timestamp()
29
+ os.utime(destination_file, times=(datetime.now().timestamp(), new_mtime))
livermask/utils/utils.py CHANGED
@@ -2,11 +2,12 @@ import gdown
2
  import logging as log
3
  import chainer
4
  from .unet3d import UNet3D
 
5
 
6
 
7
  def get_model(output):
8
- url = "https://drive.google.com/uc?id=12or5Q79at2BtLgQ7IaglNGPFGRlEgEHc"
9
- gdown.cached_download(url, output)
10
 
11
 
12
  def get_vessel_model(output):
 
2
  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):