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
- npm run build:browser or build (to create dist/keras.js and/or node build respectively)
44
+
37
45
### Usage
38
46
39
47
See `demos/src/` for source code of real examples written in VueJS.
@@ -51,41 +59,51 @@ See `demos/src/` for source code of real examples written in VueJS.
51
59
model = Model(input=..., output=...)
52
60
```
53
61
54
-
Once trained, save the weights and export model architecture config:
62
+
Once trained, save the whole model and the weights for the encoding step (and/or other uses):
55
63
56
64
```py
57
-
model.save_weights('model.hdf5')
65
+
model.save('model.hdf5')
58
66
withopen('model.json', 'w') as f:
59
67
f.write(model.to_json())
68
+
69
+
model.save_weights('model_weights.hdf5')
70
+
withopen('model_weights.json', 'w') as f:
71
+
f.write(model.to_json())
60
72
```
61
73
62
74
See jupyter notebooks of demos for details: `demos/notebooks/`. All that's required for [ResNet50](https://github.com/fchollet/keras/blob/master/keras/applications/resnet50.py), for example, is:
63
75
64
76
```py
65
77
from keras.applications import resnet50
66
78
model = resnet50.ResNet50(include_top=True, weights='imagenet')
67
-
model.save_weights('resnet50.hdf5')
79
+
80
+
model.save('resnet50.hdf5')
68
81
withopen('resnet50.json', 'w') as f:
69
82
f.write(model.to_json())
83
+
84
+
model.save_weights('resnet50_weights.hdf5')
85
+
withopen('resnet50_weights.json', 'w') as f:
86
+
f.write(model.to_json())
70
87
```
71
88
72
-
2.Run the encoder script on the HDF5 weights file:
89
+
2.From the python folder run the encoder script on the HDF5 weights file:
73
90
74
91
```sh
75
-
$ python encoder.py /path/to/model.hdf5
92
+
$ cdpython
76
93
```
77
94
78
-
This will produce 2 files in the same folder as the HDF5 weights: `model_weights.buf` and `model_metadata.json`.
95
+
```sh
96
+
$ python encoder.py /path/to/model.hdf5 (optional flag --quantize)
97
+
```
79
98
80
-
3. The 3 files required for Keras.js are:
99
+
This will produce 1 file in the same folder as the HDF5 weights: `model.bin`.
81
100
82
-
- the model file: `model.json`
101
+
3. The 1 file required for Keras.js is:
83
102
84
-
- the weights file: `model_weights.buf`
103
+
- the full model file: `encoded_model.bin`
85
104
86
-
- the weights metadata file: `model_metadata.json`
87
105
88
-
4. Include Keras.js:
106
+
4. Include Keras.js (see build step above):
89
107
90
108
```html
91
109
<scriptsrc="dist/keras.js"></script>
@@ -118,23 +136,15 @@ See `demos/src/` for source code of real examples written in VueJS.
118
136
```js
119
137
// in browser, URLs can be relative or absolute
120
138
constmodel=newKerasJS.Model({
121
-
filepaths: {
122
-
model:'url/path/to/model.json',
123
-
weights:'url/path/to/model_weights.buf',
124
-
metadata:'url/path/to/model_metadata.json'
125
-
},
139
+
filepath:'url/path/to/model.bin',
126
140
gpu:true
127
141
})
128
142
129
143
// in node, gpu flag will always be off
130
144
// paths can be filesystem paths or absolute URLs
131
145
// if filesystem path, this must be specified:
132
146
constmodel=newKerasJS.Model({
133
-
filepaths: {
134
-
model:'path/to/model.json',
135
-
weights:'path/to/model_weights.buf',
136
-
metadata:'path/to/model_metadata.json'
137
-
},
147
+
filepath:'url/path/to/model.bin',
138
148
filesystem:true
139
149
})
140
150
```
@@ -145,7 +155,7 @@ See `demos/src/` for source code of real examples written in VueJS.
145
155
model.ready()
146
156
.then(() => {
147
157
// input data object keyed by names of the input layers
148
-
// or `input` for Sequential models
158
+
// or `input` for Sequential models, possibly `dense_2` for InceptionV3 models,
149
159
// values are the flattened Float32Array data
150
160
// (input tensor shapes are specified in the model config)
0 commit comments