-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_dummy_model.py
More file actions
executable file
·112 lines (93 loc) · 3.32 KB
/
create_dummy_model.py
File metadata and controls
executable file
·112 lines (93 loc) · 3.32 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
#!/usr/bin/env python3
"""
Create a dummy TensorFlow model for testing the system
This is useful if you don't have a trained model yet
"""
import os
import json
import numpy as np
import tensorflow as tf
from tensorflow import keras
def create_dummy_model():
"""Create a simple dummy model for testing"""
print("Creating dummy TensorFlow model...")
# Create a simple CNN model
model = keras.Sequential([
keras.layers.Input(shape=(224, 224, 3)),
keras.layers.Conv2D(32, (3, 3), activation='relu'),
keras.layers.MaxPooling2D((2, 2)),
keras.layers.Conv2D(64, (3, 3), activation='relu'),
keras.layers.MaxPooling2D((2, 2)),
keras.layers.Conv2D(64, (3, 3), activation='relu'),
keras.layers.Flatten(),
keras.layers.Dense(64, activation='relu'),
keras.layers.Dropout(0.5),
keras.layers.Dense(3, activation='softmax') # 3 classes
])
model.compile(
optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy']
)
return model
def save_model(model, output_dir='my_model'):
"""Save the model in the required format"""
print(f"Saving model to {output_dir}/...")
# Create directory if it doesn't exist
os.makedirs(output_dir, exist_ok=True)
# Save the model
model.save(output_dir)
# Create metadata.json
metadata = {
"tfjsVersion": "1.3.1",
"tmVersion": "2.4.0",
"packageVersion": "0.8.4",
"packageName": "@teachablemachine/image",
"timeStamp": "2025-10-17T14:00:00.000Z",
"userMetadata": {},
"modelName": "tm-my-image-model",
"labels": [
"Person_1",
"Person_2",
"Unknown"
],
"imageSize": 224
}
metadata_path = os.path.join(output_dir, 'metadata.json')
with open(metadata_path, 'w') as f:
json.dump(metadata, f, indent=2)
print("✓ Model saved successfully!")
print(f"✓ Metadata saved to {metadata_path}")
print("\nModel classes:")
for i, label in enumerate(metadata['labels']):
print(f" {i+1}. {label}")
def main():
print("=" * 60)
print("Dummy Model Creator")
print("=" * 60)
print("\nThis script creates a simple TensorFlow model for testing.")
print("⚠️ WARNING: This is NOT a trained model!")
print("It will return random predictions.\n")
response = input("Create dummy model? (y/n): ").strip().lower()
if response != 'y':
print("Cancelled.")
return
try:
model = create_dummy_model()
save_model(model)
print("\n" + "=" * 60)
print("Dummy model created successfully!")
print("=" * 60)
print("\nYou can now test the system with this model.")
print("However, it will return random predictions.")
print("\nTo get real face recognition, you need to:")
print("1. Go to https://teachablemachine.withgoogle.com/")
print("2. Train a model with real face images")
print("3. Export and replace the my_model/ directory")
print("\n")
except Exception as e:
print(f"\n❌ Error creating model: {e}")
print("\nMake sure TensorFlow is installed:")
print(" pip install tensorflow")
if __name__ == '__main__':
main()