# 📦 pt2tflite – Convert PyTorch `.pt` Models to TFLite

`pt2tflite` is a simple Python library that automates the complete conversion pipeline from **YOLOv8 PyTorch `.pt` models** to **TensorFlow Lite `.tflite`** models — ready for mobile and embedded applications like **Flutter**, **Android**, and **Edge AI**.

---

## 🚀 Features

- 🔁 Converts `.pt` → `.onnx` → TensorFlow → `.tflite`
- 🧠 Supports YOLOv8 models (`n`, `s`, `m`, `l`, `x`)
- ⚙️ Optional `float16` quantization for smaller, faster models
- ✅ Compatible with Python 3.8
- 💡 Designed for use in Flutter and other mobile inference apps

---

## 🔧 Installation

Install from PyPI:

```bash
pip install pt2tflite
```

Or install from source:

```bash
git clone https://github.com/hamidhosen42/pt2tflite.git
cd pt2tflite
pip install -r requirements.txt
```

---

## 💻 Usage

### Python Code

```python
from pt2tflite.converter import convert_pt_to_tflite

convert_pt_to_tflite(
    pt_path="yolov8n.pt",
    output_path="yolov8n.tflite",
    quantize=True  # Optional: float16 quantization
)
```

---

## 📂 Output

After conversion, you'll get a TFLite model like:

```
yolov8n.tflite
```

✅ Ready to use with `tflite_flutter`, `TensorFlow Lite`, or other mobile inference engines.

---

## 📄 Requirements

This tool depends on:

- `ultralytics`
- `torch`
- `onnx`
- `onnx-tf`
- `tensorflow==2.10.1`

Install all with:

```bash
pip install -r requirements.txt
```

---

## 🛠️ Example Workflow

```text
1. Load YOLOv8 .pt model using Ultralytics
2. Export to ONNX
3. Convert ONNX to TensorFlow SavedModel using onnx-tf
4. Convert to TFLite using TensorFlow Lite converter
5. (Optional) Apply float16 quantization
```

---

## 🛡 License

MIT License — use it freely in personal or commercial projects.

---

## 🤝 Contributing

Contributions, issues, and feature requests are welcome!  
Feel free to open an issue or submit a pull request.

---

## 🌐 Author

**Md. Hamid Hosen**  
[GitHub](https://github.com/hamidhosen42) • [PyPI](https://pypi.org/project/pt2tflite/)