Skip to content

Commit dd041d4

Browse files
author
Nikhil Thorat
authoredMar 24, 2018
Add a deploy script to deploy all or one example to GCP. (tensorflow#31)
This PR: - Adds deploy.sh which deploys all or 1 examples by going into directories, calling `yarn`, `yarn build` and then copying the `dist` folder to GCP. This is in bash so we don't need to make a package.json in the root of the repository. - Adds links in the README to the statically hosted examples. - Adds an `await tf.nextFrame()` to MNIST train loop which allows UI to update The script can either be used without arguments, which deploys all demos: ```./deploy.sh``` Or you can pass a single argument specifying a single demo to deploy: ```./deploy.sh mnist``` This script assumes that a directory in this repo corresponds to an example. I also created an "assets" folder in our GCP bucket, which mirrors this repo. Our bucket then looks like: gs://tfjs-examples/assets/webcam-transfer-learning/pacman.js gs://tfjs-examples/assets/... gs://tfjs-examples/addition-rnn/dist/index.html gs://tfjs-examples/mnist/dist/index.html ...
1 parent f7c8479 commit dd041d4

File tree

23 files changed

+93
-16
lines changed

23 files changed

+93
-16
lines changed
 

‎addition-rnn/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Note: this example is a port of the Keras addition RNN example with a UI.
88

99
You can find the original Keras python code [here](https://github.com/keras-team/keras/blob/master/examples/addition_rnn.py).
1010

11+
[See this example live!](https://storage.googleapis.com/tfjs-examples/addition-rnn/dist/index.html)

‎addition-rnn/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"scripts": {
1313
"watch": "NODE_ENV=development parcel --no-hmr --open index.html ",
14-
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url /"
14+
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url ./"
1515
},
1616
"devDependencies": {
1717
"babel-plugin-transform-runtime": "~6.23.0",

‎deploy.sh

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2018 Google Inc. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# =============================================================================
16+
17+
# This script deploys examples to GCP so they can be statically hosted.
18+
#
19+
# The script can either be used without arguments, which deploys all demos:
20+
# ./deploy.sh
21+
# Or you can pass a single argument specifying a single demo to deploy:
22+
# ./deploy.sh mnist
23+
#
24+
# This script assumes that a directory in this repo corresponds to an example.
25+
#
26+
# Example directories should have:
27+
# - package.json
28+
# - `yarn build` script which generates a dist/ folder in the example directory.
29+
30+
if [ -z "$1" ]
31+
then
32+
EXAMPLES=$(ls -d */)
33+
else
34+
EXAMPLES=$1
35+
if [ ! -d "$EXAMPLES" ]; then
36+
echo "Error: Could not find example $1"
37+
echo "Make sure the first argument to this script matches the example dir"
38+
exit 1
39+
fi
40+
fi
41+
42+
for i in $EXAMPLES; do
43+
cd ${i}
44+
# Strip any trailing slashes.
45+
EXAMPLE_NAME=${i%/}
46+
47+
echo "building ${EXAMPLE_NAME}..."
48+
yarn
49+
yarn build
50+
gsutil mkdir -p gs://tfjs-examples/$EXAMPLE_NAME
51+
gsutil mkdir -p gs://tfjs-examples/$EXAMPLE_NAME/dist
52+
gsutil -m cp dist/* gs://tfjs-examples/$EXAMPLE_NAME/dist
53+
cd ..
54+
done
55+
56+
gsutil -m setmeta -h "Cache-Control:private" "gs://tfjs-examples/**.html"
57+
gsutil -m setmeta -h "Cache-Control:private" "gs://tfjs-examples/**.css"
58+
gsutil -m setmeta -h "Cache-Control:private" "gs://tfjs-examples/**.js"

‎iris/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ To launch the demo, do
2020
yarn
2121
yarn watch
2222
```
23+
24+
[See this example live!](https://storage.googleapis.com/tfjs-examples/iris/dist/index.html)

‎iris/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"scripts": {
1313
"watch": "NODE_ENV=development parcel --no-hmr --open index.html ",
14-
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url /"
14+
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url ./"
1515
},
1616
"devDependencies": {
1717
"babel-plugin-transform-runtime": "~6.23.0",

‎mnist-core/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ This example shows you how to train MNIST only using the [TensorFlow.js core]
66
Note: currently the entire dataset of MNIST images is stored in a PNG image we have
77
sprited, and the code in `data.js` is responsible for converting it into
88
`Tensor`s. This will become much simpler in the near future.
9+
10+
[See this example live!](https://storage.googleapis.com/tfjs-examples/mnist-core/dist/index.html)

‎mnist-core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"scripts": {
1212
"watch": "NODE_ENV=development parcel --no-hmr --open index.html ",
13-
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url /"
13+
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url ./"
1414
},
1515
"devDependencies": {
1616
"babel-plugin-transform-runtime": "~6.23.0",

‎mnist/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ be reduced by computing accuracy over fewer examples less often.
1111
Note: currently the entire dataset of MNIST images is stored in a PNG image we have
1212
sprited, and the code in `data.js` is responsible for converting it into
1313
`Tensor`s. This will become much simpler in the near future.
14+
15+
[See this example live!](https://storage.googleapis.com/tfjs-examples/mnist/dist/index.html)

‎mnist/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ async function train() {
102102
testBatch.xs.dispose();
103103
testBatch.labels.dispose();
104104
}
105+
106+
await tf.nextFrame();
105107
}
106108
}
107109

‎mnist/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"scripts": {
1313
"watch": "NODE_ENV=development parcel --no-hmr --open index.html ",
14-
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url /"
14+
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url ./"
1515
},
1616
"devDependencies": {
1717
"babel-plugin-transform-runtime": "~6.23.0",

‎mobilenet/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ Keras pretrained mobilenet model and hosted online for your convenience.
88

99
If you want, you can port your own mobilenet model by using the Keras converter script which
1010
can be found [here](https://github.com/tensorflow/tfjs-layers/blob/master/scripts/keras_model_converter.py).
11+
12+
[See this example live!](https://storage.googleapis.com/tfjs-examples/mobilenet/dist/index.html)

‎mobilenet/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"scripts": {
1212
"watch": "NODE_ENV=development parcel --no-hmr --open index.html ",
13-
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url /"
13+
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url ./"
1414
},
1515
"devDependencies": {
1616
"babel-plugin-transform-runtime": "~6.23.0",

‎polynomial-regression-core/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# TensorFlow.js Example: Fitting a curve to synthetic data
22

3-
This example shows you how to use TensorFlow.js operations and optimizers (the lower level api) to write a simple model that learns the coefficients of polynomial that we want to use to describe our data. In this toy example, we generate synthetic data by adding some noise to a polynomial function. Then starting with random coefficients, we train a model to learn the true coefficients that data was generated with.
3+
This example shows you how to use TensorFlow.js operations and optimizers (the lower level api) to write a simple model that learns the coefficients of polynomial that we want to use to describe our data. In this toy example, we generate synthetic data by adding some noise to a polynomial function. Then starting with random coefficients, we train a model to learn the true coefficients that data was generated with.
4+
5+
[See this example live!](https://storage.googleapis.com/tfjs-examples/dist/polynomial-regression-core/index.html)

‎polynomial-regression-core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"scripts": {
1414
"watch": "NODE_ENV=development parcel --no-hmr --open index.html ",
15-
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url /"
15+
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url ./"
1616
},
1717
"devDependencies": {
1818
"babel-plugin-transform-runtime": "~6.23.0",

‎polynomial-regression/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
This example creates a synthetic polynomial dataset and fits the polynomial
44
curve using the layers API.
5+
6+
[See this example live!](https://storage.googleapis.com/tfjs-examples/polynomial-regression/dist/index.html)

‎polynomial-regression/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"scripts": {
1212
"watch": "NODE_ENV=development parcel --no-hmr --open index.html ",
13-
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url /"
13+
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url ./"
1414
},
1515
"devDependencies": {
1616
"babel-plugin-transform-runtime": "~6.23.0",

‎sentiment/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ To launch the demo, do
2222
yarn
2323
yarn watch
2424
```
25+
26+
[See this example live!](https://storage.googleapis.com/tfjs-examples/sentiment/dist/index.html)

‎sentiment/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"scripts": {
1313
"watch": "NODE_ENV=development parcel --no-hmr --open index.html ",
14-
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url /"
14+
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url ./"
1515
},
1616
"devDependencies": {
1717
"babel-plugin-transform-runtime": "~6.23.0",

‎translation/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ To launch the demo, do
1616
yarn
1717
yarn watch
1818
```
19+
20+
[See this example live!](https://storage.googleapis.com/tfjs-examples/translation/dist/index.html)

‎translation/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"scripts": {
1313
"watch": "NODE_ENV=development parcel --no-hmr --open index.html ",
14-
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url /"
14+
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url ./"
1515
},
1616
"devDependencies": {
1717
"babel-plugin-transform-runtime": "~6.23.0",

‎webcam-transfer-learning/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ In this example, we'll use a pretrained [MobileNet](https://github.com/tensorflo
77
using an internal mobilenet activation to predict 4 different classes from the
88
webcam defined by the user.
99

10-
You can find this demo here: ...
10+
[See this example live!](https://storage.googleapis.com/tfjs-examples/webcam-transfer-learning/dist/index.html)

‎webcam-transfer-learning/index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
1919
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.cyan-teal.min.css" />
2020
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
21-
<script src="https://storage.googleapis.com/tfjs-examples/webcam-transfer-learning/modernizr-1.5.min.js"></script>
2221
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
23-
22+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
2423
<title>Webcam Pacman</title>
2524

2625
<style>
@@ -209,7 +208,7 @@
209208
height: 186px;
210209
position: relative;
211210
margin-bottom: 9px;
212-
background: url('https://storage.googleapis.com/tfjs-examples/webcam-transfer-learning/bck.png');
211+
background: url('https://storage.googleapis.com/tfjs-examples/assets/webcam-transfer-learning/bck.png');
213212
}
214213
#logo-l {
215214
width: 200px;
@@ -354,6 +353,7 @@
354353
<div id="train-status"></div>
355354
</div>
356355
</div>
356+
<div id="copyright">PAC-MAN™ & © BANDAI NAMCO Entertainment Inc.</div>
357357
</div>
358-
<script src="https://storage.googleapis.com/tfjs-examples/webcam-transfer-learning/pacman-google.js"></script>
358+
<script src="https://storage.googleapis.com/tfjs-examples/assets/webcam-transfer-learning/pacman-google.js"></script>
359359
<script src="index.js"></script>

‎webcam-transfer-learning/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"scripts": {
1313
"watch": "NODE_ENV=development parcel --no-hmr --open index.html ",
14-
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url /"
14+
"build": "NODE_ENV=production parcel build index.html --no-minify --public-url ./"
1515
},
1616
"devDependencies": {
1717
"babel-plugin-transform-runtime": "~6.23.0",

0 commit comments

Comments
 (0)