Spaces:
Sleeping
Sleeping
File size: 4,777 Bytes
7bf7aa7 |
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 160 161 162 163 164 165 166 167 168 |
"""
Diagnostic script to identify common issues with face recognition setup
"""
import sys
import os
import traceback
def check_python_version():
"""Check Python version"""
print("Python Version Check")
print("=" * 20)
print(f"Python version: {sys.version}")
if sys.version_info < (3, 6):
print("WARNING: Python 3.6+ recommended")
else:
print("OK: Python version is compatible")
def check_packages():
"""Check if required packages are installed"""
print("\nPackage Installation Check")
print("=" * 30)
packages = [
('numpy', 'numpy'),
('cv2', 'cv2'),
('torch', 'torch'),
('sklearn', 'sklearn'),
('PIL', 'PIL'),
('matplotlib', 'matplotlib'),
('joblib', 'joblib')
]
missing_packages = []
for package_name, import_name in packages:
try:
__import__(import_name)
print(f"OK: {package_name}")
except ImportError:
print(f"ERROR: {package_name} - MISSING")
missing_packages.append(package_name)
if missing_packages:
print(f"\nWARNING: Missing packages: {', '.join(missing_packages)}")
print("Install with: pip install " + " ".join(missing_packages))
return False
else:
print("\nOK: All required packages are installed")
return True
def check_files():
"""Check if required files exist"""
print("\nFile Structure Check")
print("=" * 25)
required_files = [
'face_recognition.py',
'face_recognition_model.py',
'test_cosine_similarity.py'
]
model_files = [
'siamese_model.t7',
'decision_tree_model.sav',
'face_recognition_scaler.sav'
]
missing_files = []
print("Required Python files:")
for file in required_files:
if os.path.exists(file):
print(f"OK: {file}")
else:
print(f"ERROR: {file} - MISSING")
missing_files.append(file)
print("\nModel files (need to be trained):")
for file in model_files:
if os.path.exists(file):
print(f"OK: {file}")
else:
print(f"ERROR: {file} - MISSING (needs training)")
missing_files.append(file)
return len(missing_files) == 0
def test_imports():
"""Test importing the face recognition module"""
print("\nImport Test")
print("=" * 15)
try:
# Add current directory to path
current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, current_dir)
from face_recognition import get_similarity, get_face_class
print("OK: Successfully imported face_recognition functions")
return True
except Exception as e:
print(f"ERROR: Failed to import face_recognition: {e}")
print("Full error:")
traceback.print_exc()
return False
def test_basic_functionality():
"""Test basic functionality without model files"""
print("\nBasic Functionality Test")
print("=" * 30)
try:
import numpy as np
from face_recognition import detected_face
# Create a test image
test_img = np.random.randint(0, 255, (100, 100, 3), dtype=np.uint8)
# Test face detection
result = detected_face(test_img)
print("OK: detected_face function works")
return True
except Exception as e:
print(f"ERROR: Basic functionality test failed: {e}")
traceback.print_exc()
return False
def main():
"""Run all diagnostic checks"""
print("Face Recognition System Diagnostic")
print("=" * 40)
checks = [
check_python_version,
check_packages,
check_files,
test_imports,
test_basic_functionality
]
results = []
for check in checks:
try:
result = check()
results.append(result)
except Exception as e:
print(f"ERROR: Check failed with error: {e}")
results.append(False)
print("\n" + "=" * 40)
print("DIAGNOSTIC SUMMARY")
print("=" * 40)
if all(results):
print("SUCCESS: All checks passed! Your setup looks good.")
print("You can now run the test script.")
else:
print("ERROR: Some checks failed. Please fix the issues above.")
print("\nCommon solutions:")
print("1. Install missing packages: pip install numpy opencv-python torch scikit-learn matplotlib joblib")
print("2. Make sure all Python files are in the same directory")
print("3. Train your models first before testing similarity")
if __name__ == "__main__":
main()
|