Spaces:
Running
Running
File size: 4,908 Bytes
7a4e326 |
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 |
"""
Quick test to verify the Kolam AI Generator project is working.
"""
import torch
import numpy as np
import sys
from pathlib import Path
# Add project paths
sys.path.append('models')
sys.path.append('utils')
def test_imports():
"""Test that all modules can be imported."""
print("π Testing imports...")
try:
from models.cnn_feature_extractor import KolamFeatureExtractor
print("β
CNN Feature Extractor imported successfully")
from models.gan_generator import KolamGenerator
print("β
GAN Generator imported successfully")
from utils.image_utils import create_synthetic_kolam
print("β
Image utilities imported successfully")
from utils.metrics import KolamDesignMetrics
print("β
Metrics imported successfully")
return True
except Exception as e:
print(f"β Import error: {e}")
return False
def test_models():
"""Test model creation and basic functionality."""
print("\nπ§ Testing model creation...")
try:
from models.cnn_feature_extractor import KolamFeatureExtractor
from models.gan_generator import KolamGenerator
# Test CNN Feature Extractor
feature_extractor = KolamFeatureExtractor(input_channels=1, feature_dim=128)
print("β
CNN Feature Extractor created successfully")
# Test GAN Generator
generator = KolamGenerator(noise_dim=100, feature_dim=128, output_channels=1, image_size=64)
print("β
GAN Generator created successfully")
# Test basic forward pass
test_input = torch.randn(2, 1, 64, 64)
features = feature_extractor(test_input)
print(f"β
CNN forward pass: {test_input.shape} β {features.shape}")
noise = torch.randn(2, 100)
generated = generator(noise)
print(f"β
Generator forward pass: {noise.shape} β {generated.shape}")
return True
except Exception as e:
print(f"β Model test error: {e}")
return False
def test_utilities():
"""Test utility functions."""
print("\nπ οΈ Testing utilities...")
try:
from utils.image_utils import create_synthetic_kolam
from utils.metrics import KolamDesignMetrics
# Test synthetic Kolam creation
kolam = create_synthetic_kolam(size=(64, 64), complexity='medium')
print(f"β
Synthetic Kolam created: {kolam.shape}")
# Test metrics
metrics = KolamDesignMetrics()
quality = metrics.calculate_overall_quality(kolam)
print(f"β
Quality metrics calculated: {quality['overall_quality']:.4f}")
return True
except Exception as e:
print(f"β Utility test error: {e}")
return False
def create_sample_data():
"""Create sample data for demonstration."""
print("\nπ Creating sample data...")
try:
from utils.image_utils import create_synthetic_kolam
# Create directories
data_dir = Path('data/processed')
data_dir.mkdir(parents=True, exist_ok=True)
# Create sample images
for i in range(5):
kolam = create_synthetic_kolam(size=(64, 64), complexity='medium')
np.save(data_dir / f'sample_{i:03d}.npy', kolam)
print(f"β
Created 5 sample images in {data_dir}")
return True
except Exception as e:
print(f"β Data creation error: {e}")
return False
def main():
"""Main test function."""
print("π Kolam AI Generator - Project Test")
print("=" * 50)
tests = [
("Import Test", test_imports),
("Model Test", test_models),
("Utility Test", test_utilities),
("Data Creation", create_sample_data)
]
passed = 0
total = len(tests)
for test_name, test_func in tests:
print(f"\nπ Running {test_name}...")
if test_func():
passed += 1
print(f"β
{test_name} PASSED")
else:
print(f"β {test_name} FAILED")
print(f"\nπ Test Results: {passed}/{total} tests passed")
if passed == total:
print("\nπ All tests passed! The Kolam AI Generator project is ready to use!")
print("\nπ Next steps:")
print("1. Add real Kolam images to data/raw/")
print("2. Run: python scripts/preprocess.py")
print("3. Start training with Jupyter notebooks in notebooks/")
print("4. Or run training scripts directly")
else:
print(f"\nβ οΈ {total - passed} tests failed. Please check the errors above.")
if __name__ == "__main__":
main()
|