Skip to content

Commit 6c61b29

Browse files
committed
Fix download_benchmarking_data()
1 parent 0883c17 commit 6c61b29

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

dlclive/benchmark.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,34 @@
3737

3838
def download_benchmarking_data(
3939
target_dir=".",
40-
url="https://huggingface.co/datasets/mwmathis/DLCspeed_benchmarking/blob/main/Data-DLC-live-benchmark.zip",
40+
url="https://huggingface.co/datasets/mwmathis/DLCspeed_benchmarking/resolve/main/Data-DLC-live-benchmark.zip",
4141
):
4242
"""
43-
Downloads a DeepLabCut-Live benchmarking Data (videos & DLC models).
43+
Downloads and extracts DeepLabCut-Live benchmarking data (videos & DLC models).
4444
"""
4545
import os
4646
import urllib.request
4747
from tqdm import tqdm
4848
import zipfile
4949

50-
def show_progress(count, block_size, total_size):
51-
pbar.update(block_size)
50+
# Avoid nested folder issue
51+
if os.path.basename(os.path.normpath(target_dir)) == "Data-DLC-live-benchmark":
52+
target_dir = os.path.dirname(os.path.normpath(target_dir))
53+
os.makedirs(target_dir, exist_ok=True) # Ensure target directory exists
5254

53-
response = urllib.request.urlopen(url)
54-
total_size = int(response.getheader("Content-Length"))
55-
pbar = tqdm(unit="B", total=total_size, position=0, desc="Downloading")
56-
filename, _ = urllib.request.urlretrieve(url, filename=zip_path, reporthook=show_progress)
57-
pbar.close()
55+
zip_path = os.path.join(target_dir, "Data-DLC-live-benchmark.zip")
5856

59-
class DownloadProgressBar(tqdm):
60-
def update_to(self, b=1, bsize=1, tsize=None):
61-
if tsize is not None:
62-
self.total = tsize
63-
self.update(b * bsize - self.n)
57+
if os.path.exists(zip_path):
58+
print(f"{zip_path} already exists. Skipping download.")
59+
else:
60+
def show_progress(count, block_size, total_size):
61+
pbar.update(block_size)
6462

65-
zip_path = os.path.join(target_dir, "Data-DLC-live-benchmark.zip")
66-
print(
67-
f"Downloading the benchmarking data from {url} ..."
68-
)
63+
print(f"Downloading the benchmarking data from {url} ...")
64+
pbar = tqdm(unit="B", total=0, position=0, desc="Downloading")
65+
66+
filename, _ = urllib.request.urlretrieve(url, filename=zip_path, reporthook=show_progress)
67+
pbar.close()
6968

7069
print(f"Extracting {zip_path} to {target_dir} ...")
7170
with zipfile.ZipFile(zip_path, 'r') as zip_ref:

0 commit comments

Comments
 (0)