You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+84-2Lines changed: 84 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,6 +64,63 @@ When you have a trained model you're happy with, save it with:
64
64
mlClassifier.save();
65
65
```
66
66
67
+
## Using the saved model
68
+
69
+
When you hit save, Tensorflow.js will download a weights file and a model topology file.
70
+
71
+
You'll need to combine both into a single `json` file. Open up your model topology file and at the top level of the JSON file, make sure to add a `weightsManifest` key pointing to your weights, like:
When using the model in your app, there's a few things to keep in mind:
83
+
84
+
1. You need to make sure you transform images into the correct dimensions, depending on the pretrained model it was trained with. (For MOBILENET, this would be 1x224x224x3).
85
+
2. You must create a pretrained model matching the dimensions used to train. An example is below for MOBILENET.
86
+
3. You must first run your images through the pretrained model to activate them.
87
+
4. After getting the final prediction, you must take the arg max.
88
+
5. You'll get back a number indicating your class.
89
+
90
+
Full example for MOBILENET:
91
+
92
+
```
93
+
const loadImage = (src) => new Promise((resolve, reject) => {
Start by instantiating a new instance of `MLClassifier` with:
@@ -76,10 +133,16 @@ This will begin loading the pretrained model and provide you with an object onto
76
133
77
134
### `constructor`
78
135
79
-
`MLClassifier` accepts a number of callbacks when initialized:
136
+
`MLClassifier` accepts a number of callbacks for beginning and end of various methods.
137
+
138
+
You can provide a custom pretrained model as a `pretrainedModel`.
139
+
140
+
You can provide a custom training model as a `trainingModel`.
80
141
81
142
#### Parameters
82
143
144
+
***pretrainedModel** (`string | tf.Model`) *Optional* - A string denoting which pretrained model to load from an internal config. Valid strings can be found on the exported object `PRETRAINED_MODELS`. You can also specify a preloaded pretrained model directly.
145
+
***trainingModel** (`tf.Model | Function`) *Optional* - A custom model to use during training. Can be provided as a `tf.Model` or as a function that accepts `{xs: [...], ys: [...]`, number of `classes`, and `params` provided to train.
83
146
***onLoadStart** (`Function`) *Optional* - A callback for when `load` (loading the pre-trained model) is first called.
84
147
***onLoadComplete** (`Function`) *Optional* - A callback for when `load` (loading the pre-trained model) is complete.
85
148
***onAddDataStart** (`Function`) *Optional* - A callback for when `addData` is first called.
@@ -98,8 +161,13 @@ This will begin loading the pretrained model and provide you with an object onto
0 commit comments