* Create LSTM model if it is not saved locally; load it if it is. * * @param {number | number[]} lstmLayerSizes Sizes of the LSTM layers, as a * number or an non-empty array of numbers.
(lstmLayerSizes)
| 163 | * number or an non-empty array of numbers. |
| 164 | */ |
| 165 | async loadModel(lstmLayerSizes) { |
| 166 | const modelsInfo = await tf.io.listModels(); |
| 167 | if (this.modelSavePath_ in modelsInfo) { |
| 168 | console.log(`Loading existing model...`); |
| 169 | this.model = await tf.loadLayersModel(this.modelSavePath_); |
| 170 | console.log(`Loaded model from ${this.modelSavePath_}`); |
| 171 | } else { |
| 172 | throw new Error( |
| 173 | `Cannot find model at ${this.modelSavePath_}. ` + |
| 174 | `Creating model from scratch.`); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Save the model in IndexedDB. |