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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
library_name: pytorch
|
| 4 |
+
tags:
|
| 5 |
+
- open-vocabulary
|
| 6 |
+
- computer-vision
|
| 7 |
+
- image-classification
|
| 8 |
+
- clip
|
| 9 |
+
- fruit-quality
|
| 10 |
+
- maturity-recognition
|
| 11 |
---
|
| 12 |
+
|
| 13 |
+
# OVFruitQG
|
| 14 |
+
|
| 15 |
+
OVFruitQG is a PyTorch release for open-vocabulary fruit and vegetable quality
|
| 16 |
+
and maturity assessment. The release includes model code, prompts, annotations,
|
| 17 |
+
paper result tables, and trained checkpoints for the main method and supervised
|
| 18 |
+
baselines.
|
| 19 |
+
|
| 20 |
+
## Included Assets
|
| 21 |
+
|
| 22 |
+
```text
|
| 23 |
+
OVFruitQG/
|
| 24 |
+
βββ checkpoints/ # Released model checkpoints
|
| 25 |
+
βββ configs/ # Split and baseline configs
|
| 26 |
+
βββ data/ # Annotation metadata and split protocol
|
| 27 |
+
βββ models/ # Public model implementations
|
| 28 |
+
βββ prompts/ # Prompt bank
|
| 29 |
+
βββ results/ # Paper table CSV files
|
| 30 |
+
βββ scripts/ # Training/evaluation/table scripts
|
| 31 |
+
βββ training/ # Training and metric utilities
|
| 32 |
+
βββ OVfruitQG dataset.zip # Dataset archive
|
| 33 |
+
βββ requirements.txt
|
| 34 |
+
βββ README.md
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
Large files such as `*.pt` checkpoints and the dataset zip should be stored with
|
| 38 |
+
Git LFS when this folder is uploaded to Hugging Face.
|
| 39 |
+
|
| 40 |
+
## Installation
|
| 41 |
+
|
| 42 |
+
```bash
|
| 43 |
+
pip install -r requirements.txt
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
The main OVFruitQG model uses a frozen CLIP backbone through Hugging Face
|
| 47 |
+
`transformers`. If the CLIP checkpoint is not already cached, it may be
|
| 48 |
+
downloaded automatically by `transformers`.
|
| 49 |
+
|
| 50 |
+
## Dataset
|
| 51 |
+
|
| 52 |
+
The dataset archive is provided as:
|
| 53 |
+
|
| 54 |
+
```text
|
| 55 |
+
OVfruitQG dataset.zip
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
Unzip it before running training/evaluation scripts. Annotation files and
|
| 59 |
+
dataset notes are also provided under `data/`.
|
| 60 |
+
|
| 61 |
+
The public split protocol is category-level and is described in:
|
| 62 |
+
|
| 63 |
+
```text
|
| 64 |
+
data/split_protocol.md
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
No per-image train/validation/test split CSV files are included in this release.
|
| 68 |
+
|
| 69 |
+
## Label Order
|
| 70 |
+
|
| 71 |
+
Quality labels:
|
| 72 |
+
|
| 73 |
+
```text
|
| 74 |
+
healthy, rotten, moldy, bruised, cracked
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
Maturity labels:
|
| 78 |
+
|
| 79 |
+
```text
|
| 80 |
+
unripe, ripe, overripe
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
The same orders are exported from `models` as `QUALITY_CLASSES` and
|
| 84 |
+
`MATURITY_CLASSES`.
|
| 85 |
+
|
| 86 |
+
## Checkpoints
|
| 87 |
+
|
| 88 |
+
The release includes four category splits:
|
| 89 |
+
|
| 90 |
+
| File pattern | Model |
|
| 91 |
+
|---|---|
|
| 92 |
+
| `checkpoints/OVFruitQG_split*.pt` | OVFruitQG / V3.1 |
|
| 93 |
+
| `checkpoints/ResNet_split*.pt` | Supervised ResNet50 |
|
| 94 |
+
| `checkpoints/ViT_split*.pt` | Supervised ViT-B/16 |
|
| 95 |
+
| `checkpoints/ResNet_LDB_fast_split*.pt` | V4.5 / ResNet LDB fast |
|
| 96 |
+
|
| 97 |
+
See `checkpoints/checkpoint_manifest.csv` for SHA256 hashes.
|
| 98 |
+
|
| 99 |
+
## Load a Checkpoint
|
| 100 |
+
|
| 101 |
+
```python
|
| 102 |
+
import torch
|
| 103 |
+
from PIL import Image
|
| 104 |
+
from torchvision import transforms
|
| 105 |
+
|
| 106 |
+
from models import build_model_for_checkpoint, load_checkpoint_into_model
|
| 107 |
+
|
| 108 |
+
checkpoint = "checkpoints/ResNet_split1.pt"
|
| 109 |
+
model = build_model_for_checkpoint(checkpoint)
|
| 110 |
+
load_checkpoint_into_model(model, checkpoint)
|
| 111 |
+
model.eval()
|
| 112 |
+
|
| 113 |
+
preprocess = transforms.Compose([
|
| 114 |
+
transforms.Resize((224, 224)),
|
| 115 |
+
transforms.ToTensor(),
|
| 116 |
+
transforms.Normalize(mean=[0.485, 0.456, 0.406],
|
| 117 |
+
std=[0.229, 0.224, 0.225]),
|
| 118 |
+
])
|
| 119 |
+
|
| 120 |
+
image = Image.open("path/to/crop.jpg").convert("RGB")
|
| 121 |
+
pixel_values = preprocess(image).unsqueeze(0)
|
| 122 |
+
|
| 123 |
+
with torch.no_grad():
|
| 124 |
+
outputs = model(pixel_values)
|
| 125 |
+
quality_id = outputs["quality_logits"].argmax(dim=-1).item()
|
| 126 |
+
maturity_id = outputs["maturity_logits"].argmax(dim=-1).item()
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
For OVFruitQG:
|
| 130 |
+
|
| 131 |
+
```python
|
| 132 |
+
from models import build_model, load_checkpoint_into_model
|
| 133 |
+
|
| 134 |
+
model = build_model(
|
| 135 |
+
"v3_1",
|
| 136 |
+
model_version="v3_1",
|
| 137 |
+
freeze_backbone=True,
|
| 138 |
+
allow_backbone_fallback=False,
|
| 139 |
+
)
|
| 140 |
+
load_checkpoint_into_model(model, "checkpoints/OVFruitQG_split1.pt")
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
For V4.5:
|
| 144 |
+
|
| 145 |
+
```python
|
| 146 |
+
from models import build_model_for_checkpoint, load_checkpoint_into_model
|
| 147 |
+
|
| 148 |
+
checkpoint = "checkpoints/ResNet_LDB_fast_split1.pt"
|
| 149 |
+
model = build_model_for_checkpoint(checkpoint)
|
| 150 |
+
load_checkpoint_into_model(model, checkpoint)
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
## Results
|
| 154 |
+
|
| 155 |
+
Paper result tables are stored in `results/`, including:
|
| 156 |
+
|
| 157 |
+
- Table 5: main recognition results
|
| 158 |
+
- Table 6: prompt retrieval and matching
|
| 159 |
+
- Table 7: seen/unseen generalization
|
| 160 |
+
- Table 8: ablation study
|
| 161 |
+
- Table 9: efficiency analysis
|
| 162 |
+
|
| 163 |
+
## License and Third-Party Models
|
| 164 |
+
|
| 165 |
+
The code is released under the MIT license. Third-party foundation models such
|
| 166 |
+
as CLIP, OpenCLIP, and Grounding DINO are not redistributed unless their files
|
| 167 |
+
are explicitly present in this folder. Use the official sources and respect
|
| 168 |
+
their original licenses.
|
| 169 |
+
|