|
37 | 37 |
|
38 | 38 | def download_benchmarking_data(
|
39 | 39 | target_dir=".",
|
40 |
| - url="http://deeplabcut.rowland.harvard.edu/datasets/dlclivebenchmark.tar.gz", |
| 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 | + import os |
45 | 46 | import urllib.request
|
46 |
| - import tarfile |
47 | 47 | from tqdm import tqdm
|
| 48 | + import zipfile |
48 | 49 |
|
49 |
| - def show_progress(count, block_size, total_size): |
50 |
| - pbar.update(block_size) |
51 |
| - |
52 |
| - def tarfilenamecutting(tarf): |
53 |
| - """' auxfun to extract folder path |
54 |
| - ie. /xyz-trainsetxyshufflez/ |
55 |
| - """ |
56 |
| - for memberid, member in enumerate(tarf.getmembers()): |
57 |
| - if memberid == 0: |
58 |
| - parent = str(member.path) |
59 |
| - l = len(parent) + 1 |
60 |
| - if member.path.startswith(parent): |
61 |
| - member.path = member.path[l:] |
62 |
| - yield member |
63 |
| - |
64 |
| - response = urllib.request.urlopen(url) |
65 |
| - print( |
66 |
| - "Downloading the benchmarking data from the DeepLabCut server @Harvard -> Go Crimson!!! {}....".format( |
67 |
| - url |
68 |
| - ) |
69 |
| - ) |
70 |
| - total_size = int(response.getheader("Content-Length")) |
71 |
| - pbar = tqdm(unit="B", total=total_size, position=0) |
72 |
| - filename, _ = urllib.request.urlretrieve(url, reporthook=show_progress) |
73 |
| - with tarfile.open(filename, mode="r:gz") as tar: |
74 |
| - tar.extractall(target_dir, members=tarfilenamecutting(tar)) |
| 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 |
| 54 | + |
| 55 | + zip_path = os.path.join(target_dir, "Data-DLC-live-benchmark.zip") |
| 56 | + |
| 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) |
| 62 | + |
| 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() |
75 | 68 |
|
| 69 | + print(f"Extracting {zip_path} to {target_dir} ...") |
| 70 | + with zipfile.ZipFile(zip_path, 'r') as zip_ref: |
| 71 | + zip_ref.extractall(target_dir) |
76 | 72 |
|
77 | 73 | def get_system_info() -> dict:
|
78 | 74 | """ Return summary info for system running benchmark
|
|
0 commit comments