File size: 4,608 Bytes
eae62a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Simple test script to verify Transformers pipeline integration
"""

from transformers import pipeline
import torch
from PIL import Image
import numpy as np

def test_transformers_pipeline():
    """Test if transformers depth estimation pipeline works"""
    print("πŸ§ͺ Testing Transformers Depth Estimation Pipeline")
    print("=" * 50)
    
    try:
        # Initialize pipeline
        print("1. Initializing pipeline...")
        pipe = pipeline(
            "depth-estimation", 
            model="apple/DepthPro",
            device=-1,  # CPU
            torch_dtype=torch.float32
        )
        print("βœ… Pipeline initialized successfully!")
        
        # Create test image
        print("2. Creating test image...")
        test_image = Image.new('RGB', (640, 480), color='blue')
        # Add some pattern
        pixels = np.array(test_image)
        for y in range(480):
            for x in range(640):
                intensity = int(255 * (1 - y / 480))
                pixels[y, x] = [intensity, intensity//2, intensity//3]
        test_image = Image.fromarray(pixels.astype(np.uint8))
        print("βœ… Test image created!")
        
        # Test pipeline
        print("3. Running depth estimation...")
        result = pipe(test_image)
        print("βœ… Pipeline executed successfully!")
        
        # Check result
        print("4. Checking results...")
        if isinstance(result, dict):
            if 'depth' in result:
                depth = result['depth']
                print(f"   Depth type: {type(depth)}")
                if hasattr(depth, 'shape'):
                    print(f"   Depth shape: {depth.shape}")
                elif hasattr(depth, 'size'):
                    print(f"   Depth size: {depth.size}")
                print("βœ… Valid depth result obtained!")
                return True
            else:
                print(f"   Result keys: {result.keys()}")
                print("⚠️  No 'depth' key in result")
                return False
        else:
            print(f"   Result type: {type(result)}")
            if hasattr(result, 'depth'):
                print("βœ… Result has depth attribute!")
                return True
            else:
                print("⚠️  Result format unexpected")
                return False
                
    except ImportError as e:
        print(f"❌ Import error: {e}")
        print("πŸ’‘ Try: pip install transformers torch")
        return False
    except Exception as e:
        print(f"❌ Pipeline test failed: {e}")
        print("πŸ’‘ This is expected if the model isn't available or if there are compatibility issues")
        return False

def test_fallback_dummy():
    """Test the dummy pipeline fallback"""
    print("\nπŸ§ͺ Testing Dummy Pipeline Fallback")
    print("=" * 40)
    
    try:
        # Import dummy pipeline from our app
        import sys
        import os
        sys.path.append(os.path.dirname(os.path.abspath(__file__)))
        
        from app import DummyDepthPipeline
        
        dummy = DummyDepthPipeline()
        test_image = Image.new('RGB', (512, 384), color='green')
        
        result = dummy(test_image)
        
        if isinstance(result, dict) and 'depth' in result:
            depth = result['depth']
            print(f"βœ… Dummy pipeline works! Depth shape: {depth.shape}")
            print(f"   Depth range: {np.min(depth):.2f} - {np.max(depth):.2f}")
            return True
        else:
            print(f"❌ Unexpected result format: {type(result)}")
            return False
            
    except Exception as e:
        print(f"❌ Dummy pipeline test failed: {e}")
        return False

if __name__ == "__main__":
    print("πŸš€ Testing Depth Pro Transformers Integration\n")
    
    # Test real pipeline
    pipeline_works = test_transformers_pipeline()
    
    # Test fallback
    dummy_works = test_fallback_dummy()
    
    print("\n" + "="*50)
    print("🏁 Test Summary:")
    print("="*50)
    print(f"Transformers Pipeline: {'βœ… WORKS' if pipeline_works else '❌ FAILED (expected in some environments)'}")
    print(f"Dummy Pipeline Fallback: {'βœ… WORKS' if dummy_works else '❌ FAILED'}")
    
    if dummy_works:
        print("\nπŸŽ‰ The app should work with fallback even if the real model fails!")
    else:
        print("\n⚠️  There may be issues with the fallback implementation.")
    
    if pipeline_works:
        print("🌟 Real Depth Pro model should work perfectly!")
    else:
        print("πŸ’‘ Real model may need specific environment setup or GPU.")