Spaces:
Runtime error
Runtime error
Download src/test_setup.py from Hanokalure/human-activity-backend: direct link, hf CLI and curl.
- Browser
- Download file 5.07 kB
-
https://huggingface.co/spaces/Hanokalure/human-activity-backend/resolve/main/src/test_setup.py
- Command line
-
hf download hf://spaces/Hanokalure/human-activity-backend/src/test_setup.py
-
curl -L -o test_setup.py https://huggingface.co/spaces/Hanokalure/human-activity-backend/resolve/main/src/test_setup.py
5.07 kB
| """ | |
| 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() |