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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Android-Projekt: ID Card Classification & Embedding Models
|
| 2 |
+
|
| 3 |
+
[](LICENSE)
|
| 4 |
+
[](https://www.tensorflow.org/)
|
| 5 |
+
[](https://developer.android.com/)
|
| 6 |
+
|
| 7 |
+
This repository contains machine learning models for ID card detection, classification, and embedding generation, optimized for Android deployment.
|
| 8 |
+
|
| 9 |
+
## π¦ Models Overview
|
| 10 |
+
|
| 11 |
+
| Model File | Format | Size | Description | Use Case |
|
| 12 |
+
|------------|--------|------|-------------|----------|
|
| 13 |
+
| `id_classifier.tflite` | TFLite | 1.11 MB | Lightweight ID classifier | Mobile inference |
|
| 14 |
+
| `id_card_embedding_model.tflite` | TFLite | 1.26 MB | Compact embedding model | Mobile feature extraction |
|
| 15 |
+
| `id_card_classifier.keras` | Keras | 5.23 MB | Full Keras classifier | Training/fine-tuning |
|
| 16 |
+
| `id_classifier_saved_model.h5` | H5 | 8.85 MB | H5 format classifier | Legacy compatibility |
|
| 17 |
+
| `id_classifier_saved_model.keras` | Keras | 12.7 MB | Complete Keras model | Development/evaluation |
|
| 18 |
+
| `id_card_embedding_model.keras` | Keras | 191 MB | High-accuracy embedding model | Server-side processing |
|
| 19 |
+
|
| 20 |
+
## π Quick Start
|
| 21 |
+
|
| 22 |
+
### For Android Development (TFLite)
|
| 23 |
+
|
| 24 |
+
```kotlin
|
| 25 |
+
// Load TFLite model in Android
|
| 26 |
+
val model = Interpreter(loadModelFile("id_classifier.tflite"))
|
| 27 |
+
|
| 28 |
+
// Prepare input
|
| 29 |
+
val inputBuffer = ByteBuffer.allocateDirect(inputSize)
|
| 30 |
+
val outputBuffer = ByteBuffer.allocateDirect(outputSize)
|
| 31 |
+
|
| 32 |
+
// Run inference
|
| 33 |
+
model.run(inputBuffer, outputBuffer)
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
### For Python/Training (Keras)
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
from tensorflow.keras.models import load_model
|
| 40 |
+
|
| 41 |
+
# Load full Keras model
|
| 42 |
+
model = load_model("id_card_classifier.keras")
|
| 43 |
+
|
| 44 |
+
# Make predictions
|
| 45 |
+
predictions = model.predict(input_data)
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
### For TFLite Interpreter
|
| 49 |
+
|
| 50 |
+
```python
|
| 51 |
+
import tensorflow as tf
|
| 52 |
+
|
| 53 |
+
# Load TFLite model
|
| 54 |
+
interpreter = tf.lite.Interpreter(model_path="id_card_embedding_model.tflite")
|
| 55 |
+
interpreter.allocate_tensors()
|
| 56 |
+
|
| 57 |
+
# Get input and output details
|
| 58 |
+
input_details = interpreter.get_input_details()
|
| 59 |
+
output_details = interpreter.get_output_details()
|
| 60 |
+
|
| 61 |
+
# Run inference
|
| 62 |
+
interpreter.set_tensor(input_details[0]['index'], input_data)
|
| 63 |
+
interpreter.invoke()
|
| 64 |
+
output = interpreter.get_tensor(output_details[0]['index'])
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
## π₯ Download & Installation
|
| 68 |
+
|
| 69 |
+
### Clone with Git LFS
|
| 70 |
+
|
| 71 |
+
```bash
|
| 72 |
+
git lfs install
|
| 73 |
+
git clone https://huggingface.co/Ajay007001/Android-Projekt
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
### Download Specific Model
|
| 77 |
+
|
| 78 |
+
```python
|
| 79 |
+
from huggingface_hub import hf_hub_download
|
| 80 |
+
|
| 81 |
+
model_path = hf_hub_download(
|
| 82 |
+
repo_id="Ajay007001/Android-Projekt",
|
| 83 |
+
filename="id_classifier.tflite"
|
| 84 |
+
)
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
## π§ Model Details
|
| 88 |
+
|
| 89 |
+
### ID Classifier
|
| 90 |
+
- **Purpose**: Classify different types of ID cards
|
| 91 |
+
- **Input**: Preprocessed ID card images
|
| 92 |
+
- **Output**: Classification probabilities
|
| 93 |
+
- **Recommended for**: Real-time mobile applications
|
| 94 |
+
|
| 95 |
+
### Embedding Model
|
| 96 |
+
- **Purpose**: Generate feature embeddings for ID cards
|
| 97 |
+
- **Input**: Raw or preprocessed ID card images
|
| 98 |
+
- **Output**: High-dimensional feature vectors
|
| 99 |
+
- **Recommended for**: Similarity search, verification systems
|
| 100 |
+
|
| 101 |
+
## π‘ Integration Tips
|
| 102 |
+
|
| 103 |
+
### Android Studio Setup
|
| 104 |
+
|
| 105 |
+
1. Place `.tflite` files in `app/src/main/assets/`
|
| 106 |
+
2. Add TensorFlow Lite dependency:
|
| 107 |
+
|
| 108 |
+
```gradle
|
| 109 |
+
implementation 'org.tensorflow:tensorflow-lite:2.14.0'
|
| 110 |
+
implementation 'org.tensorflow:tensorflow-lite-support:0.4.4'
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
3. Load model in your Activity/Fragment
|
| 114 |
+
|
| 115 |
+
### Memory Considerations
|
| 116 |
+
|
| 117 |
+
β οΈ **Important**: The `id_card_embedding_model.keras` (191 MB) requires significant memory. For mobile deployment, use the `.tflite` versions instead.
|
| 118 |
+
|
| 119 |
+
## π Performance
|
| 120 |
+
|
| 121 |
+
- **TFLite models**: Optimized for mobile inference (<50ms on modern Android devices)
|
| 122 |
+
- **Keras models**: Full precision for training and evaluation
|
| 123 |
+
- **Recommended**: Use `.tflite` for production Android apps
|
| 124 |
+
|
| 125 |
+
## π οΈ Development
|
| 126 |
+
|
| 127 |
+
### Fine-tuning
|
| 128 |
+
|
| 129 |
+
```python
|
| 130 |
+
# Load base model
|
| 131 |
+
base_model = load_model("id_card_classifier.keras")
|
| 132 |
+
|
| 133 |
+
# Freeze layers
|
| 134 |
+
for layer in base_model.layers[:-5]:
|
| 135 |
+
layer.trainable = False
|
| 136 |
+
|
| 137 |
+
# Add custom layers
|
| 138 |
+
# ... your custom architecture
|
| 139 |
+
|
| 140 |
+
# Compile and train
|
| 141 |
+
model.compile(optimizer='adam', loss='categorical_crossentropy')
|
| 142 |
+
model.fit(train_data, epochs=10)
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
### Convert to TFLite
|
| 146 |
+
|
| 147 |
+
```python
|
| 148 |
+
import tensorflow as tf
|
| 149 |
+
|
| 150 |
+
# Load Keras model
|
| 151 |
+
model = tf.keras.models.load_model("id_card_classifier.keras")
|
| 152 |
+
|
| 153 |
+
# Convert to TFLite
|
| 154 |
+
converter = tf.lite.TFLiteConverter.from_keras_model(model)
|
| 155 |
+
converter.optimizations = [tf.lite.Optimize.DEFAULT]
|
| 156 |
+
tflite_model = converter.convert()
|
| 157 |
+
|
| 158 |
+
# Save
|
| 159 |
+
with open("model.tflite", "wb") as f:
|
| 160 |
+
f.write(tflite_model)
|
| 161 |
+
```
|
| 162 |
+
|
| 163 |
+
## π Notes
|
| 164 |
+
|
| 165 |
+
- All models use Git LFS for efficient storage and download
|
| 166 |
+
- TFLite models are quantized for optimal mobile performance
|
| 167 |
+
- Keras models retain full precision for training purposes
|
| 168 |
+
- Compatible with TensorFlow 2.x
|
| 169 |
+
|
| 170 |
+
## π€ Contributing
|
| 171 |
+
|
| 172 |
+
Contributions are welcome! Please feel free to submit issues or pull requests.
|
| 173 |
+
|
| 174 |
+
## π License
|
| 175 |
+
|
| 176 |
+
[Specify your license here - e.g., MIT, Apache 2.0]
|
| 177 |
+
|
| 178 |
+
## π§ Contact
|
| 179 |
+
|
| 180 |
+
For questions or support, please open an issue in this repository.
|
| 181 |
+
|
| 182 |
+
---
|
| 183 |
+
|
| 184 |
+
**Note**: These models were originally part of a larger Android project. The large embedding model (`id_card_embedding_model.keras`) exceeded GitHub's 100MB limit and has been migrated to Hugging Face for easier access and version control.
|
| 185 |
+
---
|
| 186 |
+
license: mit
|
| 187 |
+
---
|