@@ -983,25 +983,14 @@ def merge_imgs(imgs, original_image_shape):
983983 return merged_imgs
984984
985985
986- def read_plainconfig (configname ):
987- """
988- This code is adapted from DeepLabCut with permission from MWMathis
989- """
990- if not os .path .exists (configname ):
991- raise FileNotFoundError (
992- f"Config { configname } is not found. Please make sure that the file exists."
993- )
994- with open (configname ) as file :
995- return YAML ().load (file )
996-
997- def DownloadModel (modelname , target_dir ):
986+ def download_model (modelname , target_dir ):
998987 """
999988 Downloads a specific pretained model.
1000989 This code is adapted from DeepLabCut with permission from MWMathis
1001990 """
991+ import json
1002992 import urllib .request
1003993 import tarfile
1004- from tqdm import tqdm
1005994
1006995 def show_progress (count , block_size , total_size ):
1007996 pbar .update (block_size )
@@ -1017,18 +1006,17 @@ def tarfilenamecutting(tarf):
10171006 if member .path .startswith (parent ):
10181007 member .path = member .path [l :]
10191008 yield member
1009+
10201010 #TODO: fix error in line 1021;
10211011 cellseg3d_path = os .path .split (importlib .util .find_spec ("napari-cellseg3d" ).origin )[0 ]
1022- neturls = read_plainconfig (os .path .join (cellseg3d_path ,"models" ,"pretrained" ,"pretrained_model_urls.yaml" ,))
1012+ json_path = os .path .join (cellseg3d_path , "models" , "pretrained" , "pretrained_model_urls.json" )
1013+ with open (json_path ) as f :
1014+ neturls = json .load (f )
10231015
10241016 if modelname in neturls .keys ():
10251017 url = neturls [modelname ]
10261018 response = urllib .request .urlopen (url )
1027- print (
1028- "Downloading the model from the M.W. Mathis Lab server {}...." .format (
1029- url
1030- )
1031- )
1019+ print (f"Downloading the model from the M.W. Mathis Lab server { url } ...." )
10321020 total_size = int (response .getheader ("Content-Length" ))
10331021 pbar = tqdm (unit = "B" , total = total_size , position = 0 )
10341022 filename , _ = urllib .request .urlretrieve (url , reporthook = show_progress )
0 commit comments