File size: 2,703 Bytes
e9eb33d 917c056 e9eb33d 7c098ec e9eb33d 7c098ec e9eb33d | 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 | # EfficientDet-D0
Object detection with EfficientDet-D0 trained on COCO. The model was originally
distributed as a frozen TensorFlow graph (`efficientdet-d0.pb`) and converted to
ONNX for use with OpenCV's DNN module. This is a **backbone-only** export: the
graph emits raw class logits and box regressions, while anchor generation, sigmoid,
box decoding and non-maximum suppression are performed in host code (see the demos).
## Model Details
- **Architecture**: EfficientDet-D0
- **Input**: RGB image, 512×512, raw uint8, NHWC layout (`image_arrays:0`, shape `[1, 512, 512, 3]`)
- **Output**: raw class logits (`concat:0`, shape `[1, 49104, 90]`) and box regression (`concat_1:0`, shape `[1, 49104, 4]`); anchor decode + NMS are done in host code, not in the graph
- **Framework**: ONNX (converted from the TensorFlow frozen graph via tf2onnx, opset 18)
- **Original weights**: https://www.dropbox.com/s/9mqp99fd2tpuqn6/efficientdet-d0.pb?dl=1
The graph outputs are per-anchor predictions only. The demos build the 49104 anchors
(5 pyramid levels × 9 anchors/cell), apply sigmoid to the logits, decode the box
regressions relative to the anchors, threshold on confidence and run NMS (IoU 0.6).
## Usage
### Python
```bash
python demo.py --model efficientdet-d0_2026jul.onnx --image example_outputs/input_image.png --output example_outputs/output_image.png --conf 0.4
```
Or import directly:
```python
import cv2
net = cv2.dnn.readNet("efficientdet-d0_2026jul.onnx")
# see demo.py for the full anchor decode + NMS pipeline
```
### C++
The C++ demo runs inference with OpenCV's DNN module. Adjust the OpenCV paths to your setup:
```bash
OCV=/path/to/opencv # OpenCV source tree
OCVBUILD=/path/to/opencv/build # OpenCV build directory (generated headers + libs)
g++ -std=c++17 demo.cpp -o demo \
-I$OCV/include \
-I$OCV/modules/core/include \
-I$OCV/modules/dnn/include \
-I$OCV/modules/imgproc/include \
-I$OCV/modules/imgcodecs/include \
-I$OCVBUILD \
-L$OCVBUILD/lib -Wl,-rpath,$OCVBUILD/lib -lopencv_dnn -lopencv_imgcodecs -lopencv_imgproc -lopencv_core
./demo --model efficientdet-d0_2026jul.onnx --image example_outputs/input_image.png --output example_outputs/output_image.png
```
## Conversion
The ONNX model was exported from the frozen TensorFlow graph with tf2onnx (opset 18)
via [convert_to_onnx.py](./convert_to_onnx.py) — input `image_arrays:0`, outputs
`concat:0` and `concat_1:0`, input shape overridden to `[1, 512, 512, 3]`. Requires
`tensorflow`, `tf2onnx`, and `onnx`.
```bash
python convert_to_onnx.py --pb ../pb/efficientdet-d0.pb
```
## License
See [LICENSE](./LICENSE) — released under the Apache License 2.0.
|