File size: 2,266 Bytes
e9eb33d 53892e2 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 | # TensorFlow Inception
Image classification with the Inception v1 (GoogLeNet) network trained on ImageNet.
The model was originally distributed as a frozen TensorFlow graph
(`tensorflow_inception_graph.pb`) and converted to ONNX for use with OpenCV's DNN module.
## Model Details
- **Architecture**: Inception v1 / GoogLeNet
- **Input**: RGB image, 224×224, raw 0–255 float, NHWC layout (`input:0`, shape `[1, 224, 224, 3]`)
- **Output**: ImageNet class scores, softmax over 1008 classes (`softmax2:0`)
- **Framework**: ONNX (converted from the TensorFlow frozen graph via tf2onnx, opset 18)
- **Original weights**: https://github.com/petewarden/tf_ios_makefile_example/raw/master/data/tensorflow_inception_graph.pb
## Usage
### Python
```bash
python demo.py --model tensorflow_inception_graph_2026jul.onnx --image example_outputs/input_image.png --output example_outputs/output_image.png
```
Or import directly:
```python
import cv2
net = cv2.dnn.readNet("tensorflow_inception_graph_2026jul.onnx")
# see demo.py for the full inference pipeline
```
### C++
The C++ demo runs inference with OpenCV's DNN module (default engine — no ONNX Runtime
needed). 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 tensorflow_inception_graph_2026jul.onnx --image example_outputs/input_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) — inputs `input:0`, outputs `softmax2:0`,
input shape overridden to `[1, 224, 224, 3]`. Requires `tensorflow`, `tf2onnx`, and `onnx`.
```bash
python convert_to_onnx.py --pb ../pb/tensorflow_inception_graph.pb
```
## License
See [LICENSE](./LICENSE) — the model is released by the TensorFlow Authors under the Apache License 2.0.
|