File size: 2,220 Bytes
c745b8c
 
 
 
 
 
7e71b49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
002ce59
 
 
 
 
 
 
 
 
4810827
7e71b49
 
 
 
 
 
 
eab80d2
7e71b49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: mit
language:
- en
base_model:
- google/efficientnet-b0
---

# Fall Detection Model using EfficientNetB0

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**.

---

## Model Architecture

- **Base Model**: EfficientNetB0 (`include_top=False`, pretrained on ImageNet)
- **Top Layers**:
  - GlobalAveragePooling2D
  - BatchNormalization
  - Dropout (0.4)
  - Dense (sigmoid activation)
- **Loss Function**: Binary Crossentropy
- **Optimizer**: Adam

The model was trained in two phases:
- Initial training with base model frozen (10 epochs)
- Fine-tuning with selective unfreezing (5 additional epochs)

Data augmentation techniques like `RandomFlip`, `RandomRotation`, and `RandomZoom` are used during training.

---

The repository contains **two versions of the model**:

1. **Keras `.h5` model**  
   - Full model for general use on machines with standard computational capacity.
2. **TensorFlow Lite `.tflite` model**  
   - Optimized for mobile and edge devices with limited computing power.

---

## How to Use

### 1. Load the Model from Hugging Face

```python
from huggingface_hub import from_pretrained_keras

# Replace with your actual repo path
model = from_pretrained_keras("author-username/model-name")
```

### 2. Run Inference on an Image

```python
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.efficientnet import preprocess_input
import numpy as np
import matplotlib.pyplot as plt

# Define image size
IMG_SIZE = (224, 224)

# Load and preprocess the image
img_path = "image_uri" # Your image uri (from the drive or local storage)
img = image.load_img(img_path, target_size=IMG_SIZE)
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array = preprocess_input(img_array)

# Display the image
plt.imshow(img)
plt.axis("off")
plt.show()

# Make prediction
prediction = model.predict(img_array)
print(prediction)

# Interpret prediction
if prediction[0] < 0.15:
    print("Prediction: 🚨 Fall Detected! 🚨")
else:
    print("Prediction: ✅ No Fall Detected.")
```