Update README.md
Browse files
README.md
CHANGED
|
@@ -4,4 +4,75 @@ language:
|
|
| 4 |
- en
|
| 5 |
base_model:
|
| 6 |
- google/efficientnet-b0
|
| 7 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
- en
|
| 5 |
base_model:
|
| 6 |
- google/efficientnet-b0
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
# Fall Detection Model using EfficientNetB0
|
| 10 |
+
|
| 11 |
+
This model detects whether a person has **fallen** in an input image using transfer learning with **EfficientNetB0**. It is trained for binary classification: **Fall Detected** or **No Fall Detected**.
|
| 12 |
+
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
## Model Architecture
|
| 16 |
+
|
| 17 |
+
- **Base Model**: EfficientNetB0 (`include_top=False`, pretrained on ImageNet)
|
| 18 |
+
- **Top Layers**:
|
| 19 |
+
- GlobalAveragePooling2D
|
| 20 |
+
- BatchNormalization
|
| 21 |
+
- Dropout (0.4)
|
| 22 |
+
- Dense (sigmoid activation)
|
| 23 |
+
- **Loss Function**: Binary Crossentropy
|
| 24 |
+
- **Optimizer**: Adam
|
| 25 |
+
|
| 26 |
+
The model was trained in two phases:
|
| 27 |
+
- Initial training with base model frozen (10 epochs)
|
| 28 |
+
- Fine-tuning with selective unfreezing (5 additional epochs)
|
| 29 |
+
|
| 30 |
+
Data augmentation techniques like `RandomFlip`, `RandomRotation`, and `RandomZoom` are used during training.
|
| 31 |
+
|
| 32 |
+
---
|
| 33 |
+
|
| 34 |
+
## 📦 How to Use
|
| 35 |
+
|
| 36 |
+
### 1. Load the Model from Hugging Face
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
from huggingface_hub import from_pretrained_keras
|
| 40 |
+
|
| 41 |
+
# Replace with your actual repo path
|
| 42 |
+
model = from_pretrained_keras("your-username/your-model-name")
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
### 2. Run Inference on an Image
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
from tensorflow.keras.preprocessing import image
|
| 49 |
+
from tensorflow.keras.applications.efficientnet import preprocess_input
|
| 50 |
+
import numpy as np
|
| 51 |
+
import matplotlib.pyplot as plt
|
| 52 |
+
|
| 53 |
+
# Define image size
|
| 54 |
+
IMG_SIZE = (224, 224)
|
| 55 |
+
|
| 56 |
+
# Load and preprocess the image
|
| 57 |
+
img_path = "image_uri" # Your image uri (from the drive or local storage)
|
| 58 |
+
img = image.load_img(img_path, target_size=IMG_SIZE)
|
| 59 |
+
img_array = image.img_to_array(img)
|
| 60 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 61 |
+
img_array = preprocess_input(img_array)
|
| 62 |
+
|
| 63 |
+
# Display the image
|
| 64 |
+
plt.imshow(img)
|
| 65 |
+
plt.axis("off")
|
| 66 |
+
plt.show()
|
| 67 |
+
|
| 68 |
+
# Make prediction
|
| 69 |
+
prediction = model.predict(img_array)
|
| 70 |
+
print(prediction)
|
| 71 |
+
|
| 72 |
+
# Interpret prediction
|
| 73 |
+
if prediction[0] < 0.15:
|
| 74 |
+
print("Prediction: 🚨 Fall Detected! 🚨")
|
| 75 |
+
else:
|
| 76 |
+
print("Prediction: ✅ No Fall Detected.")
|
| 77 |
+
```
|
| 78 |
+
|