-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_clip.py
More file actions
73 lines (61 loc) · 1.89 KB
/
test_clip.py
File metadata and controls
73 lines (61 loc) · 1.89 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
#!/usr/bin/env python3
"""
Test script to verify OpenAI CLIP installation
"""
def test_clip_import():
"""Test if CLIP can be imported"""
try:
import clip
print("✓ CLIP imported successfully")
return True
except ImportError as e:
print(f"✗ CLIP import failed: {e}")
print("\nInstall with: pip install git+https://github.com/openai/CLIP.git")
return False
def test_clip_models():
"""Test available CLIP models"""
try:
import clip
models = clip.available_models()
print(f"✓ Available models: {models}")
return True
except Exception as e:
print(f"✗ Failed to get models: {e}")
return False
def test_clip_load():
"""Test loading CLIP model"""
try:
import clip
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"Using device: {device}")
print("Loading ViT-B/32 model...")
model, preprocess = clip.load("ViT-B/32", device=device)
print("✓ Model loaded successfully")
# Test tokenization
text = clip.tokenize(["a dog", "a cat"])
print(f"✓ Tokenization works: {text.shape}")
return True
except Exception as e:
print(f"✗ Failed to load model: {e}")
import traceback
traceback.print_exc()
return False
def main():
print("=" * 60)
print("OpenAI CLIP Installation Test")
print("=" * 60)
print("\n1. Testing CLIP import...")
if not test_clip_import():
return
print("\n2. Testing available models...")
if not test_clip_models():
return
print("\n3. Testing model loading...")
if not test_clip_load():
return
print("\n" + "=" * 60)
print("✓ All tests passed! CLIP is ready to use.")
print("=" * 60)
if __name__ == "__main__":
main()