File size: 3,631 Bytes
e15abf5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python3
"""
Verify that FoundationPose weights are accessible from Hugging Face model repository.

This script checks:
1. Model repo exists and is accessible
2. Required weight files are present
3. Files can be downloaded successfully
"""

import os
import sys
from pathlib import Path

try:
    from huggingface_hub import list_repo_files, hf_hub_download
except ImportError:
    print("❌ huggingface_hub not installed")
    print("Install with: pip install huggingface_hub")
    sys.exit(1)

# Configuration
MODEL_REPO = os.environ.get("FOUNDATIONPOSE_MODEL_REPO", "gpue/foundationpose-weights")

# Required files
REQUIRED_FILES = [
    "2023-10-28-18-33-37/config.yml",
    "2023-10-28-18-33-37/model_best.pth",
    "2024-01-11-20-02-45/config.yml",
    "2024-01-11-20-02-45/model_best.pth",
]


def verify_repo_access():
    """Verify model repository is accessible."""
    print(f"Checking repository: {MODEL_REPO}")
    print("-" * 60)

    try:
        files = list_repo_files(repo_id=MODEL_REPO, repo_type="model")
        print(f"✓ Repository accessible")
        print(f"✓ Found {len(files)} files")
        return files
    except Exception as e:
        print(f"❌ Cannot access repository: {e}")
        return None


def verify_required_files(repo_files):
    """Verify all required weight files are present."""
    print("\nChecking required files:")
    print("-" * 60)

    all_present = True
    for required_file in REQUIRED_FILES:
        if required_file in repo_files:
            print(f"✓ {required_file}")
        else:
            print(f"❌ Missing: {required_file}")
            all_present = False

    return all_present


def test_download():
    """Test downloading a small file."""
    print("\nTesting download:")
    print("-" * 60)

    try:
        # Download a small config file to test connectivity
        test_file = "2023-10-28-18-33-37/config.yml"
        print(f"Downloading {test_file}...")

        downloaded = hf_hub_download(
            repo_id=MODEL_REPO,
            filename=test_file,
            repo_type="model"
        )

        print(f"✓ Download successful: {downloaded}")

        # Check file size
        size = Path(downloaded).stat().st_size
        print(f"✓ File size: {size:,} bytes")

        return True

    except Exception as e:
        print(f"❌ Download failed: {e}")
        return False


def main():
    """Run all verification checks."""
    print("=" * 60)
    print("FoundationPose Model Repository Verification")
    print("=" * 60)
    print()

    # Check 1: Repository access
    repo_files = verify_repo_access()
    if repo_files is None:
        print("\n❌ Verification failed: Cannot access repository")
        sys.exit(1)

    # Check 2: Required files
    has_all_files = verify_required_files(repo_files)
    if not has_all_files:
        print("\n❌ Verification failed: Missing required files")
        sys.exit(1)

    # Check 3: Download test
    can_download = test_download()
    if not can_download:
        print("\n❌ Verification failed: Cannot download files")
        sys.exit(1)

    # All checks passed
    print()
    print("=" * 60)
    print("✓ All verification checks passed!")
    print("=" * 60)
    print()
    print(f"Model repository '{MODEL_REPO}' is ready to use.")
    print()
    print("To use in your Space:")
    print("  1. Set environment variable:")
    print(f"     FOUNDATIONPOSE_MODEL_REPO={MODEL_REPO}")
    print("  2. Set USE_HF_WEIGHTS=true")
    print("  3. Set USE_REAL_MODEL=true")
    print()

    return 0


if __name__ == "__main__":
    sys.exit(main())