-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-pi05-setup.py
More file actions
executable file
·170 lines (138 loc) · 5.05 KB
/
Copy pathtest-pi05-setup.py
File metadata and controls
executable file
·170 lines (138 loc) · 5.05 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env python3
"""
Test script to verify PI 0.5 inference setup before running on the robot.
This checks:
1. Required packages are installed
2. Model can be loaded from HuggingFace
3. Cameras are accessible
4. Serial port is available
Usage:
python test-pi05-setup.py
"""
import sys
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def test_imports():
"""Test that all required packages can be imported."""
logger.info("Testing imports...")
try:
import torch
import lerobot
from lerobot.policies.factory import make_policy
from lerobot.robots.so101_follower import SO101Follower
logger.info("✓ All required packages imported successfully")
logger.info(f" - PyTorch version: {torch.__version__}")
logger.info(f" - LeRobot version: {lerobot.__version__}")
return True
except ImportError as e:
logger.error(f"✗ Import error: {e}")
return False
def test_model_loading():
"""Test loading the PI 0.5 model from HuggingFace."""
logger.info("\nTesting model loading...")
try:
from lerobot.configs.policies import PreTrainedConfig
model_path = "bdhillon/PIv2"
logger.info(f" Attempting to load config from {model_path}...")
config = PreTrainedConfig.from_pretrained(model_path)
logger.info(f"✓ Successfully loaded model config")
logger.info(f" - Policy type: {config.type}")
logger.info(f" - Device: {config.device}")
return True
except Exception as e:
logger.error(f"✗ Model loading error: {e}")
logger.info(" Tip: Run 'huggingface-cli login' if the model is private")
return False
def test_cameras():
"""Test camera availability."""
logger.info("\nTesting cameras...")
import os
cameras = {
"front": "/dev/video0",
"side": "/dev/video2",
"wrist": "/dev/video4",
}
all_ok = True
for name, path in cameras.items():
if os.path.exists(path):
logger.info(f"✓ {name} camera found at {path}")
else:
logger.warning(f"✗ {name} camera NOT found at {path}")
all_ok = False
if not all_ok:
logger.info("\n Available video devices:")
os.system("ls -la /dev/video* 2>/dev/null")
return all_ok
def test_robot_port():
"""Test robot serial port availability."""
logger.info("\nTesting robot serial port...")
import os
port = "/dev/ttyACM0"
if os.path.exists(port):
logger.info(f"✓ Robot port found at {port}")
# Check permissions
import stat
st = os.stat(port)
mode = st.st_mode
if os.access(port, os.R_OK | os.W_OK):
logger.info(f"✓ Port {port} is readable and writable")
return True
else:
logger.warning(f"✗ Port {port} exists but may not have proper permissions")
logger.info(f" Run: sudo usermod -a -G dialout $USER")
logger.info(f" Then log out and log back in")
return False
else:
logger.warning(f"✗ Robot port NOT found at {port}")
logger.info("\n Available serial ports:")
os.system("ls -la /dev/ttyACM* /dev/ttyUSB* 2>/dev/null")
return False
def test_gpu():
"""Test GPU availability."""
logger.info("\nTesting GPU...")
try:
import torch
if torch.cuda.is_available():
logger.info(f"✓ CUDA is available")
logger.info(f" - GPU: {torch.cuda.get_device_name(0)}")
logger.info(f" - CUDA version: {torch.version.cuda}")
logger.info(f" - GPU memory: {torch.cuda.get_device_properties(0).total_memory / 1e9:.1f} GB")
return True
else:
logger.warning(f"✗ CUDA is not available - will use CPU (slower)")
return False
except Exception as e:
logger.error(f"✗ GPU test error: {e}")
return False
def main():
logger.info("=" * 60)
logger.info("PI 0.5 Inference Setup Test")
logger.info("=" * 60)
results = {
"Imports": test_imports(),
"Model Loading": test_model_loading(),
"Cameras": test_cameras(),
"Robot Port": test_robot_port(),
"GPU": test_gpu(),
}
logger.info("\n" + "=" * 60)
logger.info("Test Summary")
logger.info("=" * 60)
for test_name, passed in results.items():
status = "✓ PASS" if passed else "✗ FAIL"
logger.info(f"{test_name:20s}: {status}")
all_critical_passed = results["Imports"] and results["Model Loading"]
logger.info("=" * 60)
if all_critical_passed:
logger.info("✓ Critical tests passed! You can proceed with inference.")
logger.info("\nTo run inference:")
logger.info(" ./run-pi05-inference.sh")
logger.info(" OR")
logger.info(" python run-pi05-inference-simple.py")
return 0
else:
logger.error("✗ Some critical tests failed. Please fix the issues above.")
return 1
if __name__ == "__main__":
sys.exit(main())