Created
February 14, 2017 09:42
-
-
Save waichee/54310f4253a8a2f84359ef202c4f217f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script is used to compile Tensorflow Serving protobuf definition into Python | |
# The generated definitions in Python are stored in the tensorflow_serving_apis folder | |
# Usage: | |
# ./compile_ts_serving_proto.sh 333325e413e9680d67ae90196fa123f5271fcf615 | |
# | |
: ${1?”Error. Please provide the Tensorflow Serving git commit hash/branch name. Usage: ./compile_ts_serving_proto.sh my_awesome_branch “} | |
script_dir=”$( cd “$( dirname “${BASH_SOURCE[0]}” )” && pwd )” | |
ts_git_revision=$1 #branch/release or commit hash | |
local_ts_api_dir=”${script_dir}/tensorflow_serving_apis/” #directory that stores the compiled python proto definition | |
rm -rf build | |
mkdir build && cd build | |
# Check out the Tensor Serving for the revision required | |
git clone — recurse-submodules https://github.com/tensorflow/serving.git | |
cd “${script_dir}/build/serving” && git checkout ${ts_git_revision} | |
# Organize the directory to match the proto imports expected | |
mv tensorflow tensorflow_base && mv tensorflow_base/tensorflow tensorflow | |
echo “Checked out Tensorflow Serving revision: ${ts_git_revision}” | |
# Copy the Protobuf definitions from TS Serving APIs | |
cp tensorflow_serving/apis/*.py “${local_ts_api_dir}/tensorflow_serving/apis/” | |
# Download Protobuf Compiler | |
# Note this assume that you are running the script from Mac. Change the download path for the protobuf if you’re on different operating system | |
PROTOBUF_VERSION=$(grep ‘set(PROTOBUF_URL’ “${script_dir}/build/serving/tensorflow/contrib/cmake/external/protobuf.cmake” | grep -oE ‘v[0–9.]+’) | |
echo “Downloading Protobuf version: ${PROTOBUF_VERSION}” | |
curl -sLOS “https://github.com/google/protobuf/releases/download/${PROTOBUF_VERSION}/protoc-${PROTOBUF_VERSION#"v"}-osx-x86_64.zip" | |
unzip “protoc-${PROTOBUF_VERSION#”v”}-osx-x86_64.zip” | |
echo “Compiling the Protobuf definition” | |
bin/protoc — proto_path=”${script_dir}/build/serving” — python_out=${local_ts_api_dir} “${script_dir}/build/serving/tensorflow_serving/apis/model.proto” | |
bin/protoc — proto_path=”${script_dir}/build/serving” — python_out=${local_ts_api_dir} “${script_dir}/build/serving/tensorflow_serving/apis/predict.proto” | |
bin/protoc — proto_path=”${script_dir}/build/serving” — python_out=${local_ts_api_dir} “${script_dir}/build/serving/tensorflow_serving/apis/prediction_service.proto” | |
touch ${script_dir}/build/serving/setup.py | |
touch ${script_dir}/build/serving/tensorflow_serving/__init__.py | |
touch ${script_dir}/build/serving/tensorflow_serving/apis/__init__.py | |
cp ${local_ts_api_dir}/*.py ${script_dir}/build/serving/tensorflow_serving/apis/ | |
echo “All done. Check this directory for the compiled python definitions: ${local_ts_api_dir}” |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment