-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_test.py
More file actions
159 lines (125 loc) Β· 4.61 KB
/
simple_test.py
File metadata and controls
159 lines (125 loc) Β· 4.61 KB
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
#!/usr/bin/env python3
"""
Simple Test Script for Folder-based Damage Detection
This script demonstrates the simplified folder-based processing.
"""
import os
import sys
from pathlib import Path
# Add the project root to the path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
def create_sample_structure():
"""Create the simple folder structure and add instructions."""
print("ποΈ Creating simple folder structure...")
# Create folders
input_dir = Path("input")
output_dir = Path("output")
input_dir.mkdir(exist_ok=True)
output_dir.mkdir(exist_ok=True)
# Create simple instructions
readme_content = """# How to Use
## Step 1: Add Images
Put your poster images in this folder:
- poster1.jpg
- poster2.png
- poster3.bmp
etc.
## Step 2: Run Detection
From the main project folder, run:
```bash
python3 pretrained_damage_detector.py --folder
```
## Step 3: Check Results
Results will appear in the output/ folder with:
- Annotated images showing damage status
- JSON reports with detailed analysis
"""
with open(input_dir / "README.md", "w") as f:
f.write(readme_content)
print(f"β
Created: {input_dir}/")
print(f"β
Created: {output_dir}/")
print(f"π Added instructions in {input_dir}/README.md")
def test_if_images_exist():
"""Test if there are any images to process."""
input_dir = Path("input")
if not input_dir.exists():
return False, 0
image_extensions = {'.jpg', '.jpeg', '.png', '.bmp', '.tiff', '.webp'}
image_count = 0
for file_path in input_dir.iterdir():
if file_path.is_file() and file_path.suffix.lower() in image_extensions:
image_count += 1
return image_count > 0, image_count
def run_simple_test():
"""Run a simple test of the folder processing."""
print("\nπ§ͺ Testing Simple Folder Processing...")
has_images, count = test_if_images_exist()
if not has_images:
print("β οΈ No images found in input/ folder")
print("π Please add some poster images to input/ folder and try again")
print("\nExample:")
print(" cp your_poster.jpg input/")
print(" python3 pretrained_damage_detector.py --folder")
return
print(f"πΈ Found {count} images in input/ folder")
print("π Running damage detection...")
try:
# Import and run the detector
from pretrained_damage_detector import PretrainedDamageDetector
detector = PretrainedDamageDetector(device='cpu') # Use CPU for testing
summary = detector.process_input_folder("input", "output")
print("\n" + "="*40)
print("π TEST RESULTS")
print("="*40)
print(f"πΈ Total Images: {summary['total_images']}")
print(f"β
Processed: {summary['processed']}")
print(f"π΄ Damaged: {summary['damaged']}")
print(f"π’ Undamaged: {summary['undamaged']}")
print(f"π Damage Rate: {summary['damage_rate']}")
print(f"π Results saved to: output/")
# List output files
output_dir = Path("output")
if output_dir.exists():
files = list(output_dir.iterdir())
print(f"\nπ Output files ({len(files)}):")
for file in files:
print(f" β’ {file.name}")
print("\nβ
Test completed successfully!")
except Exception as e:
print(f"β Test failed: {e}")
print("\nTry installing dependencies:")
print(" pip install -r requirements.txt")
def show_usage():
"""Show simple usage instructions."""
print("π― Simple Damage Detector Usage")
print("="*35)
print()
print("π Folder Structure:")
print(" input/ β Put your images here")
print(" output/ β Results appear here")
print()
print("π Commands:")
print(" python3 pretrained_damage_detector.py --folder")
print(" python3 pretrained_damage_detector.py image.jpg")
print()
print("π§ Setup:")
print(" 1. Add images to input/ folder")
print(" 2. Run: python3 pretrained_damage_detector.py --folder")
print(" 3. Check results in output/ folder")
print()
print("That's it! Simple and clean. π")
def main():
"""Main test function."""
print("π― Simple Damage Detection Test")
print("="*35)
# Create folder structure
create_sample_structure()
# Show usage
show_usage()
# Test if we can run detection
print("\n" + "="*40)
print("π§ͺ TESTING")
print("="*40)
run_simple_test()
if __name__ == "__main__":
main()