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()