Skip to content

Commit 63250ec

Browse files
Address tfjs-react-native typos in documentation strings (#8217)
1 parent c027d6a commit 63250ec

File tree

7 files changed

+840
-751
lines changed

7 files changed

+840
-751
lines changed

tfjs-react-native/DEVELOPMENT.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# Development
22

3-
This file will document some of the differences from the regular developement workflow in [DEVELOPMENT.md](../DEVELOPMENT.md). You should read that document first to get familiar with typical TensorFlow.js development workflow.
3+
This file will document some of the differences from the regular development workflow in [DEVELOPMENT.md](../DEVELOPMENT.md). You should read that document first to get familiar with typical TensorFlow.js development workflow.
44

55
Development and testing for tfjs-react-native is somewhat different from the packages like tfjs-core or tfjs-layers for a few reasons:
6-
- __Dependency on having a physical mobile device to run__: While the CPU backend can run in a simulator, the WebGL one requires running on a physical device. So most of the time you will want to test something using a mobile device connected to your computer.
7-
- __No browser or node environment__: We are running JavaScript outside of a browser and outside of node. We thus have to make sure we don't include things that depend on those two environments.
86

7+
- **Dependency on having a physical mobile device to run**: While the CPU backend can run in a simulator, the WebGL one requires running on a physical device. So most of the time you will want to test something using a mobile device connected to your computer.
8+
- **No browser or node environment**: We are running JavaScript outside of a browser and outside of node. We thus have to make sure we don't include things that depend on those two environments.
99

1010
## Key Terms & Caveats
1111

1212
These are a few key terms/technologies to be familiar with that are different from what we use for web or node.js development.
1313

1414
- [React Native](https://facebook.github.io/react-native/) — This is the framework that this package targets.
1515
- [Metro](https://facebook.github.io/metro/) — This is the bundler used to create the JavaScript bundle that is loaded into the native app by react native.
16-
- The bundle needs to be created at 'compile time' thus all imports/requires need to be resolved. Thus _dynamic_ `import`s/`require`s are __statically resolved__. So you cannot exclude a require with a conditional in JS code.
16+
- The bundle needs to be created at 'compile time' thus all imports/requires need to be resolved. Thus _dynamic_ `import`s/`require`s are **statically resolved**. So you cannot exclude a require with a conditional in JS code.
1717
- Since tfjs does dynamic `require`'s of certain node libraries that are not present in react native, files that do that need to be excluded from the metro build process. For end users, this is documented in the [README](../README.md), but it also happens in `integration_rn59/prep_tests.ts`.
1818
- Metro does not play well with symlinks, so if you are trying to develop against a local build of tfjs, copy the dist folder into the app's node_modules as appropriate. Do not use yalc.
1919
- [.ipa](https://en.wikipedia.org/wiki/.ipa) & [.apk](https://en.wikipedia.org/wiki/Android_application_package) — These are the formats for the final native bundle that is put on an iOS and Android device. They are created by their respective dev tools, [XCode](https://developer.apple.com/xcode/) and [Android Studio](https://developer.android.com/studio).
@@ -33,8 +33,9 @@ Unit tests from tfjs-core are imported into a react native application and run a
3333
Because these are part of an app to run them you must compile and run the integration_rn59 of the target device. There is a button in that app to start the unit tests.
3434

3535
This is _automated in CI_ and runs on:
36-
- Changes to tfjs-core: [Tests will be run against HEAD of tfjs-core](../tfjs-core/cloudbuild.yml)
37-
- Changes to tfjs-react-native: [Tests will be run against the **published** version](./cloudbuild.yml) of tfjs on npm that is references in `integration_rn59/package.json`
36+
37+
- Changes to tfjs-core: [Tests will be run against HEAD of tfjs-core](../tfjs-core/cloudbuild.yml)
38+
- Changes to tfjs-react-native: [Tests will be run against the **published** version](./cloudbuild.yml) of tfjs on npm that is references in `integration_rn59/package.json`
3839

3940
### Other integration tests
4041

tfjs-react-native/integration_rn59/components/ml.ts

+38-31
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
* =============================================================================
1616
*/
1717

18-
import * as mobilenet from '@tensorflow-models/mobilenet';
19-
import * as tf from '@tensorflow/tfjs';
20-
import {asyncStorageIO, bundleResourceIO} from '@tensorflow/tfjs-react-native';
18+
import * as mobilenet from "@tensorflow-models/mobilenet";
19+
import * as tf from "@tensorflow/tfjs";
20+
import {
21+
asyncStorageIO,
22+
bundleResourceIO,
23+
} from "@tensorflow/tfjs-react-native";
2124

2225
// All functions (i.e. 'runners") in this file are async
2326
// functions that return a function that can be invoked to
@@ -64,11 +67,12 @@ export async function mobilenetRunner() {
6467
* A runner that loads a model bundled with the app and runs a prediction
6568
* through it.
6669
*/
67-
const modelJson = require('../assets/model/bundle_model_test.json');
68-
const modelWeights = require('../assets/model/bundle_model_test_weights.bin');
70+
const modelJson = require("../assets/model/bundle_model_test.json");
71+
const modelWeights = require("../assets/model/bundle_model_test_weights.bin");
6972
export async function localModelRunner() {
70-
const model =
71-
await tf.loadLayersModel(bundleResourceIO(modelJson, modelWeights));
73+
const model = await tf.loadLayersModel(
74+
bundleResourceIO(modelJson, modelWeights)
75+
);
7276

7377
return async () => {
7478
const res = model.predict(tf.randomNormal([1, 10])) as tf.Tensor;
@@ -81,11 +85,12 @@ export async function localModelRunner() {
8185
* A runner that loads a model bundled with the app and runs a prediction
8286
* through it.
8387
*/
84-
const modelJson2 = require('../assets/graph_model/model.json');
85-
const modelWeights2 = require('../assets/graph_model/group1-shard1of1.bin');
88+
const modelJson2 = require("../assets/graph_model/model.json");
89+
const modelWeights2 = require("../assets/graph_model/group1-shard1of1.bin");
8690
export async function localGraphModelRunner() {
87-
const model =
88-
await tf.loadGraphModel(bundleResourceIO(modelJson2, modelWeights2));
91+
const model = await tf.loadGraphModel(
92+
bundleResourceIO(modelJson2, modelWeights2)
93+
);
8994
return async () => {
9095
const res = model.predict(tf.randomNormal([1, 10])) as tf.Tensor;
9196
const data = await res.data();
@@ -97,43 +102,45 @@ export async function localGraphModelRunner() {
97102
* A runner that loads a sharded model bundled with the app and runs a
98103
* prediction through it.
99104
*/
100-
const shardedModelJson = require('../assets/sharded_model/model.json');
101-
const shardedModelWeights1: number =
102-
require('../assets/sharded_model/group1-shard1of2.bin');
103-
const shardedModelWeights2: number =
104-
require('../assets/sharded_model/group1-shard2of2.bin');
105+
const shardedModelJson = require("../assets/sharded_model/model.json");
106+
const shardedModelWeights1: number = require("../assets/sharded_model/group1-shard1of2.bin");
107+
const shardedModelWeights2: number = require("../assets/sharded_model/group1-shard2of2.bin");
105108

106109
export async function localShardedGraphModelRunner() {
107-
const model = await tf.loadGraphModel(bundleResourceIO(
108-
shardedModelJson, [shardedModelWeights1, shardedModelWeights2]));
110+
const model = await tf.loadGraphModel(
111+
bundleResourceIO(shardedModelJson, [
112+
shardedModelWeights1,
113+
shardedModelWeights2,
114+
])
115+
);
109116

110117
return async () => {
111118
const input = tf.zeros([1, 224, 224, 3]);
112119
const res = model.predict(input) as tf.Tensor;
113120
const data = await res.data();
114-
return JSON.stringify({predictionsLength: data.length});
121+
return JSON.stringify({ predictionsLength: data.length });
115122
};
116123
}
117124

118125
/**
119-
* A runner that traines a model.
126+
* A runner that trains a model.
120127
*/
121128
export async function trainModelRunner() {
122129
// Define a model for linear regression.
123130
const model = tf.sequential();
124-
model.add(tf.layers.dense({units: 5, inputShape: [1]}));
125-
model.add(tf.layers.dense({units: 1}));
126-
model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});
131+
model.add(tf.layers.dense({ units: 5, inputShape: [1] }));
132+
model.add(tf.layers.dense({ units: 1 }));
133+
model.compile({ loss: "meanSquaredError", optimizer: "sgd" });
127134

128135
// Generate some synthetic data for training.
129136
const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);
130137
const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);
131138

132139
return async () => {
133140
// Train the model using the data.
134-
await model.fit(xs, ys, {epochs: 20});
141+
await model.fit(xs, ys, { epochs: 20 });
135142

136-
return 'done';
143+
return "done";
137144
};
138145
}
139146

@@ -143,14 +150,14 @@ export async function trainModelRunner() {
143150
export async function saveModelRunner() {
144151
// Define a model for linear regression.
145152
const model = tf.sequential();
146-
model.add(tf.layers.dense({units: 5, inputShape: [1]}));
147-
model.add(tf.layers.dense({units: 1}));
148-
model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});
153+
model.add(tf.layers.dense({ units: 5, inputShape: [1] }));
154+
model.add(tf.layers.dense({ units: 1 }));
155+
model.compile({ loss: "meanSquaredError", optimizer: "sgd" });
149156

150157
return async () => {
151-
await model.save(asyncStorageIO('custom-model-test'));
152-
await tf.loadLayersModel(asyncStorageIO('custom-model-test'));
158+
await model.save(asyncStorageIO("custom-model-test"));
159+
await tf.loadLayersModel(asyncStorageIO("custom-model-test"));
153160

154-
return 'done';
161+
return "done";
155162
};
156163
}

tfjs-react-native/integration_rn59/components/tfjs_unit_test_runner.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class TestRunner extends Component<TestRunnerProps, TestRunnerState> {
123123
const reactReporter: jasmine.CustomReporter = {
124124
jasmineStarted: suiteInfo => {
125125
// The console.warn below seems necessary in order for the spy on
126-
// console.warn defined in one of the tests to run corrently.
126+
// console.warn defined in one of the tests to run currently.
127127
console.warn('starting tests');
128128
//@ts-ignore
129129
console.reportErrorsAsExceptions = false;

0 commit comments

Comments
 (0)