Skip to content

Commit

Permalink
Merge pull request webmachinelearning#55 from Honry/add-ssd
Browse files Browse the repository at this point in the history
Add SSD MobileNet V1 coco examples
  • Loading branch information
huningxin authored Jul 2, 2021
2 parents 95226f6 + f8dfac0 commit 52242e5
Show file tree
Hide file tree
Showing 8 changed files with 1,022 additions and 18 deletions.
36 changes: 35 additions & 1 deletion object_detection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,41 @@

Object detection is the process of detecting instances of semantic objects of a pre-defined classes in digital images and videos.

This example shows how the Tiny YOLO v2 model from [YAD2K project](https://github.com/allanzelener/YAD2K) and [ONNX model zoo](https://github.com/onnx/models/blob/master/vision/object_detection_segmentation/tiny-yolov2/model/tinyyolov2-8.tar.gz) may be implemented by using the WebNN API. (Note: these two models are all trained on the [Pascal VOC](http://host.robots.ox.ac.uk/pascal/VOC/) dataset.)
This example shows how the Tiny YOLO v2 model from [YAD2K project](https://github.com/allanzelener/YAD2K) and [ONNX model zoo](https://github.com/onnx/models/blob/master/vision/object_detection_segmentation/tiny-yolov2/model/tinyyolov2-8.tar.gz), [SSD MobileNet V1 models](http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_2018_01_28.tar.gz) may be implemented by using the WebNN API. (Note: Tiny YOLO V2 models are trained on the [Pascal VOC](http://host.robots.ox.ac.uk/pascal/VOC/) dataset, SSD MobileNet V1 models are trained on the [COCO](https://cocodataset.org/#home) dataset.)


### How to Generate SSD MobileNet V1 models

Since the original [SSD MobileNet V1 model](http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_2018_01_28.tar.gz) contains customized preprocess and postprocess graphs, we only implement a cut model with WebNN API, you can generate the cut model via following commands:

Here is the converter command for removing the preprocess and postprocess graphs by using tensorflow's [`optimize_for_inference`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/optimize_for_inference.py) tool:

```
python3 -m tensorflow.python.tools.optimize_for_inference \
--input=./frozen_inference_graph.pb \
--output=./frozen_inference_graph_stripped.pb --frozen_graph=True \
--input_names=Preprocessor/sub \
--output_names='concat,concat_1' \
--alsologtostderr
```

Use ['TensorFlow Lite converter'](https://www.tensorflow.org/lite/convert) tool to convert frozen graph to tflite model:

```
tflite_convert \
--graph_def_file=./frozen_inference_graph_stripped.pb \
--output_file=./ssd_mobilenet_v1_coco.tflite \
--input_format=TENSORFLOW_GRAPHDEF --output_format=TFLITE \
--input_shapes=1,300,300,3 --input_arrays=Preprocessor/sub \
--enable_v1_converter \
--output_arrays='concat,concat_1' \
--inference_type=FLOAT --logtostderr
```

Use ['tflite2onnx'](https://github.com/jackwish/tflite2onnx) tool to convert tflite model to onnx model:
```
tflite2onnx ssd_mobilenet_v1_coco.tflite ssd_mobilenet_v1_coco.onnx
```

### Usage

Expand Down
3 changes: 3 additions & 0 deletions object_detection/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<label class="btn btn-outline-info btn-sm mr-2 active">
<input type="radio" name="model" id="tinyyolov2" autocomplete="off" checked>Tiny Yolo V2
</label>
<label class="btn btn-outline-info btn-sm mr-2">
<input type="radio" name="model" id="ssdmobilenetv1" autocomplete="off">SSD MobileNet V1
</label>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion object_detection/labels/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
The label file `pascal.classes.txt` comes from [YAD2K](https://github.com/allanzelener/YAD2K), which is licensed under MIT.
The label files `pascal_classes.txt` and `coco_classes.txt` come from [YAD2K](https://github.com/allanzelener/YAD2K), which is licensed under MIT.
91 changes: 91 additions & 0 deletions object_detection/labels/coco_classes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
???
person
bicycle
car
motorcycle
airplane
bus
train
truck
boat
traffic light
fire hydrant
???
stop sign
parking meter
bench
bird
cat
dog
horse
sheep
cow
elephant
bear
zebra
giraffe
???
backpack
umbrella
???
???
handbag
tie
suitcase
frisbee
skis
snowboard
sports ball
kite
baseball bat
baseball glove
skateboard
surfboard
tennis racket
bottle
???
wine glass
cup
fork
knife
spoon
bowl
banana
apple
sandwich
orange
broccoli
carrot
hot dog
pizza
donut
cake
chair
couch
potted plant
bed
???
dining table
???
???
toilet
???
tv
laptop
mouse
remote
keyboard
cell phone
microwave
oven
toaster
sink
refrigerator
???
book
clock
vase
scissors
teddy bear
hair drier
toothbrush
Loading

0 comments on commit 52242e5

Please sign in to comment.