Spaces:
Runtime error
Runtime error
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() |