()
| 131 | } |
| 132 | |
| 133 | protected async loadBinaryModel(): Promise<tf.io.ModelArtifacts> { |
| 134 | const topologyPath = this.path[0]; |
| 135 | const weightManifestPath = this.path[1]; |
| 136 | const topology = |
| 137 | await stat(topologyPath).catch(doesNotExistHandler('Topology Path')); |
| 138 | const weightManifest = |
| 139 | await stat(weightManifestPath) |
| 140 | .catch(doesNotExistHandler('Weight Manifest Path')); |
| 141 | |
| 142 | // `this.path` can be either a directory or a file. If it is a file, assume |
| 143 | // it is model.json file. |
| 144 | if (!topology.isFile()) { |
| 145 | throw new Error('File specified for topology is not a file!'); |
| 146 | } |
| 147 | if (!weightManifest.isFile()) { |
| 148 | throw new Error('File specified for the weight manifest is not a file!'); |
| 149 | } |
| 150 | |
| 151 | const modelTopology = await readFile(this.path[0]); |
| 152 | const weightsManifest = JSON.parse(await readFile(this.path[1], 'utf8')); |
| 153 | |
| 154 | const modelArtifacts: tf.io.ModelArtifacts = { |
| 155 | modelTopology, |
| 156 | }; |
| 157 | const [weightSpecs, weightData] = |
| 158 | await this.loadWeights(weightsManifest, this.path[1]); |
| 159 | |
| 160 | modelArtifacts.weightSpecs = weightSpecs; |
| 161 | modelArtifacts.weightData = weightData; |
| 162 | |
| 163 | return modelArtifacts; |
| 164 | } |
| 165 | |
| 166 | protected async loadJSONModel(): Promise<tf.io.ModelArtifacts> { |
| 167 | const path = this.path as string; |
no test coverage detected