Instructions to use zeromodels/efficientdet_d2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/efficientdet_d2 with ZeroModels:
# pip install -U zeromodels # ZeroModels is pure Keras 3, so pick a backend: "jax", "torch" or "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" from zeromodels import AutoZModel # AutoZModel reads the repo's model_type and loads the matching class. # For a task head use the matching loader, e.g. AutoZMImageClassify / AutoZMDetect / # AutoZMSemanticSegment / AutoZMTextGenerate (see zeromodels.auto). model = AutoZModel.from_weights("zeromodels/efficientdet_d2") - Keras
How to use zeromodels/efficientdet_d2 with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://zeromodels/efficientdet_d2") - Notebooks
- Google Colab
- Kaggle
File size: 5,187 Bytes
46cb2de | 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 | ---
pipeline_tag: object-detection
license: apache-2.0
library_name: zeromodels
tags:
- keras
- zeromodels
- efficientdet
- object-detection
- arxiv:1911.09070
- pytorch
- jax
- tf
---
## ***See [our collection](https://hf.co/collections/zeromodels/efficientdet) for all versions of EfficientDet.***
# Run EfficientDet with Keras 3: JAX, PyTorch, or TensorFlow
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/efficientdet/) [](https://hf.co/collections/zeromodels/efficientdet)
# zeromodels/efficientdet_d2
Paper: [EfficientDet: Scalable and Efficient Object Detection (arXiv:1911.09070)](https://arxiv.org/abs/1911.09070) · [HF Papers](https://huggingface.co/papers/1911.09070)
EfficientDet is a family of single-shot, anchor-based detectors built for a clean accuracy/compute trade-off. An EfficientNet-B2 backbone feeds a weighted bi-directional feature pyramid (BiFPN) that fuses multi-scale features with learnable per-input weights, and one shared class head and box head run over every pyramid level. This checkpoint runs at 768x768 over the 90 COCO categories.
For more details on the model, see Google's original [AutoML EfficientDet repository](https://github.com/google/automl/tree/master/efficientdet).
Pure-**Keras 3** conversion of Google AutoML's [EfficientDet](https://github.com/google/automl/tree/master/efficientdet) (`efficientdet-d2`) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
This is an **object detection** checkpoint (`EfficientDetDetect`): the backbone, BiFPN and shared heads emit per-anchor boxes that are decoded against anchors and NMS-filtered into detections.
## ✨ Quick start
```python
import os
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
from PIL import Image
from zeromodels.models.efficientdet import EfficientDetDetect, EfficientDetImageProcessor
model = EfficientDetDetect.from_weights("zeromodels/efficientdet_d2")
processor = EfficientDetImageProcessor.from_weights("zeromodels/efficientdet_d2")
image = Image.open("your_image.jpg").convert("RGB")
inputs = processor(image)
output = model(inputs["pixel_values"], training=False)
results = processor.post_process_object_detection(
output, threshold=0.3, target_sizes=inputs["original_sizes"]
)[0]
for score, name, box in zip(
results["scores"], results["label_names"], results["boxes"]
):
print(f"{name}: {float(score):.3f} {[round(float(v)) for v in box]}")
```
Load any EfficientDet variant the same way with `from_weights("zeromodels/<variant>")` (use `EfficientDetDetect` for detection, `EfficientDetModel` for the raw head outputs):
| Variant | Hub | Backbone | Input |
|---|---|---|---|
| `efficientdet_d0` | [`zeromodels/efficientdet_d0`](https://huggingface.co/zeromodels/efficientdet_d0) | EfficientNet-B0 | 512 |
| `efficientdet_d1` | [`zeromodels/efficientdet_d1`](https://huggingface.co/zeromodels/efficientdet_d1) | EfficientNet-B1 | 640 |
| `efficientdet_d2` | [`zeromodels/efficientdet_d2`](https://huggingface.co/zeromodels/efficientdet_d2) | EfficientNet-B2 | 768 |
| `efficientdet_d3` | [`zeromodels/efficientdet_d3`](https://huggingface.co/zeromodels/efficientdet_d3) | EfficientNet-B3 | 896 |
| `efficientdet_d4` | [`zeromodels/efficientdet_d4`](https://huggingface.co/zeromodels/efficientdet_d4) | EfficientNet-B4 | 1024 |
| `efficientdet_d5` | [`zeromodels/efficientdet_d5`](https://huggingface.co/zeromodels/efficientdet_d5) | EfficientNet-B5 | 1280 |
| `efficientdet_d6` | [`zeromodels/efficientdet_d6`](https://huggingface.co/zeromodels/efficientdet_d6) | EfficientNet-B6 | 1280 |
| `efficientdet_d7` | [`zeromodels/efficientdet_d7`](https://huggingface.co/zeromodels/efficientdet_d7) | EfficientNet-B6 | 1536 |
## Tips
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
- Detection: `EfficientDetDetect` + `post_process_object_detection` (try `threshold=0.3`-`0.4`).
- NMS is class-agnostic by default (one box per object); pass `class_agnostic=False` for per-class NMS.
- `EfficientDetModel.from_weights(...)` loads the same weights without the decode head, returning raw per-level `class_outputs` / `box_outputs`.
- Larger variants take a bigger input (D0 512 up to D7 1536); each side must be divisible by 128.
- Community / fine-tuned repos hosted in the zeromodels format load with `from_weights("<org>/<repo>")`.
- Weights are resolution-independent: pass `image_size=N` (a multiple of 128) to `from_weights` to run at a custom size.
- See [EfficientDet docs](https://imvision12.github.io/ZeroModels/efficientdet/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
## Special Thanks
A huge thank you to the Google Brain / AutoML authors (Mingxing Tan, Ruoming Pang, Quoc V. Le) for creating and releasing EfficientDet.
License: Apache 2.0.
|