lines) {
85 | int lineNum = 0;
86 | for (final String line : lines) {
87 | drawText(canvas, posX, posY - getTextSize() * (lines.size() - lineNum - 1), line);
88 | // drawText(canvas, posX, posY+ getTextSize() * (lines.size() - lineNum - 1), line);
89 |
90 | ++lineNum;
91 | }
92 | }
93 |
94 | public void setInteriorColor(final int color) {
95 | interiorPaint.setColor(color);
96 | }
97 |
98 | public void setExteriorColor(final int color) {
99 | exteriorPaint.setColor(color);
100 | }
101 |
102 | public float getTextSize() {
103 | return textSize;
104 | }
105 |
106 | public void setAlpha(final int alpha) {
107 | interiorPaint.setAlpha(alpha);
108 | exteriorPaint.setAlpha(alpha);
109 | }
110 |
111 | public void getTextBounds(
112 | final String line, final int index, final int count, final Rect lineBounds) {
113 | interiorPaint.getTextBounds(line, index, count, lineBounds);
114 | }
115 |
116 | public void setTextAlign(final Align align) {
117 | interiorPaint.setTextAlign(align);
118 | exteriorPaint.setTextAlign(align);
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/java/me/ndres/tflitedemo/CameraActivity.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 | ==============================================================================*/
15 |
16 | package me.ndres.tflitedemo;
17 |
18 | import android.app.Activity;
19 | import android.os.Bundle;
20 |
21 | /** Main {@code Activity} class for the Camera app. */
22 | public class CameraActivity extends Activity {
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_camera);
28 | if (null == savedInstanceState) {
29 | getFragmentManager()
30 | .beginTransaction()
31 | .replace(R.id.container, Camera2BasicFragment.newInstance())
32 | .commit();
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/java/me/ndres/tflitedemo/GpuDelegateHelper.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 | ==============================================================================*/
15 |
16 | package me.ndres.tflitedemo;
17 |
18 | import org.tensorflow.lite.Delegate;
19 |
20 | /**
21 | * Helper class for {@code GpuDelegate}.
22 | *
23 | * WARNING: This is an experimental API and subject to change.
24 | */
25 | public class GpuDelegateHelper {
26 | private GpuDelegateHelper() {}
27 |
28 | /** Checks whether {@code GpuDelegate} is available. */
29 | public static boolean isGpuDelegateAvailable() {
30 | try {
31 | Class.forName("org.tensorflow.lite.experimental.GpuDelegate");
32 | return true;
33 | } catch (Exception e) {
34 | return false;
35 | }
36 | }
37 |
38 | /** Returns an instance of {@code GpuDelegate} if available. */
39 | public static Delegate createGpuDelegate() {
40 | try {
41 | return Class.forName("org.tensorflow.lite.experimental.GpuDelegate")
42 | .asSubclass(Delegate.class)
43 | .getDeclaredConstructor()
44 | .newInstance();
45 | } catch (Exception e) {
46 | throw new IllegalStateException(e);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/java/me/ndres/tflitedemo/ImageClassifierFloatInception.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 | ==============================================================================*/
15 |
16 | package me.ndres.tflitedemo;
17 |
18 | import android.app.Activity;
19 |
20 | import java.io.IOException;
21 |
22 | /**
23 | * This classifier works with the Inception-v3 slim model.
24 | * It applies floating point inference rather than using a quantized model.
25 | */
26 | public class ImageClassifierFloatInception extends ImageClassifier {
27 |
28 | /**
29 | * The inception net requires additional normalization of the used input.
30 | */
31 | private static final int IMAGE_MEAN = 128;
32 | private static final float IMAGE_STD = 128.0f;
33 |
34 | /**
35 | * An array to hold inference results, to be feed into Tensorflow Lite as outputs.
36 | * This isn't part of the super class, because we need a primitive array here.
37 | */
38 | private float[][] labelProbArray = null;
39 |
40 | /**
41 | * Initializes an {@code ImageClassifier}.
42 | *
43 | * @param activity
44 | */
45 | ImageClassifierFloatInception(Activity activity) throws IOException {
46 | super(activity);
47 | labelProbArray = new float[1][getNumLabels()];
48 | }
49 |
50 | @Override
51 | protected String getModelPath() {
52 | // you can download this file from
53 | // https://storage.googleapis.com/download.tensorflow.org/models/tflite/inception_v3_slim_2016_android_2017_11_10.zip
54 | return "inceptionv3_slim_2016.tflite";
55 | }
56 |
57 | @Override
58 | protected String getLabelPath() {
59 | return "labels_imagenet_slim.txt";
60 | }
61 |
62 | @Override
63 | protected int getImageSizeX() {
64 | return 299;
65 | }
66 |
67 | @Override
68 | protected int getImageSizeY() {
69 | return 299;
70 | }
71 |
72 | @Override
73 | protected int getNumBytesPerChannel() {
74 | // a 32bit float value requires 4 bytes
75 | return 4;
76 | }
77 |
78 | @Override
79 | protected void addPixelValue(int pixelValue) {
80 | imgData.putFloat((((pixelValue >> 16) & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
81 | imgData.putFloat((((pixelValue >> 8) & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
82 | imgData.putFloat(((pixelValue & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
83 | }
84 |
85 | @Override
86 | protected float getProbability(int labelIndex) {
87 | return labelProbArray[0][labelIndex];
88 | }
89 |
90 | @Override
91 | protected void setProbability(int labelIndex, Number value) {
92 | labelProbArray[0][labelIndex] = value.floatValue();
93 | }
94 |
95 | @Override
96 | protected float getNormalizedProbability(int labelIndex) {
97 | // TODO the following value isn't in [0,1] yet, but may be greater. Why?
98 | return getProbability(labelIndex);
99 | }
100 |
101 | @Override
102 | protected void runInference() {
103 | tflite.run(imgData, labelProbArray);
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/java/me/ndres/tflitedemo/ImageClassifierFloatMobileNet.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 | ==============================================================================*/
15 |
16 | package me.ndres.tflitedemo;
17 |
18 | import android.app.Activity;
19 | import java.io.IOException;
20 |
21 | /** This classifier works with the float MobileNet model. */
22 | public class ImageClassifierFloatMobileNet extends ImageClassifier {
23 |
24 | /**
25 | * An array to hold inference results, to be feed into Tensorflow Lite as outputs. This isn't part
26 | * of the super class, because we need a primitive array here.
27 | */
28 | private float[][] labelProbArray = null;
29 |
30 | /**
31 | * Initializes an {@code ImageClassifierFloatMobileNet}.
32 | *
33 | * @param activity
34 | */
35 | ImageClassifierFloatMobileNet(Activity activity) throws IOException {
36 | super(activity);
37 | labelProbArray = new float[1][getNumLabels()];
38 | }
39 |
40 | @Override
41 | protected String getModelPath() {
42 | // you can download this file from
43 | // see build.gradle for where to obtain this file. It should be auto
44 | // downloaded into assets.
45 | return "converted_model.tflite";
46 | }
47 |
48 | @Override
49 | protected String getLabelPath() {
50 | return "labels_emotion.txt";
51 | }
52 |
53 | @Override
54 | protected int getImageSizeX() {
55 | return 48;
56 | }
57 |
58 | @Override
59 | protected int getImageSizeY() {
60 | return 48;
61 | }
62 |
63 | @Override
64 | protected int getNumBytesPerChannel() {
65 | return 4; // Float.SIZE / Byte.SIZE;
66 | }
67 |
68 | @Override
69 | protected void addPixelValue(int pixelValue) {
70 | float ret = (((pixelValue >> 16) & 0xFF) + ((pixelValue >> 8) & 0xFF) + (pixelValue & 0xFF)) / 3.0f / 127.0f;
71 | imgData.putFloat(ret - 1.0f);
72 | }
73 |
74 | @Override
75 | protected float getProbability(int labelIndex) {
76 | return labelProbArray[0][labelIndex];
77 | }
78 |
79 | @Override
80 | protected void setProbability(int labelIndex, Number value) {
81 | labelProbArray[0][labelIndex] = value.floatValue();
82 | }
83 |
84 | @Override
85 | protected float getNormalizedProbability(int labelIndex) {
86 | return labelProbArray[0][labelIndex];
87 | }
88 |
89 | @Override
90 | protected void runInference() {
91 | tflite.run(imgData, labelProbArray);
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/java/me/ndres/tflitedemo/ImageClassifierQuantizedMobileNet.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 | ==============================================================================*/
15 |
16 | package me.ndres.tflitedemo;
17 |
18 | import android.app.Activity;
19 | import java.io.IOException;
20 |
21 | /**
22 | * This classifier works with the quantized MobileNet model.
23 | */
24 | public class ImageClassifierQuantizedMobileNet extends ImageClassifier {
25 |
26 | /**
27 | * An array to hold inference results, to be feed into Tensorflow Lite as outputs.
28 | * This isn't part of the super class, because we need a primitive array here.
29 | */
30 | private byte[][] labelProbArray = null;
31 |
32 | /**
33 | * Initializes an {@code ImageClassifier}.
34 | *
35 | * @param activity
36 | */
37 | ImageClassifierQuantizedMobileNet(Activity activity) throws IOException {
38 | super(activity);
39 | labelProbArray = new byte[1][getNumLabels()];
40 | }
41 |
42 | @Override
43 | protected String getModelPath() {
44 | // you can download this file from
45 | // see build.gradle for where to obtain this file. It should be auto
46 | // downloaded into assets.
47 | return "mobilenet_v1_1.0_224_quant.tflite";
48 | }
49 |
50 | @Override
51 | protected String getLabelPath() {
52 | return "labels_emotion.txt";
53 | }
54 |
55 | @Override
56 | protected int getImageSizeX() {
57 | return 224;
58 | }
59 |
60 | @Override
61 | protected int getImageSizeY() {
62 | return 224;
63 | }
64 |
65 | @Override
66 | protected int getNumBytesPerChannel() {
67 | // the quantized model uses a single byte only
68 | return 1;
69 | }
70 |
71 | @Override
72 | protected void addPixelValue(int pixelValue) {
73 | imgData.put((byte) ((pixelValue >> 16) & 0xFF));
74 | imgData.put((byte) ((pixelValue >> 8) & 0xFF));
75 | imgData.put((byte) (pixelValue & 0xFF));
76 | }
77 |
78 | @Override
79 | protected float getProbability(int labelIndex) {
80 | return labelProbArray[0][labelIndex];
81 | }
82 |
83 | @Override
84 | protected void setProbability(int labelIndex, Number value) {
85 | labelProbArray[0][labelIndex] = value.byteValue();
86 | }
87 |
88 | @Override
89 | protected float getNormalizedProbability(int labelIndex) {
90 | return (labelProbArray[0][labelIndex] & 0xff) / 255.0f;
91 | }
92 |
93 | @Override
94 | protected void runInference() {
95 | tflite.run(imgData, labelProbArray);
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/java/me/ndres/tflitedemo/OverlayView.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 | ==============================================================================*/
15 |
16 | package me.ndres.tflitedemo;
17 |
18 | import android.content.Context;
19 | import android.graphics.Canvas;
20 | import android.util.AttributeSet;
21 | import android.view.View;
22 |
23 | import java.util.LinkedList;
24 | import java.util.List;
25 |
26 | /**
27 | * A simple View providing a render callback to other classes.
28 | */
29 | public class OverlayView extends View {
30 | private final List callbacks = new LinkedList();
31 |
32 | public OverlayView(final Context context, final AttributeSet attrs) {
33 | super(context, attrs);
34 | }
35 |
36 | /**
37 | * Interface defining the callback for client classes.
38 | */
39 | public interface DrawCallback {
40 | public void drawCallback(final Canvas canvas);
41 | }
42 |
43 | public void addCallback(final DrawCallback callback) {
44 | callbacks.add(callback);
45 | }
46 |
47 | @Override
48 | public synchronized void draw(final Canvas canvas) {
49 | for (final DrawCallback callback : callbacks) {
50 | callback.drawCallback(canvas);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/drawable-hdpi/ic_action_info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tf_lite_android/demo/app/src/main/res/drawable-hdpi/ic_action_info.png
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tf_lite_android/demo/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/drawable-hdpi/tile.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tf_lite_android/demo/app/src/main/res/drawable-hdpi/tile.9.png
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/drawable-mdpi/ic_action_info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tf_lite_android/demo/app/src/main/res/drawable-mdpi/ic_action_info.png
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tf_lite_android/demo/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/drawable-xhdpi/ic_action_info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tf_lite_android/demo/app/src/main/res/drawable-xhdpi/ic_action_info.png
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tf_lite_android/demo/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/drawable-xxhdpi/ic_action_info.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tf_lite_android/demo/app/src/main/res/drawable-xxhdpi/ic_action_info.png
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tf_lite_android/demo/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/drawable-xxhdpi/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tf_lite_android/demo/app/src/main/res/drawable-xxhdpi/logo.png
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/drawable/item_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/layout-land/fragment_camera2_basic.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
23 |
24 |
29 |
30 |
35 |
36 |
42 |
43 |
51 |
56 |
57 |
64 |
65 |
69 |
70 |
71 |
72 |
77 |
78 |
85 |
86 |
90 |
91 |
92 |
93 |
97 |
98 |
105 |
106 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/layout-v26/fragment_camera2_basic.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
22 |
27 |
28 |
38 |
39 |
46 |
47 |
58 |
59 |
60 |
61 |
70 |
71 |
75 |
76 |
83 |
84 |
91 |
92 |
93 |
94 |
99 |
100 |
107 |
108 |
112 |
113 |
114 |
115 |
116 |
121 |
122 |
129 |
130 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/layout/activity_camera.xml:
--------------------------------------------------------------------------------
1 |
16 |
23 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/layout/fragment_camera2_basic.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
22 |
23 |
24 |
28 |
29 |
34 |
35 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
57 |
58 |
69 |
70 |
71 |
72 |
82 |
83 |
87 |
88 |
95 |
96 |
103 |
104 |
105 |
106 |
111 |
112 |
119 |
120 |
124 |
125 |
126 |
127 |
128 |
133 |
134 |
141 |
142 |
146 |
147 |
148 |
149 |
150 |
151 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/layout/listview_row.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
16 |
17 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/values-sw600dp/template-dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 | @dimen/margin_huge
22 | @dimen/margin_medium
23 |
24 |
25 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/values-sw600dp/template-styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/values-v11/template-styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/values-v21/base-colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/values-v21/base-template-styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/values/base-strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | TfLite Camera Demo
20 |
21 |
29 |
30 | Threads:
31 |
32 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | #cc4285f4
19 | #aaaaaa
20 | #eeaa55
21 | #eeeeee
22 |
23 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 | Picture
18 | Info
19 | This sample needs camera permission.
20 | This device doesn\'t support Camera2 API.
21 | NN:On
22 | NN:Off
23 | Use NNAPI
24 | tflite
25 | NNAPI
26 | GPU
27 | CPU
28 | Model
29 | Device
30 | mobilenet v1 quant;
31 | mobilenet v1 float;;
32 |
33 |
34 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/values/template-dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 | 4dp
22 | 8dp
23 | 16dp
24 | 32dp
25 | 64dp
26 |
27 |
28 |
29 | @dimen/margin_medium
30 | @dimen/margin_medium
31 |
32 |
33 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/app/src/main/res/values/template-styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
34 |
35 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | google()
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.3.0'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tf_lite_android/demo/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/tf_lite_android/demo/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Feb 05 16:26:59 COT 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
7 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/tf_lite_android/demo/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/tfjs/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | [
4 | "env",
5 | {
6 | "esmodules": false,
7 | "targets": {
8 | "browsers": [
9 | "> 3%"
10 | ]
11 | }
12 | }
13 | ]
14 | ],
15 | "plugins": [
16 | "transform-runtime"
17 | ]
18 | }
--------------------------------------------------------------------------------
/tfjs/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .cache
3 | dist
4 |
--------------------------------------------------------------------------------
/tfjs/cat.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tfjs/cat.jpg
--------------------------------------------------------------------------------
/tfjs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | TensorFlow.js: Using a pretrained MobileNet
5 |
6 |
7 |
14 |
15 |
16 |
17 |
45 |
46 |
47 |
48 |
49 | TensorFlow.js: Emotion detection
50 |
51 |
52 |
53 | Description
54 |
55 |
56 |
57 |
58 |
59 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/tfjs/index.js:
--------------------------------------------------------------------------------
1 | import * as tf from '@tensorflow/tfjs';
2 | import * as faceapi from 'face-api.js';
3 |
4 | const isDev = process.env.NODE_ENV === 'development';
5 |
6 | const MOBILENET_MODEL_PATH = isDev ? 'http://localhost:1235/emotion_detection/model.json' : './emotion_detection/model.json';
7 | const DETECTION_MODEL_PATH = isDev ? 'http://localhost:1235/face_detection': './face_detection';
8 | const FACE_EXPRESSIONS = ["angry","disgust","scared", "happy", "sad", "surprised","neutral"]
9 |
10 |
11 | const IMAGE_SIZE = 48;
12 |
13 | let mobilenet;
14 | const mobilenetDemo = async () => {
15 | status('Loading model...');
16 |
17 | mobilenet = await tf.loadGraphModel(MOBILENET_MODEL_PATH);
18 |
19 | // Warmup the model. This isn't necessary, but makes the first prediction
20 | // faster. Call `dispose` to release the WebGL memory allocated for the return
21 | // value of `predict`.
22 | mobilenet.predict(tf.zeros([1, IMAGE_SIZE, IMAGE_SIZE, 1])).dispose();
23 |
24 | status('');
25 | };
26 |
27 | /**
28 | * Given an image element, makes a prediction through mobilenet returning the
29 | * probabilities of the top K classes.
30 | */
31 | async function predict(imgElement) {
32 | let img = await tf.browser.fromPixels(imgElement, 3).toFloat();
33 |
34 | const logits = tf.tidy(() => {
35 | // tf.fromPixels() returns a Tensor from an image element.
36 | img = tf.image.resizeBilinear(img, [IMAGE_SIZE, IMAGE_SIZE]);
37 | img = img.mean(2);
38 | const offset = tf.scalar(127.5);
39 | // Normalize the image from [0, 255] to [-1, 1].
40 | const normalized = img.sub(offset).div(offset);
41 |
42 | // Reshape to a single-element batch so we can pass it to predict.
43 | const batched = normalized.reshape([1, IMAGE_SIZE, IMAGE_SIZE, 1]);
44 |
45 | // Make a prediction through mobilenet.
46 | return mobilenet.predict(batched);
47 | });
48 |
49 | return logits
50 | }
51 |
52 | /**
53 | * Computes the probabilities of the topK classes given logits by computing
54 | * softmax to get probabilities and then sorting the probabilities.
55 | * @param logits Tensor representing the logits from MobileNet.
56 | * @param topK The number of top predictions to show.
57 | */
58 | export async function getTopClass(values) {
59 |
60 | const valuesAndIndices = [];
61 | for (let i = 0; i < values.length; i++) {
62 | valuesAndIndices.push({value: values[i], index: i});
63 | }
64 | valuesAndIndices.sort((a, b) => {
65 | return b.value - a.value;
66 | });
67 |
68 | return valuesAndIndices[0]
69 | }
70 |
71 | //
72 | // UI
73 | //
74 |
75 |
76 | const demoStatusElement = document.getElementById('status');
77 | const status = msg => demoStatusElement.innerText = msg;
78 | const predictionsElement = document.getElementById('predictions');
79 |
80 |
81 |
82 | window.onPlay = async function onPlay() {
83 | const video = document.getElementById('video');
84 | const overlay = document.getElementById('overlay');
85 |
86 | const detection = await faceapi.detectSingleFace(video, new faceapi.TinyFaceDetectorOptions())
87 |
88 | if (detection) {
89 |
90 | const faceCanvases = await faceapi.extractFaces(video, [detection])
91 |
92 | const prediction = await predict(faceCanvases[0]);
93 |
94 | const values = await prediction.data();
95 | const topClass = await getTopClass(values)
96 |
97 | // TODO(eliot): fix this hack. we should not use private properties
98 | detection._className = FACE_EXPRESSIONS[topClass.index]
99 | detection._classScore = topClass.value
100 | drawDetections(video, overlay, detection)
101 |
102 | }
103 |
104 | setTimeout(window.onPlay, 100)
105 | };
106 |
107 | function resizeCanvasAndResults(dimensions, canvas, results) {
108 | const { width, height } = dimensions instanceof HTMLVideoElement
109 | ? faceapi.getMediaDimensions(dimensions)
110 | : dimensions
111 | canvas.width = width
112 | canvas.height = height
113 |
114 | // resize detections (and landmarks) in case displayed image is smaller than
115 | // original size
116 | return faceapi.resizeResults(results, { width, height })
117 | }
118 |
119 | function drawDetections(dimensions, canvas, detections) {
120 | const resizedDetections = resizeCanvasAndResults(dimensions, canvas, detections)
121 | faceapi.drawDetection(canvas, resizedDetections)
122 | }
123 |
124 | async function init() {
125 | var video = document.getElementById('video');
126 |
127 | await faceapi.loadTinyFaceDetectorModel(DETECTION_MODEL_PATH)
128 | const stream = await navigator.mediaDevices.getUserMedia({ video: {} })
129 | video.srcObject = stream
130 | };
131 |
132 | window.onload = async function () {
133 | await mobilenetDemo()
134 | init()
135 | }
136 |
--------------------------------------------------------------------------------
/tfjs/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "tfjs-examples-mobilenet",
3 | "version": "0.1.0",
4 | "description": "",
5 | "main": "index.js",
6 | "license": "Apache-2.0",
7 | "private": true,
8 | "engines": {
9 | "node": ">=8.9.0"
10 | },
11 | "dependencies": {
12 | "@tensorflow/tfjs": "1.0.4",
13 | "face-api.js": "0.19.0",
14 | "parcel-plugin-static-files-copy": "^2.0.0"
15 | },
16 | "scripts": {
17 | "watch": "./serve.sh",
18 | "build": "cross-env NODE_ENV=production parcel build index.html --no-minify --public-url ./",
19 | "link-local": "yalc link",
20 | "postinstall": "yarn upgrade --pattern @tensorflow"
21 | },
22 | "devDependencies": {
23 | "babel-core": "^6.26.3",
24 | "babel-plugin-transform-runtime": "^6.23.0",
25 | "babel-preset-env": "^1.7.0",
26 | "clang-format": "~1.2.2",
27 | "cross-env": "^5.1.6",
28 | "http-server": "~0.10.0",
29 | "parcel-bundler": "~1.10.3",
30 | "yalc": "~1.0.0-pre.22"
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tfjs/serve.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Copyright 2018 Google LLC. All Rights Reserved.
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 | # =============================================================================
17 |
18 | # This script starts two HTTP servers on different ports:
19 | # * Port 1234 (using parcel) serves HTML and JavaScript.
20 | # * Port 1235 (using http-server) serves pretrained model resources.
21 | #
22 | # The reason for this arrangement is that Parcel currently has a limitation that
23 | # prevents it from serving the pretrained models; see
24 | # https://github.com/parcel-bundler/parcel/issues/1098. Once that issue is
25 | # resolved, a single Parcel server will be sufficient.
26 |
27 | NODE_ENV=development
28 | RESOURCE_PORT=1235
29 |
30 |
31 | echo Starting the pretrained model server...
32 | node_modules/http-server/bin/http-server dist --cors -p "${RESOURCE_PORT}" > /dev/null & HTTP_SERVER_PID=$!
33 |
34 | echo Starting the example html/js server...
35 | # This uses port 1234 by default.
36 | NODE_ENV=development node_modules/parcel-bundler/bin/cli.js serve -d dist index.html --open --no-hmr --public-url /
37 |
38 | # When the Parcel server exits, kill the http-server too.
39 | kill $HTTP_SERVER_PID
40 |
41 |
--------------------------------------------------------------------------------
/tfjs/static/emotion_detection/group1-shard1of4.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tfjs/static/emotion_detection/group1-shard1of4.bin
--------------------------------------------------------------------------------
/tfjs/static/emotion_detection/group1-shard2of4.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tfjs/static/emotion_detection/group1-shard2of4.bin
--------------------------------------------------------------------------------
/tfjs/static/emotion_detection/group1-shard3of4.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tfjs/static/emotion_detection/group1-shard3of4.bin
--------------------------------------------------------------------------------
/tfjs/static/emotion_detection/group1-shard4of4.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tfjs/static/emotion_detection/group1-shard4of4.bin
--------------------------------------------------------------------------------
/tfjs/static/emotion_detection_old/group1-shard1of4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tfjs/static/emotion_detection_old/group1-shard1of4
--------------------------------------------------------------------------------
/tfjs/static/emotion_detection_old/group1-shard2of4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tfjs/static/emotion_detection_old/group1-shard2of4
--------------------------------------------------------------------------------
/tfjs/static/emotion_detection_old/group1-shard3of4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tfjs/static/emotion_detection_old/group1-shard3of4
--------------------------------------------------------------------------------
/tfjs/static/emotion_detection_old/group1-shard4of4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tfjs/static/emotion_detection_old/group1-shard4of4
--------------------------------------------------------------------------------
/tfjs/static/face_detection/tiny_face_detector_model-shard1:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tfjs/static/face_detection/tiny_face_detector_model-shard1
--------------------------------------------------------------------------------
/tfjs/static/face_detection/tiny_face_detector_model-shard1.weight:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EliotAndres/tensorflow-2-run-on-mobile-devices-ios-android-browser/684c1399059090dabb6f84a09419032ff046e23b/tfjs/static/face_detection/tiny_face_detector_model-shard1.weight
--------------------------------------------------------------------------------
/tfjs/static/face_detection/tiny_face_detector_model-weights_manifest.json:
--------------------------------------------------------------------------------
1 | [{"weights":[{"name":"conv0/filters","shape":[3,3,3,16],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.009007044399485869,"min":-1.2069439495311063}},{"name":"conv0/bias","shape":[16],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.005263455241334205,"min":-0.9211046672334858}},{"name":"conv1/depthwise_filter","shape":[3,3,16,1],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.004001977630690033,"min":-0.5042491814669441}},{"name":"conv1/pointwise_filter","shape":[1,1,16,32],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.013836609615999109,"min":-1.411334180831909}},{"name":"conv1/bias","shape":[32],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0015159862590771096,"min":-0.30926119685173037}},{"name":"conv2/depthwise_filter","shape":[3,3,32,1],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.002666276225856706,"min":-0.317286870876948}},{"name":"conv2/pointwise_filter","shape":[1,1,32,64],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.015265831292844286,"min":-1.6792414422128714}},{"name":"conv2/bias","shape":[64],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0020280554598453,"min":-0.37113414915168985}},{"name":"conv3/depthwise_filter","shape":[3,3,64,1],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.006100742489683862,"min":-0.8907084034938438}},{"name":"conv3/pointwise_filter","shape":[1,1,64,128],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.016276211832083907,"min":-2.0508026908425725}},{"name":"conv3/bias","shape":[128],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.003394414279975143,"min":-0.7637432129944072}},{"name":"conv4/depthwise_filter","shape":[3,3,128,1],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.006716050119961009,"min":-0.8059260143953211}},{"name":"conv4/pointwise_filter","shape":[1,1,128,256],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.021875603993733724,"min":-2.8875797271728514}},{"name":"conv4/bias","shape":[256],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0041141652009066415,"min":-0.8187188749804216}},{"name":"conv5/depthwise_filter","shape":[3,3,256,1],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.008423839597141042,"min":-0.9013508368940915}},{"name":"conv5/pointwise_filter","shape":[1,1,256,512],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.030007277283014035,"min":-3.8709387695088107}},{"name":"conv5/bias","shape":[512],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.008402082966823203,"min":-1.4871686851277068}},{"name":"conv8/filters","shape":[1,1,512,25],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.028336129469030042,"min":-4.675461362389957}},{"name":"conv8/bias","shape":[25],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.002268134028303857,"min":-0.41053225912299807}}],"paths":["tiny_face_detector_model-shard1.weight"]}]
2 |
--------------------------------------------------------------------------------