kolam-ai-generator / test_project.py
Rishab7310's picture
Upload 7 files
7a4e326 verified
"""
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()