File size: 5,073 Bytes
062cf9b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Quick Setup Test for Basketball Binary Classifier
πŸ§ͺ This tests if everything is ready before full training
"""

def test_imports():
    """Test if all required modules can be imported"""
    print("πŸ§ͺ Testing imports...")
    
    try:
        import torch
        import torchvision
        print(f"βœ… PyTorch: {torch.__version__}")
        print(f"βœ… TorchVision: {torchvision.__version__}")
        
        if torch.cuda.is_available():
            print(f"βœ… CUDA: {torch.version.cuda}")
            print(f"πŸš€ GPU: {torch.cuda.get_device_name(0)}")
        else:
            print("⚠️ CUDA: Not available (will use CPU - slower training)")
            
    except ImportError as e:
        print(f"❌ Import error: {e}")
        return False
    
    try:
        from binary_dataset import get_binary_dataloaders
        from binary_model import get_binary_model
        print("βœ… Custom modules imported successfully")
    except ImportError as e:
        print(f"❌ Custom module error: {e}")
        return False
    
    return True

def test_data_paths():
    """Test if data paths exist"""
    print("\nπŸ“‚ Testing data paths...")
    
    import os
    
    data_root = r"C:\ASH_PROJECT\data\UCF101"
    annotation_path = r"C:\ASH_PROJECT\data\ucfTrainTestlist"
    
    if os.path.exists(data_root):
        print("βœ… UCF101 data directory found")
        # Count some directories
        dirs = [d for d in os.listdir(data_root) if os.path.isdir(os.path.join(data_root, d))]
        print(f"   πŸ“ Found {len(dirs)} action classes")
        
        # Check if Basketball exists
        if "Basketball" in dirs:
            print("βœ… Basketball class found")
            basket_path = os.path.join(data_root, "Basketball")
            videos = [f for f in os.listdir(basket_path) if f.endswith(('.avi', '.mp4'))]
            print(f"   πŸ€ Basketball videos: {len(videos)}")
        else:
            print("⚠️ Basketball class not found")
            
    else:
        print(f"❌ UCF101 data not found at: {data_root}")
        return False
    
    if os.path.exists(annotation_path):
        print("βœ… Annotation path found")
    else:
        print(f"❌ Annotations not found at: {annotation_path}")
        return False
    
    return True

def test_model_creation():
    """Test if we can create a binary model"""
    print("\nπŸ”§ Testing model creation...")
    
    try:
        from binary_model import get_binary_model
        
        model = get_binary_model("simple")
        print("βœ… Binary model created successfully")
        
        # Test with dummy input
        import torch
        dummy_input = torch.randn(1, 3, 16, 112, 112)
        
        with torch.no_grad():
            output = model(dummy_input)
            print(f"βœ… Model forward pass: {output.shape}")
            
            if output.shape == (1, 2):
                print("βœ… Correct output shape for binary classification")
            else:
                print(f"⚠️ Expected (1, 2), got {output.shape}")
        
        return True
        
    except Exception as e:
        print(f"❌ Model creation failed: {e}")
        return False

def test_dataset_loading():
    """Test if we can load a small batch of data"""
    print("\nπŸ“Š Testing dataset loading...")
    
    try:
        from binary_dataset import get_binary_dataloaders
        
        # Test with very small batch
        train_loader, test_loader, class_weights = get_binary_dataloaders(
            r"C:\ASH_PROJECT\data\UCF101",
            r"C:\ASH_PROJECT\data\ucfTrainTestlist", 
            target_action="Basketball",
            batch_size=2,  # Very small for testing
            num_workers=0
        )
        
        print("βœ… DataLoaders created successfully")
        print(f"   πŸ“Š Training batches: {len(train_loader)}")
        print(f"   πŸ“Š Test batches: {len(test_loader)}")
        print(f"   βš–οΈ Class weights: {class_weights}")
        
        # Try to load one batch
        print("\nπŸ” Testing batch loading...")
        for clips, labels in train_loader:
            print(f"βœ… First batch: clips={clips.shape}, labels={labels}")
            break
        
        return True
        
    except Exception as e:
        print(f"❌ Dataset loading failed: {e}")
        return False

def main():
    """Run all tests"""
    
    print("πŸš€" * 30)
    print("πŸš€ BASKETBALL BINARY CLASSIFIER SETUP TEST")
    print("πŸš€" * 30)
    
    all_passed = True
    
    all_passed &= test_imports()
    all_passed &= test_data_paths() 
    all_passed &= test_model_creation()
    all_passed &= test_dataset_loading()
    
    print("\n" + "=" * 50)
    if all_passed:
        print("πŸŽ‰ ALL TESTS PASSED!")
        print("βœ… Ready for basketball binary classifier training!")
        print("\nπŸš€ Next step: Run 'python train_basketball.py'")
    else:
        print("❌ SOME TESTS FAILED!")
        print("πŸ’‘ Fix the issues above before training")
    print("=" * 50)

if __name__ == "__main__":
    main()