|
37 | 37 |
|
38 | 38 | def download_benchmarking_data( |
39 | 39 | 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", |
41 | 41 | ): |
42 | 42 | """ |
43 | | - Downloads a DeepLabCut-Live benchmarking Data (videos & DLC models). |
| 43 | + Downloads and extracts DeepLabCut-Live benchmarking data (videos & DLC models). |
44 | 44 | """ |
45 | 45 | import os |
46 | 46 | import urllib.request |
47 | 47 | from tqdm import tqdm |
48 | 48 | import zipfile |
49 | 49 |
|
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 |
52 | 54 |
|
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") |
58 | 56 |
|
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) |
64 | 62 |
|
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() |
69 | 68 |
|
70 | 69 | print(f"Extracting {zip_path} to {target_dir} ...") |
71 | 70 | with zipfile.ZipFile(zip_path, 'r') as zip_ref: |
|
0 commit comments