@webwriter/deep-learning-model 0.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/main.yml +8 -0
- package/LICENSE +7 -0
- package/README.md +290 -0
- package/components/dataset-input/dataset-input.styles.ts +20 -0
- package/components/dataset-input/dataset-input.ts +196 -0
- package/components/inference-fields/class-input.ts +83 -0
- package/components/inference-fields/class-output.ts +62 -0
- package/components/inference-fields/image-input.ts +182 -0
- package/components/inference-fields/image.ts +82 -0
- package/components/inference-fields/inference-interfaces.ts +15 -0
- package/components/inference-fields/number-input.ts +62 -0
- package/components/inference-fields/number-output.ts +56 -0
- package/components/model-editor.ts +288 -0
- package/components/model-tests/bad-samples.ts +152 -0
- package/components/model-tests/loss-distribution.ts +174 -0
- package/components/reference-element-select.ts +105 -0
- package/custom-elements.json +1470 -0
- package/custom.d.ts +180 -0
- package/dist/widgets/webwriter-feature-engineering.css +444 -0
- package/dist/widgets/webwriter-feature-engineering.js +112763 -0
- package/dist/widgets/webwriter-model-designing.css +444 -0
- package/dist/widgets/webwriter-model-designing.js +114587 -0
- package/dist/widgets/webwriter-model-evaluation.css +444 -0
- package/dist/widgets/webwriter-model-evaluation.js +119010 -0
- package/dist/widgets/webwriter-model-prediction.css +444 -0
- package/dist/widgets/webwriter-model-prediction.js +109251 -0
- package/dist/widgets/webwriter-model-training.css +444 -0
- package/dist/widgets/webwriter-model-training.js +121465 -0
- package/editing-config.json +73 -0
- package/icon.svg +1 -0
- package/lib/dataset/class.ts +155 -0
- package/lib/dataset/dataset.ts +293 -0
- package/lib/dataset/feature.ts +110 -0
- package/lib/dataset/image.ts +312 -0
- package/lib/dataset/linear.ts +120 -0
- package/lib/layers/activation.ts +48 -0
- package/lib/layers/add.ts +50 -0
- package/lib/layers/attention.ts +74 -0
- package/lib/layers/concat.ts +50 -0
- package/lib/layers/conv.ts +83 -0
- package/lib/layers/dropout.ts +44 -0
- package/lib/layers/fcl.ts +66 -0
- package/lib/layers/flatten.ts +48 -0
- package/lib/layers/index.ts +770 -0
- package/lib/layers/input.ts +55 -0
- package/lib/layers/noise.ts +43 -0
- package/lib/layers/output.ts +64 -0
- package/lib/layers/reshape.ts +76 -0
- package/lib/layers/transposeconv.ts +90 -0
- package/lib/tflib.ts +10 -0
- package/lit-localize.json +47 -0
- package/localization/ar.xlf +553 -0
- package/localization/bg.xlf +552 -0
- package/localization/cs.xlf +553 -0
- package/localization/da.xlf +552 -0
- package/localization/de.xlf +552 -0
- package/localization/el.xlf +554 -0
- package/localization/es.xlf +553 -0
- package/localization/et.xlf +553 -0
- package/localization/fi.xlf +552 -0
- package/localization/fr.xlf +553 -0
- package/localization/generated/ar.ts +159 -0
- package/localization/generated/bg.ts +158 -0
- package/localization/generated/cs.ts +159 -0
- package/localization/generated/da.ts +158 -0
- package/localization/generated/de.ts +158 -0
- package/localization/generated/el.ts +160 -0
- package/localization/generated/es.ts +159 -0
- package/localization/generated/et.ts +159 -0
- package/localization/generated/fi.ts +158 -0
- package/localization/generated/fr.ts +159 -0
- package/localization/generated/hu.ts +158 -0
- package/localization/generated/id.ts +159 -0
- package/localization/generated/index.js +3 -0
- package/localization/generated/it.ts +159 -0
- package/localization/generated/ja.ts +158 -0
- package/localization/generated/ko.ts +158 -0
- package/localization/generated/locale-codes.js +83 -0
- package/localization/generated/lt.ts +158 -0
- package/localization/generated/lv.ts +158 -0
- package/localization/generated/nb.ts +158 -0
- package/localization/generated/nl.ts +158 -0
- package/localization/generated/pl.ts +159 -0
- package/localization/generated/pt-BR.ts +159 -0
- package/localization/generated/pt-PT.ts +159 -0
- package/localization/generated/ro.ts +159 -0
- package/localization/generated/ru.ts +159 -0
- package/localization/generated/sk.ts +159 -0
- package/localization/generated/sl.ts +159 -0
- package/localization/generated/sv.ts +158 -0
- package/localization/generated/tr.ts +158 -0
- package/localization/generated/uk.ts +158 -0
- package/localization/generated/zh-hans.ts +141 -0
- package/localization/generated/zh-hant.ts +141 -0
- package/localization/hu.xlf +552 -0
- package/localization/id.xlf +553 -0
- package/localization/it.xlf +553 -0
- package/localization/ja.xlf +552 -0
- package/localization/ko.xlf +552 -0
- package/localization/lt.xlf +552 -0
- package/localization/lv.xlf +552 -0
- package/localization/nb.xlf +552 -0
- package/localization/nl.xlf +552 -0
- package/localization/pkg/ar.xliff +7 -0
- package/localization/pkg/bg.xliff +7 -0
- package/localization/pkg/cs.xliff +7 -0
- package/localization/pkg/da.xliff +7 -0
- package/localization/pkg/de.xliff +7 -0
- package/localization/pkg/el.xliff +7 -0
- package/localization/pkg/es.xliff +7 -0
- package/localization/pkg/et.xliff +7 -0
- package/localization/pkg/fi.xliff +7 -0
- package/localization/pkg/fr.xliff +7 -0
- package/localization/pkg/hu.xliff +7 -0
- package/localization/pkg/id.xliff +7 -0
- package/localization/pkg/it.xliff +7 -0
- package/localization/pkg/ja.xliff +7 -0
- package/localization/pkg/ko.xliff +7 -0
- package/localization/pkg/lt.xliff +7 -0
- package/localization/pkg/lv.xliff +7 -0
- package/localization/pkg/nb.xliff +7 -0
- package/localization/pkg/nl.xliff +7 -0
- package/localization/pkg/pl.xliff +7 -0
- package/localization/pkg/pt-BR.xliff +7 -0
- package/localization/pkg/pt-PT.xliff +7 -0
- package/localization/pkg/ro.xliff +7 -0
- package/localization/pkg/ru.xliff +7 -0
- package/localization/pkg/sk.xliff +7 -0
- package/localization/pkg/sl.xliff +7 -0
- package/localization/pkg/sv.xliff +7 -0
- package/localization/pkg/tr.xliff +7 -0
- package/localization/pkg/uk.xliff +7 -0
- package/localization/pkg/zh-hans.xliff +7 -0
- package/localization/pkg/zh-hant.xliff +7 -0
- package/localization/pl.xlf +553 -0
- package/localization/pt-BR.xlf +553 -0
- package/localization/pt-PT.xlf +553 -0
- package/localization/ro.xlf +553 -0
- package/localization/ru.xlf +553 -0
- package/localization/sk.xlf +553 -0
- package/localization/sl.xlf +553 -0
- package/localization/snippets/ar.xliff +16 -0
- package/localization/snippets/bg.xliff +16 -0
- package/localization/snippets/cs.xliff +16 -0
- package/localization/snippets/da.xliff +16 -0
- package/localization/snippets/de.xliff +16 -0
- package/localization/snippets/el.xliff +16 -0
- package/localization/snippets/es.xliff +16 -0
- package/localization/snippets/et.xliff +16 -0
- package/localization/snippets/fi.xliff +16 -0
- package/localization/snippets/fr.xliff +16 -0
- package/localization/snippets/hu.xliff +16 -0
- package/localization/snippets/id.xliff +16 -0
- package/localization/snippets/it.xliff +16 -0
- package/localization/snippets/ja.xliff +16 -0
- package/localization/snippets/ko.xliff +16 -0
- package/localization/snippets/lt.xliff +16 -0
- package/localization/snippets/lv.xliff +16 -0
- package/localization/snippets/nb.xliff +16 -0
- package/localization/snippets/nl.xliff +16 -0
- package/localization/snippets/pl.xliff +16 -0
- package/localization/snippets/pt-BR.xliff +16 -0
- package/localization/snippets/pt-PT.xliff +16 -0
- package/localization/snippets/ro.xliff +16 -0
- package/localization/snippets/ru.xliff +16 -0
- package/localization/snippets/sk.xliff +16 -0
- package/localization/snippets/sl.xliff +16 -0
- package/localization/snippets/sv.xliff +16 -0
- package/localization/snippets/tr.xliff +16 -0
- package/localization/snippets/uk.xliff +16 -0
- package/localization/snippets/zh-hans.xliff +16 -0
- package/localization/snippets/zh-hant.xliff +16 -0
- package/localization/sv.xlf +552 -0
- package/localization/tr.xlf +552 -0
- package/localization/uk.xlf +552 -0
- package/localization/zh-hans.xlf +552 -0
- package/localization/zh-hant.xlf +552 -0
- package/package.json +103 -2
- package/snippets/MNIST.html +21 -0
- package/test.json +63 -0
- package/tsconfig.json +8 -0
- package/widgets/webwriter-feature-engineering.ts +421 -0
- package/widgets/webwriter-model-designing.ts +323 -0
- package/widgets/webwriter-model-evaluation.ts +215 -0
- package/widgets/webwriter-model-prediction.ts +307 -0
- package/widgets/webwriter-model-training.ts +709 -0
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
import { SlButton, SlButtonGroup, SlCheckbox, SlIcon, SlIconButton, SlInput, SlOption, SlSelect, SlTooltip } from "@shoelace-style/shoelace";
|
|
2
|
+
import { LitElementWw } from "@webwriter/lit";
|
|
3
|
+
import ApexCharts from "apexcharts";
|
|
4
|
+
import { css, html, TemplateResult } from "lit";
|
|
5
|
+
import { msg } from "@lit/localize";
|
|
6
|
+
import { customElement, property, query } from "lit/decorators.js";
|
|
7
|
+
import { AiWidgetsReferenceSelect } from "../components/reference-element-select";
|
|
8
|
+
import { AiWidgetsFeatures } from "./webwriter-feature-engineering";
|
|
9
|
+
import { AiWidgetsDesigns } from "./webwriter-model-designing";
|
|
10
|
+
//import {setWasmPaths, setThreadsCount} from '@tensorflow/tfjs-backend-wasm';
|
|
11
|
+
import { Editor, Layer } from "../lib/layers";
|
|
12
|
+
import LOCALIZE from "../localization/generated";
|
|
13
|
+
//setWasmPaths('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@4.22.0/dist/');
|
|
14
|
+
//setThreadsCount(4);
|
|
15
|
+
|
|
16
|
+
import type * as TF from "@tensorflow/tfjs";
|
|
17
|
+
import getTF from "../lib/tflib";
|
|
18
|
+
let tf: typeof TF;
|
|
19
|
+
|
|
20
|
+
function uint8ToHex(uint8:Uint8Array) {
|
|
21
|
+
return Array.from(uint8, b => b.toString(16).padStart(2, '0')).join('');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function hexToUint8(hex:string) {
|
|
25
|
+
if (hex.length % 2 !== 0) {
|
|
26
|
+
throw new Error("Invalid hex string");
|
|
27
|
+
}
|
|
28
|
+
const len = hex.length / 2;
|
|
29
|
+
const result = new Uint8Array(len);
|
|
30
|
+
for (let i = 0; i < len; i++) {
|
|
31
|
+
result[i] = parseInt(hex.substr(i * 2, 2), 16);
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
(async () => {
|
|
37
|
+
tf = await getTF()
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The NoOpLayer is important for designating an output name. This will be read by later widgets to connect the correct model output to the dataset labels.
|
|
41
|
+
*/
|
|
42
|
+
class NoOpLayer extends tf.layers.Layer {
|
|
43
|
+
constructor(config) {
|
|
44
|
+
super(config);
|
|
45
|
+
this.supportsMasking = true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
call(inputs, kwargs) {
|
|
49
|
+
return inputs;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
computeOutputShape(inputShape) {
|
|
53
|
+
return inputShape;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static get className() {
|
|
57
|
+
return 'NoOpLayer';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
(window as any).NoOpLayer = NoOpLayer;
|
|
61
|
+
|
|
62
|
+
tf.serialization.registerClass(NoOpLayer);
|
|
63
|
+
})()
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A widget to train models designed in the model designing widget using datasets created in the feature engineering widget.
|
|
67
|
+
*
|
|
68
|
+
* @event finished - Fired when the training process has finished.
|
|
69
|
+
* @event epoch - Fired after each epoch during training.
|
|
70
|
+
*/
|
|
71
|
+
@customElement("webwriter-model-training")
|
|
72
|
+
export class AiWidgetsTraining extends LitElementWw {
|
|
73
|
+
/** @internal */
|
|
74
|
+
static scopedElements = {
|
|
75
|
+
"sl-button": SlButton,
|
|
76
|
+
"sl-button-group": SlButtonGroup,
|
|
77
|
+
"sl-option": SlOption,
|
|
78
|
+
"sl-select": SlSelect,
|
|
79
|
+
"sl-input":SlInput,
|
|
80
|
+
"sl-icon": SlIcon,
|
|
81
|
+
"sl-icon-button": SlIconButton,
|
|
82
|
+
"sl-checkbox": SlCheckbox,
|
|
83
|
+
"sl-tooltip": SlTooltip,
|
|
84
|
+
"ref-select": AiWidgetsReferenceSelect
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
protected localize = LOCALIZE;
|
|
88
|
+
|
|
89
|
+
static styles = css`
|
|
90
|
+
:host {
|
|
91
|
+
display:block;
|
|
92
|
+
font-size: 0.9rem;
|
|
93
|
+
}
|
|
94
|
+
:host([contenteditable][editmode="hidden"]) {
|
|
95
|
+
min-height: 30px;
|
|
96
|
+
background:lightgray;
|
|
97
|
+
font-size: inherit;
|
|
98
|
+
}
|
|
99
|
+
:host div[part='options'] {
|
|
100
|
+
display:none;
|
|
101
|
+
}
|
|
102
|
+
:host([contenteditable]) div[part='options'] {
|
|
103
|
+
display:block;
|
|
104
|
+
}
|
|
105
|
+
:host .controls {
|
|
106
|
+
display:flex;
|
|
107
|
+
flex-direction: row;
|
|
108
|
+
flex-wrap: wrap;
|
|
109
|
+
align-content: center;
|
|
110
|
+
justify-content: flex-start;
|
|
111
|
+
align-items: flex-end;
|
|
112
|
+
gap: 10px;
|
|
113
|
+
}
|
|
114
|
+
#error {
|
|
115
|
+
color:red;
|
|
116
|
+
}
|
|
117
|
+
#error:before {
|
|
118
|
+
content:"⚠";
|
|
119
|
+
}
|
|
120
|
+
`
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The feature engineering widget to use as data source for training the model.
|
|
124
|
+
*/
|
|
125
|
+
@property({ type: String, attribute: true, reflect: true })
|
|
126
|
+
accessor featureWidgetId: string;
|
|
127
|
+
|
|
128
|
+
@query('#feature-select')
|
|
129
|
+
private accessor featureSelect;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The model design widget to use as model source for training.
|
|
133
|
+
*/
|
|
134
|
+
@property({ type: String, attribute: true, reflect: true })
|
|
135
|
+
accessor modelWidgetId: string;
|
|
136
|
+
|
|
137
|
+
@query('#design-select')
|
|
138
|
+
private accessor modelSelect;
|
|
139
|
+
|
|
140
|
+
@query('#start-training')
|
|
141
|
+
private accessor startTrainingBtn;
|
|
142
|
+
|
|
143
|
+
@query('#reset-training')
|
|
144
|
+
private accessor resetTrainingBtn;
|
|
145
|
+
|
|
146
|
+
@query('#training-metrics')
|
|
147
|
+
private accessor trainingMetricsDiv;
|
|
148
|
+
|
|
149
|
+
@query("#speed")
|
|
150
|
+
private accessor speed:HTMLSpanElement;
|
|
151
|
+
|
|
152
|
+
@query("#memory")
|
|
153
|
+
private accessor memory:HTMLSpanElement;
|
|
154
|
+
|
|
155
|
+
@query("#error")
|
|
156
|
+
private accessor error:HTMLSpanElement;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* If true, the transformed training samples will be cached for faster training.
|
|
160
|
+
*/
|
|
161
|
+
@property({ type: Boolean, attribute: true, reflect: true })
|
|
162
|
+
accessor cache: boolean;
|
|
163
|
+
|
|
164
|
+
/** The prefered tfjs backend */
|
|
165
|
+
@property({ type: String, attribute: true, reflect: true })
|
|
166
|
+
accessor currentBackend: "webgl" | "cpu" = "webgl";
|
|
167
|
+
|
|
168
|
+
/** Stores the model jsons with a name like "best" or "epoch-20" for loading by the inference and test widgets */
|
|
169
|
+
@property({ type: Object, attribute: true, reflect: true })
|
|
170
|
+
accessor modelVersions:Record<string, string> = {}
|
|
171
|
+
|
|
172
|
+
/** "edit" means that students can use the widget to train a model while "hidden" means the widget will be invisible to student but the trained models can be used by other widgets. */
|
|
173
|
+
@property({ type: String, attribute: true, reflect: true })
|
|
174
|
+
accessor editMode: "edit"|"hidden" = "edit";
|
|
175
|
+
|
|
176
|
+
@query("#optimizer")
|
|
177
|
+
private accessor optimizer: SlSelect;
|
|
178
|
+
|
|
179
|
+
@query("#lr")
|
|
180
|
+
private accessor lr: SlInput;
|
|
181
|
+
|
|
182
|
+
@query("#momentum")
|
|
183
|
+
private accessor momentum: SlInput;
|
|
184
|
+
|
|
185
|
+
@query("#batch")
|
|
186
|
+
private accessor batch: SlInput;
|
|
187
|
+
|
|
188
|
+
@query("#epochs")
|
|
189
|
+
private accessor epochs: SlInput;
|
|
190
|
+
|
|
191
|
+
constructor() {
|
|
192
|
+
super();
|
|
193
|
+
let that = this;
|
|
194
|
+
setInterval(function() {
|
|
195
|
+
try {
|
|
196
|
+
that.memory.innerText = (tf.memory().numBytes / 1024 / 1024).toFixed(2);
|
|
197
|
+
} catch(e) {}
|
|
198
|
+
}, 50)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
public render(): TemplateResult {
|
|
202
|
+
let that = this;
|
|
203
|
+
setTimeout(function () { that.chart.render() }, 100);
|
|
204
|
+
|
|
205
|
+
function editModeChanged(e: Event) {
|
|
206
|
+
const select = e.target as HTMLSelectElement;
|
|
207
|
+
this.editMode = select.value;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return html`
|
|
211
|
+
<div id="content" style=${this.editMode == "hidden" ? "display:none" : ""}>
|
|
212
|
+
<div class="controls">
|
|
213
|
+
<sl-select id="optimizer" value="adam" label=${msg("Optimizer")} size="small" @sl-change=${this.changeOptimizer}>
|
|
214
|
+
<sl-option value="adam">Adam</sl-option>
|
|
215
|
+
<sl-option value="momentum">Momentum</sl-option>
|
|
216
|
+
<sl-option value="rmsprop">RMSProp</sl-option>
|
|
217
|
+
<sl-option value="sgd">SGD</sl-option>
|
|
218
|
+
</sl-select>
|
|
219
|
+
<sl-input id="lr" type="number" label=${msg("Learning Rate")} min="0.0001" max="0.01" value="0.002" step="0.0005" size="small" style="max-width:100px"></sl-input>
|
|
220
|
+
<sl-input style="display:none" id="momentum" type="number" label=${msg("Momentum")} min="0.1" max="0.99" value="0.9" size="small" style="max-width:100px"></sl-input>
|
|
221
|
+
<sl-input id="batch" type="number" label=${msg("Batch Size")} min="1" max="512" value="128" step="1" size="small" style="max-width:100px"></sl-input>
|
|
222
|
+
<sl-input id="epochs" type="number" label=${msg("Epochs")} min="1" max="500" value="20" size="small" style="max-width:100px"></sl-input>
|
|
223
|
+
<sl-button-group>
|
|
224
|
+
<sl-button id="start-training" @click=${this.training}>${msg("Start training")}</sl-button>
|
|
225
|
+
<sl-button id="reset-training" @click=${this.resetModel}>${msg("Reset")}</sl-button>
|
|
226
|
+
</sl-button-group>
|
|
227
|
+
</div>
|
|
228
|
+
<p id="error" style="display:none"></p>
|
|
229
|
+
<div id="training-metrics" style="display:none">
|
|
230
|
+
${this.chartContainer}
|
|
231
|
+
<sl-select id="metrics" value="Loss Accuracy" multiple clearable @sl-change=${this.updateGraph}>
|
|
232
|
+
<sl-option value="Loss">${msg("Loss")}</sl-option>
|
|
233
|
+
<sl-option value="Accuracy">${msg("Accuracy")}</sl-option>
|
|
234
|
+
<sl-option value="R2_Score">${msg("R2 Score")}</sl-option>
|
|
235
|
+
<sl-option value="Percision">${msg("Precision")}</sl-option>
|
|
236
|
+
<sl-option value="Recall">${msg("Recall")}</sl-option>
|
|
237
|
+
</sl-select>
|
|
238
|
+
<p style="margin:0px">${msg("Training Speed:")} <span id="speed">0</span>s/epoch ${msg("Used Tensor Memory:")} <span id="memory"></span>MB</p>
|
|
239
|
+
</div>
|
|
240
|
+
</div>
|
|
241
|
+
<p style=${this.editMode != "hidden" ? "display:none" : ""}>${msg("Model Training Widget hidden from students.")}</p>
|
|
242
|
+
<div part="options">
|
|
243
|
+
<p>${msg("Feature Source")}</p>
|
|
244
|
+
<ref-select id="feature-select" typeName="Features" elemId=${this.featureWidgetId} elementType="webwriter-feature-engineering" @refchange=${(e) => this.featureWidgetId = e.detail.id} ownerId=${this.id}></ref-select>
|
|
245
|
+
<p>${msg("Design Source")}</p>
|
|
246
|
+
<ref-select id="design-select" typeName="Design" elemId=${this.modelWidgetId} elementType="webwriter-model-designing" @refchange=${(e) => this.modelWidgetId = e.detail.id} ownerId=${this.id}></ref-select>
|
|
247
|
+
<sl-select label=${msg("Edit Permissions")} value=${this.editMode} @sl-change=${editModeChanged}>
|
|
248
|
+
<sl-option value="hidden">${msg("hide widget")}</sl-option>
|
|
249
|
+
<sl-option value="edit">${msg("edit everything")}</sl-option>
|
|
250
|
+
</sl-select>
|
|
251
|
+
<br>
|
|
252
|
+
<sl-select label=${msg("Preferred Backend")} value=${this.currentBackend} @sl-change=${(e) => this.currentBackend = (e.target as HTMLSelectElement).value as ("webgl" | "cpu")}>
|
|
253
|
+
<sl-option value="cpu">${msg("CPU")}</sl-option>
|
|
254
|
+
<sl-option value="webgl">${msg("WebGL (GPU)")}</sl-option>
|
|
255
|
+
</sl-select>
|
|
256
|
+
<br>
|
|
257
|
+
<sl-checkbox ?checked=${this.cache} @sl-change=${() => this.cache = !this.cache}>${msg("Cache training samples")}</sl-checkbox>
|
|
258
|
+
<p>${msg("This allows for the transformed samples to be cached on the computation device thus dramatically increasing training speed but requiring significantly more storage on the device.")}</p>
|
|
259
|
+
<p style="color:red">${msg("(Warning: Too much tensor data can overfill the device RAM and crash during training and in the worst case lock-up the host system.)")}</p>
|
|
260
|
+
</div>`
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
private showError(err:string) {
|
|
264
|
+
this.error.innerHTML = err;
|
|
265
|
+
this.error.style.display = "block";
|
|
266
|
+
}
|
|
267
|
+
private hideError() {
|
|
268
|
+
this.error.style.display = "none";
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
private changeOptimizer() {
|
|
272
|
+
let optimizer = (this.shadowRoot.getElementById("optimizer") as SlSelect).value as string;
|
|
273
|
+
if (optimizer == "momentum") {
|
|
274
|
+
this.shadowRoot.getElementById("momentum").style.display = "";
|
|
275
|
+
} else {
|
|
276
|
+
this.shadowRoot.getElementById("momentum").style.display = "none";
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
private setHyperParamsActive(active:boolean) {
|
|
281
|
+
this.optimizer.disabled = !active;
|
|
282
|
+
this.lr.disabled = !active;
|
|
283
|
+
this.momentum.disabled = !active;
|
|
284
|
+
this.batch.disabled = !active;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
private chartContainer = document.createElement("div")
|
|
288
|
+
private losses: Record<string, Array<number>> = {};
|
|
289
|
+
private insights: Record<string, any> = {min_val_loss: 100, min_val_loss_index: 0};
|
|
290
|
+
private chart = new ApexCharts(this.chartContainer, {
|
|
291
|
+
series: [],
|
|
292
|
+
chart: {
|
|
293
|
+
id: 'realtime',
|
|
294
|
+
height: 200,
|
|
295
|
+
type: 'line',
|
|
296
|
+
animations: {
|
|
297
|
+
enabled: false
|
|
298
|
+
},
|
|
299
|
+
toolbar: {
|
|
300
|
+
show: false
|
|
301
|
+
},
|
|
302
|
+
zoom: {
|
|
303
|
+
enabled: false
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
dataLabels: {
|
|
307
|
+
enabled: false
|
|
308
|
+
},
|
|
309
|
+
title: {
|
|
310
|
+
text: 'Training Metrics',
|
|
311
|
+
align: 'left'
|
|
312
|
+
},
|
|
313
|
+
markers: {
|
|
314
|
+
size: 0
|
|
315
|
+
},
|
|
316
|
+
xaxis: {
|
|
317
|
+
type: 'number',
|
|
318
|
+
labels: {
|
|
319
|
+
rotate: -90,
|
|
320
|
+
tickAmount: 10,
|
|
321
|
+
hideOverlappingLabels: true,
|
|
322
|
+
step: 5
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
yaxis: {
|
|
326
|
+
min: 0
|
|
327
|
+
},
|
|
328
|
+
legend: {
|
|
329
|
+
show: false
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Used to recursively connect the inputs via the layers to the output nodes.
|
|
335
|
+
* @param layer One output layer of the model to solve the dependencies for.
|
|
336
|
+
* @param inputs All the input tensors of the model with the "in_<feature>"" as the key.
|
|
337
|
+
* @param resolvedLayers A reference to an array storing the already resolved layers for later use when solving for other output layers.
|
|
338
|
+
* @returns Returns a NoOpLayer with an output name of "out_<feature>"
|
|
339
|
+
*/
|
|
340
|
+
resolveOutput(layer: Layer, inputs: Record<string, TF.SymbolicTensor>, resolvedLayers: Record<number, any>): TF.SymbolicTensor {
|
|
341
|
+
let visitedLayersInThisPath = [];
|
|
342
|
+
|
|
343
|
+
function resolveLayer(layer: Layer, input_layers: Record<string, TF.SymbolicTensor>): Record<string, TF.SymbolicTensor> {
|
|
344
|
+
if (visitedLayersInThisPath.indexOf(layer.id) != -1)
|
|
345
|
+
throw Error("cyclic dependency in network")
|
|
346
|
+
if (resolvedLayers[layer.id] != null)
|
|
347
|
+
return resolvedLayers[layer.id];
|
|
348
|
+
|
|
349
|
+
let outputTensor = layer.forward(input_layers)
|
|
350
|
+
resolvedLayers[layer.id] = outputTensor;
|
|
351
|
+
visitedLayersInThisPath.push(layer.id);
|
|
352
|
+
return outputTensor;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function resolveDependencies(layer:Layer) {
|
|
356
|
+
if (layer.getState().type == "input") {
|
|
357
|
+
return resolveLayer(layer, inputs);
|
|
358
|
+
} else {
|
|
359
|
+
let input_layers = {};
|
|
360
|
+
let layers = layer.getInputLayers();
|
|
361
|
+
for (let input in layers) {
|
|
362
|
+
let resolvedLayer = resolveDependencies(layers[input].outputOfLayer)
|
|
363
|
+
input_layers[input] = resolvedLayer[layers[input].outputField];
|
|
364
|
+
}
|
|
365
|
+
return resolveLayer(layer, input_layers);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return new (window as any).NoOpLayer({name: "out_" + layer.getState().select}).apply(resolveDependencies(Object.values(layer.getInputLayers())[0].outputOfLayer).output_1) as TF.SymbolicTensor;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Builds the complete tfjs model using the layers from the model design widget. It sets the correct input names for the input layers as "in_<feature>". The output layers dependency graph is build and the loss is applied to the output tensor for training.
|
|
374
|
+
* @returns Model and losses for training
|
|
375
|
+
*/
|
|
376
|
+
async buildModel() {
|
|
377
|
+
this.hideError();
|
|
378
|
+
let design = this.modelSelect.getRefElement() as AiWidgetsDesigns;
|
|
379
|
+
|
|
380
|
+
let featureWidget = this.featureSelect.getRefElement() as AiWidgetsFeatures;
|
|
381
|
+
let dataset = featureWidget?.getDataset()?.tensorDataset;
|
|
382
|
+
if (dataset == null) {
|
|
383
|
+
this.showError("The feature data is not ready yet. Please wait a moment and try again.")
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
let model = null;
|
|
388
|
+
try { model = design.getModel(); } catch (e) { console.warn("Live model export failed, using saved state.", e); }
|
|
389
|
+
let missingSelection = !model || model.length == 0 || model.some(l => (l.type == "input" || l.type == "output") && (l.select == null || l.select == ""));
|
|
390
|
+
if (missingSelection && design.state)
|
|
391
|
+
model = JSON.parse(design.state);
|
|
392
|
+
|
|
393
|
+
if (model == null || model.length == 0) {
|
|
394
|
+
this.showError("No model design available.")
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
let editor = new Editor(document.createElement("div"), "read", design.maxModelParameters, design.maxLayerParameters);
|
|
399
|
+
await editor.import(model, dataset)
|
|
400
|
+
|
|
401
|
+
if (editor.getNumberOfParameters() > design.maxModelParameters) {
|
|
402
|
+
this.showError("The Neural Network is to large. Reduce the overall number of parameters.")
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
for (let layer of model) {
|
|
407
|
+
if (!layer.valid) {
|
|
408
|
+
this.showError("A layer has an Invalid configuration.")
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
let inputs: Record<string, TF.SymbolicTensor> = {};
|
|
414
|
+
for (let input_node of model.filter(l => l.type == "input")) {
|
|
415
|
+
let shape = dataset.featureMaps[input_node.select].size();
|
|
416
|
+
inputs[input_node.select] = tf.input({ shape: shape , name:"in_" + input_node.select});
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
let outputs: Record<string, TF.SymbolicTensor> = {};
|
|
420
|
+
let resolvedLayers = {};
|
|
421
|
+
let losses = {};
|
|
422
|
+
for (let output of editor.getOutputs()) {
|
|
423
|
+
outputs[output.getState().select] = this.resolveOutput(output, inputs, resolvedLayers);
|
|
424
|
+
losses["out_" + output.getState().select] = this.lossStringToFunction(output.getState().loss);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return {model:tf.model({ inputs: Object.values(inputs), outputs: Object.values(outputs) }), losses}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Converts a loss string to the corresponding tfjs loss function.
|
|
432
|
+
* @param loss The loss string like "MSE" or "BCE"
|
|
433
|
+
* @returns The tfjs loss function
|
|
434
|
+
*/
|
|
435
|
+
lossStringToFunction(loss: string) {
|
|
436
|
+
switch(loss) {
|
|
437
|
+
case "BCE": return tf.metrics.binaryCrossentropy;
|
|
438
|
+
case "MAE": return tf.metrics.meanAbsoluteError;
|
|
439
|
+
case "Huber": return tf.losses.huberLoss;
|
|
440
|
+
case "MSE": return tf.metrics.meanSquaredError;
|
|
441
|
+
case "Difference": return tf.losses.absoluteDifference;
|
|
442
|
+
case "WL": return tf.losses.computeWeightedLoss;
|
|
443
|
+
case "CosDist": return tf.losses.cosineDistance;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
private updateGraph() {
|
|
448
|
+
let metrics = (this.shadowRoot.getElementById("metrics") as SlSelect).value as string[]
|
|
449
|
+
this.chart.updateSeries(
|
|
450
|
+
Object.entries(this.losses).map(
|
|
451
|
+
function ([k, v]) { return { name: k, data: v } }
|
|
452
|
+
).filter(e => metrics.indexOf(e.name.replace("Training_","").replace("Validation_", "")) != -1)
|
|
453
|
+
)
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Returns the model for named checkpoints for other widgets to use.
|
|
458
|
+
* @param name The checkpoint name like "best" or "epoch-20". All the available checkpoints can be retrieved via this.getAvailableModels().
|
|
459
|
+
* @returns The tf.LayersModel in an initialized state ready for use.
|
|
460
|
+
*/
|
|
461
|
+
public async getModel(name) {
|
|
462
|
+
if (this.modelVersions == null || this.modelVersions[name] == null)
|
|
463
|
+
return null;
|
|
464
|
+
const jsonObj = JSON.parse(this.modelVersions[name]);
|
|
465
|
+
const modelWeights = hexToUint8(jsonObj.weightData);
|
|
466
|
+
const handler = {
|
|
467
|
+
load: async () => {
|
|
468
|
+
const modelArtifacts = {
|
|
469
|
+
modelTopology: jsonObj.modelTopology,
|
|
470
|
+
weightSpecs: jsonObj.weightSpecs,
|
|
471
|
+
weightData: modelWeights.buffer,
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
return modelArtifacts;
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
const model = await tf.loadLayersModel(handler);
|
|
479
|
+
return model;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/** Returns the available model checkpoints */
|
|
483
|
+
public getAvailableModels() {
|
|
484
|
+
return Object.keys(this.modelVersions);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/** Deletes all model checkpoints */
|
|
488
|
+
private clearModels() {
|
|
489
|
+
this.modelVersions = {};
|
|
490
|
+
this.dispatchEvent(new CustomEvent('finished', {detail: {}}));
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/** Is true, while tf is in the training process */
|
|
494
|
+
private isTraining = false;
|
|
495
|
+
|
|
496
|
+
/** contains the currently trained model */
|
|
497
|
+
private currentTraining: TF.LayersModel;
|
|
498
|
+
private currentEpoch = 0;
|
|
499
|
+
|
|
500
|
+
/** A list of available backends for tf to use. Could be expanded and are tried out in order. (Not all backends support all layer and operation types, but can provide better training speed) */
|
|
501
|
+
private backendPriority = ["webgl","cpu"];
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Sets the state of this training widget back to the initial configuration and deletes previous training progress.
|
|
505
|
+
*/
|
|
506
|
+
private resetModel() {
|
|
507
|
+
this.hideError();
|
|
508
|
+
this.trainingMetricsDiv.style.display = "none";
|
|
509
|
+
if (this.currentTraining)
|
|
510
|
+
this.currentTraining.dispose();
|
|
511
|
+
this.currentTraining = null;
|
|
512
|
+
this.clearModels();
|
|
513
|
+
this.losses = {}
|
|
514
|
+
this.currentEpoch = 0;
|
|
515
|
+
this.insights = {min_val_loss: 100, min_val_loss_index: 0};
|
|
516
|
+
if (this.chart != null)
|
|
517
|
+
this.chart.removeAnnotation("best");
|
|
518
|
+
this.updateGraph();
|
|
519
|
+
this.setHyperParamsActive(true);
|
|
520
|
+
this.startTrainingBtn.innerText = msg("Start Training");
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Initializes the model for training and preps the UI.
|
|
525
|
+
*/
|
|
526
|
+
async initModel() {
|
|
527
|
+
if (this.isTraining)
|
|
528
|
+
return;
|
|
529
|
+
|
|
530
|
+
this.hideError();
|
|
531
|
+
if (this.currentTraining)
|
|
532
|
+
this.currentTraining.dispose();
|
|
533
|
+
|
|
534
|
+
try {
|
|
535
|
+
await tf.setBackend(this.currentBackend); // cpu, webgl, wasm
|
|
536
|
+
await tf.ready();
|
|
537
|
+
let built = await this.buildModel();
|
|
538
|
+
if (built == null || built.model == null || built.losses == null)
|
|
539
|
+
return;
|
|
540
|
+
let {model, losses} = built;
|
|
541
|
+
this.setHyperParamsActive(false);
|
|
542
|
+
this.currentTraining = model;
|
|
543
|
+
let optimizer = (this.shadowRoot.getElementById("optimizer") as SlSelect).value as string;
|
|
544
|
+
let lr = parseFloat(this.lr.value);
|
|
545
|
+
let momentum = parseFloat(this.momentum.value);
|
|
546
|
+
model.compile({
|
|
547
|
+
optimizer: optimizer != "momentum" ? tf.train[optimizer](lr) : tf.train["momentum"](lr, momentum),
|
|
548
|
+
loss: losses,
|
|
549
|
+
metrics: ["accuracy", tf.metrics.r2Score, tf.metrics.precision, tf.metrics.recall],
|
|
550
|
+
});
|
|
551
|
+
model.summary();
|
|
552
|
+
} catch (e) {
|
|
553
|
+
console.error(e);
|
|
554
|
+
this.showError("Could not build the model. Please check the model design and feature data.")
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Runs the tf training loop and keeps the UI up-to-date
|
|
560
|
+
*/
|
|
561
|
+
async training() {
|
|
562
|
+
let that = this;
|
|
563
|
+
if (this.currentTraining != null && this.isTraining) {
|
|
564
|
+
this.currentTraining.stopTraining = true;
|
|
565
|
+
this.isTraining = false;
|
|
566
|
+
console.log("stop training")
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
if (this.currentTraining == null) {
|
|
571
|
+
await this.initModel();
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
if (this.currentTraining == null)
|
|
575
|
+
return;
|
|
576
|
+
|
|
577
|
+
this.trainingMetricsDiv.style.display = "";
|
|
578
|
+
this.startTrainingBtn.innerText = msg("Stop Training");
|
|
579
|
+
|
|
580
|
+
if (this.currentTraining != null && !this.isTraining) {
|
|
581
|
+
this.isTraining = true;
|
|
582
|
+
this.resetTrainingBtn.disabled = true;
|
|
583
|
+
let dataset = (this.featureSelect.getRefElement() as AiWidgetsFeatures).getDataset().tensorDataset;
|
|
584
|
+
let model = (this.modelSelect.getRefElement() as AiWidgetsDesigns).getModel();
|
|
585
|
+
|
|
586
|
+
let inputNames: Set<string> = new Set();
|
|
587
|
+
for (let input_node of model.filter(l => l.type == "input"))
|
|
588
|
+
inputNames.add(input_node.select)
|
|
589
|
+
|
|
590
|
+
let outputNames: Set<string> = new Set();
|
|
591
|
+
for (let output_node of model.filter(l => l.type == "output"))
|
|
592
|
+
outputNames.add(output_node.select);
|
|
593
|
+
|
|
594
|
+
let batchsize = parseInt(this.batch.value)
|
|
595
|
+
const tfDataset = tf.data.generator(dataset.getTrainingDataGenerator(inputNames, outputNames, this.cache)).batch(batchsize).prefetch(4)
|
|
596
|
+
const valDataset = tf.data.generator(dataset.getValidationDataGenerator(inputNames, outputNames, this.cache)).batch(batchsize).prefetch(4)
|
|
597
|
+
|
|
598
|
+
let lastEpoch = Date.now();
|
|
599
|
+
let numEpochs = parseInt(this.epochs.value);
|
|
600
|
+
|
|
601
|
+
await this.currentTraining.fitDataset(tfDataset, {
|
|
602
|
+
epochs: this.currentEpoch + numEpochs + 1,
|
|
603
|
+
validationData: valDataset,
|
|
604
|
+
initialEpoch: this.currentEpoch + 1,
|
|
605
|
+
callbacks: {
|
|
606
|
+
onEpochEnd: async (epoch, logs) => {
|
|
607
|
+
if (this.currentTraining.stopTraining == true)
|
|
608
|
+
return;
|
|
609
|
+
for (let loss in logs) {
|
|
610
|
+
let label = loss.replace("loss","Loss").replace("acc","Accuracy").replace("r2Score2","R2_Score").replace("recall2","Recall").replace("percision2","Percision").replace("val_","Validation_");
|
|
611
|
+
if (label.indexOf("Validation") == -1)
|
|
612
|
+
label = "Training_" + label;
|
|
613
|
+
|
|
614
|
+
//label = loss;
|
|
615
|
+
|
|
616
|
+
if (this.losses[label] == null)
|
|
617
|
+
this.losses[label] = [];
|
|
618
|
+
this.losses[label].push(Math.round(logs[loss] * 1000) / 1000);
|
|
619
|
+
if (loss == "val_loss" && logs[loss] < this.insights.min_val_loss ) {
|
|
620
|
+
this.insights.min_val_loss = logs[loss];
|
|
621
|
+
this.insights.min_val_loss_index = epoch;
|
|
622
|
+
await this.saveCurrentModel('best');
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
//if (epoch % 5 == 0)
|
|
627
|
+
//await this.saveCurrentModel('epoch-' + epoch);
|
|
628
|
+
|
|
629
|
+
that.updateGraph();
|
|
630
|
+
this.chart.removeAnnotation("best");
|
|
631
|
+
this.chart.addPointAnnotation({
|
|
632
|
+
id: "best",
|
|
633
|
+
x: this.insights.min_val_loss_index,
|
|
634
|
+
y: this.insights.min_val_loss,
|
|
635
|
+
label: {
|
|
636
|
+
text: "Best",
|
|
637
|
+
style: {
|
|
638
|
+
background: "#FF4560",
|
|
639
|
+
color: "#fff"
|
|
640
|
+
}
|
|
641
|
+
},
|
|
642
|
+
marker: {
|
|
643
|
+
size: 6,
|
|
644
|
+
fillColor: "#fff",
|
|
645
|
+
strokeColor: "#FF4560"
|
|
646
|
+
}
|
|
647
|
+
})
|
|
648
|
+
this.currentEpoch = epoch;
|
|
649
|
+
|
|
650
|
+
this.speed.innerText = (((Date.now() - lastEpoch) / 1000) * 0.7 + parseFloat(this.speed.innerText) * 0.3).toFixed(2);
|
|
651
|
+
lastEpoch = Date.now();
|
|
652
|
+
|
|
653
|
+
this.dispatchEvent(new CustomEvent('epoch', {detail: {}}));
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}).then(async function() {
|
|
657
|
+
that.resetTrainingBtn.disabled = false;
|
|
658
|
+
that.currentTraining.stopTraining = false;
|
|
659
|
+
that.startTrainingBtn.innerText = msg("Continue Training");
|
|
660
|
+
that.isTraining = false;
|
|
661
|
+
await that.saveCurrentModel('epoch-' + that.currentEpoch);
|
|
662
|
+
that.modelVersions = JSON.parse(JSON.stringify(that.modelVersions));
|
|
663
|
+
}).catch(async function(err) {
|
|
664
|
+
console.error(err);
|
|
665
|
+
that.resetTrainingBtn.disabled = false;
|
|
666
|
+
that.currentTraining.stopTraining = false;
|
|
667
|
+
that.startTrainingBtn.innerText = msg("Continue Training");
|
|
668
|
+
that.isTraining = false;
|
|
669
|
+
let index = that.backendPriority.indexOf(tf.getBackend()) + 1
|
|
670
|
+
if (index == that.backendPriority.length)
|
|
671
|
+
console.error("The model is broken.");
|
|
672
|
+
console.warn("switching to backend " + that.backendPriority[index]);
|
|
673
|
+
that.currentBackend = that.backendPriority[index] as ("cpu" | "webgl");
|
|
674
|
+
await that.initModel();
|
|
675
|
+
await that.training();
|
|
676
|
+
});
|
|
677
|
+
this.dispatchEvent(new CustomEvent('finished', {detail: {}}));
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
/** This is called when the widget is removed from the UI (i.e. deleted by the user or reload) */
|
|
682
|
+
async disconnectedCallback(): Promise<void> {
|
|
683
|
+
tf.backend().dispose();
|
|
684
|
+
tf.dispose();
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Saves the current model as a checkpoint for other widgets to use later.
|
|
689
|
+
* @param name The checkpoint name.
|
|
690
|
+
*/
|
|
691
|
+
async saveCurrentModel(name) {
|
|
692
|
+
let that = this;
|
|
693
|
+
|
|
694
|
+
async function handleSave(artifats) {
|
|
695
|
+
const weightData = new Uint8Array(artifats.weightData);
|
|
696
|
+
const b64encoded = uint8ToHex(weightData);
|
|
697
|
+
|
|
698
|
+
that.modelVersions[name] = JSON.stringify({
|
|
699
|
+
modelTopology: artifats.modelTopology,
|
|
700
|
+
weightSpecs: artifats.weightSpecs,
|
|
701
|
+
weightData: b64encoded
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
return {} as TF.io.SaveResult;
|
|
705
|
+
}
|
|
706
|
+
await this.currentTraining.save(tf.io.withSaveHandler(handleSave));
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|