55Licensed under GNU Lesser General Public License v3.0
66"""
77
8-
9- import sys
8+ import argparse
109import shutil
11- import warnings
12-
13- from dlclive import benchmark_videos
10+ import sys
1411import urllib .request
15- import argparse
12+ import warnings
1613from pathlib import Path
17- from dlclibrary .dlcmodelzoo .modelzoo_download import (
18- download_huggingface_model ,
19- )
2014
15+ from dlclibrary .dlcmodelzoo .modelzoo_download import download_huggingface_model
16+
17+ from dlclive import benchmark_videos
2118
2219MODEL_NAME = "superanimal_quadruped"
2320SNAPSHOT_NAME = "snapshot-700000.pb"
@@ -27,28 +24,33 @@ def urllib_pbar(count, blockSize, totalSize):
2724 percent = int (count * blockSize * 100 / totalSize )
2825 outstr = f"{ round (percent )} %"
2926 sys .stdout .write (outstr )
30- sys .stdout .write ("\b " * len (outstr ))
27+ sys .stdout .write ("\b " * len (outstr ))
3128 sys .stdout .flush ()
3229
3330
3431def main ():
3532 parser = argparse .ArgumentParser (
36- description = "Test DLC-Live installation by downloading and evaluating a demo DLC project!" )
37- parser .add_argument ('--nodisplay' , action = 'store_false' , help = "Run the test without displaying tracking" )
33+ description = "Test DLC-Live installation by downloading and evaluating a demo DLC project!"
34+ )
35+ parser .add_argument (
36+ "--nodisplay" ,
37+ action = "store_false" ,
38+ help = "Run the test without displaying tracking" ,
39+ )
3840 args = parser .parse_args ()
3941 display = args .nodisplay
4042
4143 if not display :
42- print (' Running without displaying video' )
44+ print (" Running without displaying video" )
4345
4446 # make temporary directory in $HOME
4547 # TODO: why create this temp directory in $HOME?
4648 print ("\n Creating temporary directory...\n " )
47- tmp_dir = Path ().home () / ' dlc-live-tmp'
48- tmp_dir .mkdir (mode = 0o775 ,exist_ok = True )
49+ tmp_dir = Path ().home () / " dlc-live-tmp"
50+ tmp_dir .mkdir (mode = 0o775 , exist_ok = True )
4951
50- video_file = str (tmp_dir / ' dog_clip.avi' )
51- model_dir = tmp_dir / ' DLC_Dog_resnet_50_iteration-0_shuffle-0'
52+ video_file = str (tmp_dir / " dog_clip.avi" )
53+ model_dir = tmp_dir / " DLC_Dog_resnet_50_iteration-0_shuffle-0"
5254
5355 # download dog test video from github:
5456 # TODO: Should check if the video's already there before downloading it (should have been cloned with the files)
@@ -58,25 +60,31 @@ def main():
5860
5961 # download model from the DeepLabCut Model Zoo
6062 if Path (model_dir / SNAPSHOT_NAME ).exists ():
61- print (' Model already downloaded, using cached version' )
63+ print (" Model already downloaded, using cached version" )
6264 else :
6365 print ("Downloading full_dog model from the DeepLabCut Model Zoo..." )
6466 download_huggingface_model (MODEL_NAME , model_dir )
6567
6668 # assert these things exist so we can give informative error messages
6769 assert Path (video_file ).exists (), f"Missing video file { video_file } "
68- assert Path (model_dir / SNAPSHOT_NAME ).exists (), f"Missing model file { model_dir / SNAPSHOT_NAME } "
70+ assert Path (
71+ model_dir / SNAPSHOT_NAME
72+ ).exists (), f"Missing model file { model_dir / SNAPSHOT_NAME } "
6973
7074 # run benchmark videos
7175 print ("\n Running inference...\n " )
72- benchmark_videos (str (model_dir ), video_file , display = display , resize = 0.5 , pcutoff = 0.25 )
76+ benchmark_videos (
77+ str (model_dir ), video_file , display = display , resize = 0.5 , pcutoff = 0.25
78+ )
7379
7480 # deleting temporary files
7581 print ("\n Deleting temporary files...\n " )
7682 try :
7783 shutil .rmtree (tmp_dir )
7884 except PermissionError :
79- warnings .warn (f'Could not delete temporary directory { str (tmp_dir )} due to a permissions error, but otherwise dlc-live seems to be working fine!' )
85+ warnings .warn (
86+ f"Could not delete temporary directory { str (tmp_dir )} due to a permissions error, but otherwise dlc-live seems to be working fine!"
87+ )
8088
8189 print ("\n Done!\n " )
8290
0 commit comments