Skip to content

Instantly share code, notes, and snippets.

bazel build tensorflow/tools/quantization:graph_to_dot
bazel-bin/tensorflow/tools/quantization/graph_to_dot \
--graph=/tmp/tensorflow_inception_graph.pb \
--dot_output=/tmp/tensorflow_inception_graph.dot
mkdir /tmp/model/
curl\
"https://storage.googleapis.com/download.tensorflow.org/ \
models/inception_dec_2015.zip" \
-o /tmp/model/inception_dec_2015.zip
unzip /tmp/model/inception_dec_2015.zip -d /tmp/model/
bazel build tensorflow/tools/graph_transforms:transform_graph
bazel-bin/tensorflow/tools/graph_transforms/transform_graph \
--in_graph="/tmp/model/tensorflow_inception_graph.pb" \
--out_graph="/tmp/model/quantized_graph.pb" --inputs='Mul:0' \
--outputs='softmax:0' \
--transforms='add_default_attributes strip_unused_nodes(type=float, shape="1,299,299,3") remove_nodes(op=Identity, op=CheckNumerics) fold_old_batch_norms quantize_weights quantize_nodes strip_unused_nodes'
bazel build tensorflow/examples/label_image:label_image
bazel-bin/tensorflow/examples/label_image/label_image \
--input_mean=128 --input_std=128 --input_layer=Mul \
--output_layer=softmax --graph=/tmp/model/quantized_graph.pb \
--labels=/tmp/model/imagenet_comp_graph_label_strings.txt
bazel-bin/tensorflow/tools/graph_transforms/transform_graph \
--in_graph=/tmp/model/quantized_graph.pb \
--out_graph=/tmp/model/logged_quantized_graph.pb \
--inputs=Mul \
--outputs=softmax \
--transforms='insert_logging(op=RequantizationRange, show_name=true, message="__requant_min_max:")'
bazel-bin/tensorflow/examples/label_image/label_image \
--input_mean=128 --input_std=128 \
--input_layer=Mul --output_layer=softmax \
--graph=/tmp/model/logged_quantized_graph.pb \
--labels=/tmp/model/imagenet_comp_graph_label_strings.txt 2> \
/tmp/model/logged_ranges.txt
cat /tmp/model/logged_ranges.txt
bazel-bin/tensorflow/tools/graph_transforms/transform_graph \
--in_graph=/tmp/model/quantized_graph.pb \
--out_graph=/tmp/model/ranged_quantized_graph.pb \
--inputs=Mul \
--outputs=softmax \
--transforms='freeze_requantization_ranges(min_max_log_file=/tmp/model/logged_ranges.txt)'
bazel-bin/tensorflow/examples/label_image/label_image \
--input_mean=128 --input_std=128 --input_layer=Mul \
--output_layer=softmax \
--graph=/tmp/model/ranged_quantized_graph.pb \
--labels=/tmp/model/imagenet_comp_graph_label_strings.txt
@petewarden
petewarden / preprocessor.cc
Created October 29, 2018 05:28
Reference implementation of speech preprocessing
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,

TensorFlow Lite for Microcontrollers

This an experimental port of TensorFlow Lite aimed at micro controllers and other devices with only kilobytes of memory. It doesn't require any operating system support, any standard C or C++ libraries, or dynamic memory allocation, so it's designed to be portable even to 'bare metal' systems. The core runtime fits in 16KB on a Cortex M3, and with enough operators to run a speech keyword detection model, takes up a total of 22KB.

Table of Contents