Skip to content

Commit a18aca7

Browse files
author
David Parnell
committed
Update Read.me with single binary build instructions
1 parent 4131fe9 commit a18aca7

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

README.md

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ Library version compatibility:
3434

3535
- Bidirectional LSTM for IMDB sentiment classification
3636

37+
### Clone and Setup
38+
- git clone https://github.com/transcranial/keras-js.git
39+
- npm i
40+
- npm run proto2js
41+
42+
### Build
43+
- npm run build:browser or build (to create dist/keras.js and/or node build respectively)
44+
3745
### Usage
3846

3947
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.
5159
model = Model(input=..., output=...)
5260
```
5361

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):
5563

5664
```py
57-
model.save_weights('model.hdf5')
65+
model.save('model.hdf5')
5866
with open('model.json', 'w') as f:
5967
f.write(model.to_json())
68+
69+
model.save_weights('model_weights.hdf5')
70+
with open('model_weights.json', 'w') as f:
71+
f.write(model.to_json())
6072
```
6173

6274
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:
6375

6476
```py
6577
from keras.applications import resnet50
6678
model = resnet50.ResNet50(include_top=True, weights='imagenet')
67-
model.save_weights('resnet50.hdf5')
79+
80+
model.save('resnet50.hdf5')
6881
with open('resnet50.json', 'w') as f:
6982
f.write(model.to_json())
83+
84+
model.save_weights('resnet50_weights.hdf5')
85+
with open('resnet50_weights.json', 'w') as f:
86+
f.write(model.to_json())
7087
```
7188

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:
7390

7491
```sh
75-
$ python encoder.py /path/to/model.hdf5
92+
$ cd python
7693
```
7794

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+
```
7998

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`.
81100

82-
- the model file: `model.json`
101+
3. The 1 file required for Keras.js is:
83102

84-
- the weights file: `model_weights.buf`
103+
- the full model file: `encoded_model.bin`
85104

86-
- the weights metadata file: `model_metadata.json`
87105

88-
4. Include Keras.js:
106+
4. Include Keras.js (see build step above):
89107

90108
```html
91109
<script src="dist/keras.js"></script>
@@ -118,23 +136,15 @@ See `demos/src/` for source code of real examples written in VueJS.
118136
```js
119137
// in browser, URLs can be relative or absolute
120138
const model = new KerasJS.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',
126140
gpu: true
127141
})
128142

129143
// in node, gpu flag will always be off
130144
// paths can be filesystem paths or absolute URLs
131145
// if filesystem path, this must be specified:
132146
const model = new KerasJS.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',
138148
filesystem: true
139149
})
140150
```
@@ -145,7 +155,7 @@ See `demos/src/` for source code of real examples written in VueJS.
145155
model.ready()
146156
.then(() => {
147157
// 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,
149159
// values are the flattened Float32Array data
150160
// (input tensor shapes are specified in the model config)
151161
const inputData = {

0 commit comments

Comments
 (0)