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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: NanoVLM
|
| 3 |
+
emoji: π€
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: "5.0.0"
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# NanoVLM
|
| 14 |
+
|
| 15 |
+
NanoVLM is a lightweight Vision-Language Model (VLM) designed for efficient multimodal understanding. It combines image encoding and language generation to answer questions about images while remaining suitable for resource-constrained environments.
|
| 16 |
+
|
| 17 |
+
## Features
|
| 18 |
+
|
| 19 |
+
- πΌοΈ Image understanding
|
| 20 |
+
- π¬ Visual Question Answering (VQA)
|
| 21 |
+
- β‘ Lightweight architecture
|
| 22 |
+
- π€ Hugging Face compatible
|
| 23 |
+
- π Training and inference notebook included
|
| 24 |
+
|
| 25 |
+
## Model Architecture
|
| 26 |
+
|
| 27 |
+
The model consists of:
|
| 28 |
+
|
| 29 |
+
- Vision Encoder
|
| 30 |
+
- Projection Layer
|
| 31 |
+
- Language Model
|
| 32 |
+
- Cross-modal fusion between visual and textual representations
|
| 33 |
+
|
| 34 |
+
```
|
| 35 |
+
Image
|
| 36 |
+
β
|
| 37 |
+
Vision Encoder
|
| 38 |
+
β
|
| 39 |
+
Projection Layer
|
| 40 |
+
β
|
| 41 |
+
Language Model
|
| 42 |
+
β
|
| 43 |
+
Generated Answer
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
## Installation
|
| 47 |
+
|
| 48 |
+
Clone the repository
|
| 49 |
+
|
| 50 |
+
```bash
|
| 51 |
+
git clone https://github.com/your-username/nanovlm.git
|
| 52 |
+
cd nanovlm
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
Install dependencies
|
| 56 |
+
|
| 57 |
+
```bash
|
| 58 |
+
pip install -r requirements.txt
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
## Usage
|
| 62 |
+
|
| 63 |
+
### Inference
|
| 64 |
+
|
| 65 |
+
```python
|
| 66 |
+
from PIL import Image
|
| 67 |
+
|
| 68 |
+
image = Image.open("example.jpg")
|
| 69 |
+
|
| 70 |
+
question = "What is in this image?"
|
| 71 |
+
|
| 72 |
+
answer = model.chat(image, question)
|
| 73 |
+
|
| 74 |
+
print(answer)
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
### Notebook
|
| 78 |
+
|
| 79 |
+
Open the notebook:
|
| 80 |
+
|
| 81 |
+
```
|
| 82 |
+
NanoVlm_fixed.ipynb
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
and execute all cells.
|
| 86 |
+
|
| 87 |
+
## Dataset
|
| 88 |
+
|
| 89 |
+
The model can be trained on datasets such as:
|
| 90 |
+
|
| 91 |
+
- COCO Captions
|
| 92 |
+
- VQAv2
|
| 93 |
+
- Flickr30k
|
| 94 |
+
- Custom datasets
|
| 95 |
+
|
| 96 |
+
## Training
|
| 97 |
+
|
| 98 |
+
Example:
|
| 99 |
+
|
| 100 |
+
```bash
|
| 101 |
+
python train.py
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
Adjust hyperparameters such as:
|
| 105 |
+
|
| 106 |
+
- Learning rate
|
| 107 |
+
- Batch size
|
| 108 |
+
- Number of epochs
|
| 109 |
+
- Image resolution
|
| 110 |
+
|
| 111 |
+
## Results
|
| 112 |
+
|
| 113 |
+
| Metric | Value |
|
| 114 |
+
|---------|------:|
|
| 115 |
+
| Accuracy | -- |
|
| 116 |
+
| BLEU | -- |
|
| 117 |
+
| CIDEr | -- |
|
| 118 |
+
|
| 119 |
+
*(Replace with your experimental results.)*
|
| 120 |
+
|
| 121 |
+
## Repository Structure
|
| 122 |
+
|
| 123 |
+
```
|
| 124 |
+
.
|
| 125 |
+
βββ NanoVlm_fixed.ipynb
|
| 126 |
+
βββ app.py
|
| 127 |
+
βββ requirements.txt
|
| 128 |
+
βββ README.md
|
| 129 |
+
βββ images/
|
| 130 |
+
βββ model/
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
## Requirements
|
| 134 |
+
|
| 135 |
+
- Python 3.10+
|
| 136 |
+
- PyTorch
|
| 137 |
+
- Transformers
|
| 138 |
+
- Pillow
|
| 139 |
+
- Torchvision
|
| 140 |
+
- Gradio (optional)
|
| 141 |
+
|
| 142 |
+
Install:
|
| 143 |
+
|
| 144 |
+
```bash
|
| 145 |
+
pip install torch torchvision transformers pillow gradio
|
| 146 |
+
```
|
| 147 |
+
|
| 148 |
+
## Citation
|
| 149 |
+
|
| 150 |
+
If you use this project, please cite:
|
| 151 |
+
|
| 152 |
+
```bibtex
|
| 153 |
+
@misc{nanovlm2026,
|
| 154 |
+
title={NanoVLM: A Lightweight Vision-Language Model},
|
| 155 |
+
author={Your Name},
|
| 156 |
+
year={2026},
|
| 157 |
+
publisher={Hugging Face}
|
| 158 |
+
}
|
| 159 |
+
```
|
| 160 |
+
|
| 161 |
+
## License
|
| 162 |
+
|
| 163 |
+
MIT License
|
| 164 |
+
|
| 165 |
+
## Acknowledgements
|
| 166 |
+
|
| 167 |
+
This project builds upon the excellent work of:
|
| 168 |
+
|
| 169 |
+
- Hugging Face Transformers
|
| 170 |
+
- PyTorch
|
| 171 |
+
- Vision Transformer (ViT)
|
| 172 |
+
- Large Language Models research
|
| 173 |
+
|
| 174 |
+
---
|
| 175 |
+
|
| 176 |
+
β If you find this project useful, consider giving it a star on GitHub or liking it on Hugging Face.
|