| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #!/bin/bash
- set -e
- root=$(cd $(dirname ${0})/..; pwd)
- build=${root}/build
- node_modules=${root}/node_modules
- src=${root}/src
- tools=${root}/tools
- third_party=${root}/third_party
- identifier=tensorflow
- virtualenv=${build}/virtualenv/${identifier}
- if [ $(which python3) ] && [ $(which pip3) ]; then
- python="python3"
- pip="pip3"
- else
- python="python"
- pip="pip"
- fi
- bold() {
- echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)"
- }
- git_sync () {
- mkdir -p "${third_party}"
- if [ -d "${third_party}/${1}" ]; then
- git -C "${third_party}/${1}" fetch -p --quiet
- git -C "${third_party}/${1}" reset --quiet --hard origin/master
- else
- echo "Clone ${2}..."
- git -C "${third_party}" clone --recursive ${2}
- fi
- }
- clean() {
- bold "tf clean"
- rm -rf ${virtualenv}
- rm -rf ${third_party}/${identifier}
- }
- sync() {
- bold "tf sync"
- git_sync tensorflow https://github.com/tensorflow/tensorflow.git
- }
- install() {
- bold "tf install"
- virtualenv --quiet -p ${python} ${virtualenv}
- source ${virtualenv}/bin/activate
- ${pip} install --quiet protobuf
- deactivate
- }
- schema() {
- bold "tf schema"
- ${node_modules}/protobufjs/bin/pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --keep-case --decode-text -r tf -o ${src}/tf-proto.js \
- ${third_party}/${identifier}/tensorflow/core/protobuf/saved_model.proto \
- ${third_party}/${identifier}/tensorflow/core/protobuf/meta_graph.proto \
- ${third_party}/${identifier}/tensorflow/core/protobuf/saver.proto \
- ${third_party}/${identifier}/tensorflow/core/framework/graph.proto \
- ${third_party}/${identifier}/tensorflow/core/framework/op_def.proto \
- ${third_party}/${identifier}/tensorflow/core/framework/tensor_shape.proto \
- ${third_party}/${identifier}/tensorflow/core/framework/types.proto \
- ${third_party}/${identifier}/tensorflow/core/framework/node_def.proto \
- ${third_party}/${identifier}/tensorflow/core/framework/versions.proto \
- ${third_party}/${identifier}/tensorflow/core/framework/function.proto \
- ${third_party}/${identifier}/tensorflow/core/framework/attr_value.proto \
- ${third_party}/${identifier}/tensorflow/core/framework/tensor.proto \
- ${third_party}/${identifier}/tensorflow/core/framework/resource_handle.proto
- }
- metadata() {
- bold "tf metadata"
- source ${virtualenv}/bin/activate
- pushd ${tools} > /dev/null
- protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/attr_value.proto --python_out=${tools}
- protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/tensor.proto --python_out=${tools}
- protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/types.proto --python_out=${tools}
- protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/tensor_shape.proto --python_out=${tools}
- protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/resource_handle.proto --python_out=${tools}
- protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/api_def.proto --python_out=${tools}
- protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/op_def.proto --python_out=${tools}
- touch ${tools}/tensorflow/__init__.py
- touch ${tools}/tensorflow/core/__init__.py
- touch ${tools}/tensorflow/core/framework/__init__.py
- ${python} tf-script.py
- rm -rf ${tools}/tensorflow
- popd > /dev/null
- deactivate
- }
- while [ "$#" != 0 ]; do
- command="$1" && shift
- case "${command}" in
- "clean") clean;;
- "sync") sync;;
- "install") install;;
- "schema") schema;;
- "metadata") metadata;;
- esac
- done
|