Karim Mansour commited on
Commit
598f665
·
verified ·
1 Parent(s): 4731b69

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +46 -0
README.md CHANGED
@@ -19,4 +19,50 @@ MobileNetV2
19
  ![image/png](https://cdn-uploads.huggingface.co/production/uploads/675c1368c65656c954bc34bf/nOXW3S983-ybbxL4Lvymy.png)
20
 
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
 
19
  ![image/png](https://cdn-uploads.huggingface.co/production/uploads/675c1368c65656c954bc34bf/nOXW3S983-ybbxL4Lvymy.png)
20
 
21
 
22
+ ```python
23
+ from huggingface_hub import hf_hub_download
24
+ from tensorflow.keras.models import load_model
25
+ from tensorflow.keras.preprocessing import image
26
+ import numpy as np
27
+
28
+ # 1. Hugging Face repo ID and model filename
29
+ repo_id = "your-username/your-repo" # Replace with your repo ID
30
+ filename = "hieroglyphics_modelMobileNetV2.keras" # Replace with your model filename
31
+
32
+ # 2. Download the model from Hugging Face Hub
33
+ model_path = hf_hub_download(repo_id=repo_id, filename=filename)
34
+ model = load_model(model_path)
35
+
36
+ # 3. Class names corresponding to model output indices
37
+ class_names = [
38
+ "100", "Her", "Woman", "among", "angry", "ankh", "aroura", "at", "bad", "bandage",
39
+ "bee", "belongs", "birth", "board", "book", "boy", "branch", "bread", "brewer", "builder",
40
+ "bury", "canal", "cloth", "cobra", "composite_bow", "cooked", "corpse", "dessert", "divide",
41
+ "duck", "elephant", "enclosed", "eye", "fabric", "face", "falcon", "fingre", "fish", "flail",
42
+ "folded", "foot", "galena", "giraffe", "he", "hit", "horn", "king", "leg", "length", "life",
43
+ "limits", "lion", "lizard", "loaf", "man", "mascot", "meet", "mother", "mouth", "musical",
44
+ "nile", "not", "now", "nurse", "nursing", "occur", "one", "owl", "pair", "papyrus", "pool",
45
+ "quailchick", "reed", "ring", "rope", "ruler", "sail", "sandal", "semen", "small", "snake",
46
+ "soldier", "star", "stick", "swallow", "this", "to", "turtle", "viper", "wall", "water", "you"
47
+ ]
48
+
49
+ # 4. Function to prepare input image for prediction
50
+ def prepare_image(img_path, target_size=(224, 224)):
51
+ img = image.load_img(img_path, target_size=target_size) # Load and resize image
52
+ img_array = image.img_to_array(img) # Convert to array
53
+ img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
54
+ img_array = img_array / 255.0 # Normalize
55
+ return img_array
56
+
57
+ # 5. Provide the path to your test image here
58
+ img_path = "path/to/your/hieroglyph_image.jpg"
59
+ img = prepare_image(img_path)
60
+
61
+ # 6. Run prediction
62
+ predictions = model.predict(img)
63
+ predicted_index = np.argmax(predictions)
64
+ predicted_label = class_names[predicted_index]
65
+
66
+ print(f"Predicted Hieroglyph: {predicted_label}")
67
+ ```
68