@webwriter/deep-learning-model 0.0.1 → 1.0.1
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 +273 -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 +1446 -0
- package/custom.d.ts +180 -0
- package/dist/widgets/webwriter-feature-engineering.css +444 -0
- package/dist/widgets/webwriter-feature-engineering.js +112241 -0
- package/dist/widgets/webwriter-model-designing.css +444 -0
- package/dist/widgets/webwriter-model-designing.js +113967 -0
- package/dist/widgets/webwriter-model-evaluation.css +444 -0
- package/dist/widgets/webwriter-model-evaluation.js +119019 -0
- package/dist/widgets/webwriter-model-prediction.css +444 -0
- package/dist/widgets/webwriter-model-prediction.js +109260 -0
- package/dist/widgets/webwriter-model-training.css +444 -0
- package/dist/widgets/webwriter-model-training.js +121391 -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 +708 -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 +6 -0
- package/lit-localize.json +47 -0
- package/localization/ar.xlf +532 -0
- package/localization/bg.xlf +531 -0
- package/localization/cs.xlf +532 -0
- package/localization/da.xlf +531 -0
- package/localization/de.xlf +531 -0
- package/localization/el.xlf +533 -0
- package/localization/es.xlf +532 -0
- package/localization/et.xlf +532 -0
- package/localization/fi.xlf +531 -0
- package/localization/fr.xlf +532 -0
- package/localization/generated/ar.ts +158 -0
- package/localization/generated/bg.ts +157 -0
- package/localization/generated/cs.ts +158 -0
- package/localization/generated/da.ts +157 -0
- package/localization/generated/de.ts +157 -0
- package/localization/generated/el.ts +159 -0
- package/localization/generated/es.ts +158 -0
- package/localization/generated/et.ts +158 -0
- package/localization/generated/fi.ts +157 -0
- package/localization/generated/fr.ts +158 -0
- package/localization/generated/hu.ts +157 -0
- package/localization/generated/id.ts +158 -0
- package/localization/generated/index.js +3 -0
- package/localization/generated/it.ts +158 -0
- package/localization/generated/ja.ts +157 -0
- package/localization/generated/ko.ts +157 -0
- package/localization/generated/locale-codes.js +83 -0
- package/localization/generated/lt.ts +157 -0
- package/localization/generated/lv.ts +157 -0
- package/localization/generated/nb.ts +157 -0
- package/localization/generated/nl.ts +157 -0
- package/localization/generated/pl.ts +158 -0
- package/localization/generated/pt-BR.ts +158 -0
- package/localization/generated/pt-PT.ts +158 -0
- package/localization/generated/ro.ts +158 -0
- package/localization/generated/ru.ts +158 -0
- package/localization/generated/sk.ts +158 -0
- package/localization/generated/sl.ts +158 -0
- package/localization/generated/sv.ts +157 -0
- package/localization/generated/tr.ts +157 -0
- package/localization/generated/uk.ts +157 -0
- package/localization/generated/zh-hans.ts +140 -0
- package/localization/generated/zh-hant.ts +140 -0
- package/localization/hu.xlf +531 -0
- package/localization/id.xlf +532 -0
- package/localization/it.xlf +532 -0
- package/localization/ja.xlf +531 -0
- package/localization/ko.xlf +531 -0
- package/localization/lt.xlf +531 -0
- package/localization/lv.xlf +531 -0
- package/localization/nb.xlf +531 -0
- package/localization/nl.xlf +531 -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 +532 -0
- package/localization/pt-BR.xlf +532 -0
- package/localization/pt-PT.xlf +532 -0
- package/localization/ro.xlf +532 -0
- package/localization/ru.xlf +532 -0
- package/localization/sk.xlf +532 -0
- package/localization/sl.xlf +532 -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 +531 -0
- package/localization/tr.xlf +531 -0
- package/localization/uk.xlf +531 -0
- package/localization/zh-hans.xlf +531 -0
- package/localization/zh-hant.xlf +531 -0
- package/package.json +104 -3
- 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 +300 -0
- package/widgets/webwriter-model-evaluation.ts +215 -0
- package/widgets/webwriter-model-prediction.ts +307 -0
- package/widgets/webwriter-model-training.ts +684 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { msg } from "@lit/localize";
|
|
2
|
+
import { SlButton, SlButtonGroup, SlIcon, SlIconButton, SlInput, SlOption, SlSelect } from "@shoelace-style/shoelace";
|
|
3
|
+
import { LitElementWw } from "@webwriter/lit";
|
|
4
|
+
import { css, html, TemplateResult } from "lit";
|
|
5
|
+
import { until } from 'lit-html/directives/until.js';
|
|
6
|
+
import { property } from "lit/decorators.js";
|
|
7
|
+
import { Dataset, TransformedDataset } from "../../lib/dataset/dataset";
|
|
8
|
+
|
|
9
|
+
import type * as TF from "@tensorflow/tfjs";
|
|
10
|
+
import getTF from "../../lib/tflib";
|
|
11
|
+
let tf: typeof TF;
|
|
12
|
+
(async () => {tf = await getTF()})()
|
|
13
|
+
|
|
14
|
+
async function waitFor(condition: Function, interval = 10) {
|
|
15
|
+
if (condition())
|
|
16
|
+
return;
|
|
17
|
+
return new Promise(async function(res, rej) {
|
|
18
|
+
let inter = setInterval(function() {
|
|
19
|
+
if (condition()) {
|
|
20
|
+
clearInterval(inter)
|
|
21
|
+
res(null);
|
|
22
|
+
}
|
|
23
|
+
}, interval)
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class BadSamples extends LitElementWw {
|
|
28
|
+
static scopedElements = {
|
|
29
|
+
"sl-button": SlButton,
|
|
30
|
+
"sl-button-group": SlButtonGroup,
|
|
31
|
+
"sl-option": SlOption,
|
|
32
|
+
"sl-select": SlSelect,
|
|
33
|
+
"sl-input":SlInput,
|
|
34
|
+
"sl-icon": SlIcon,
|
|
35
|
+
"sl-icon-button": SlIconButton,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static styles = css`
|
|
39
|
+
#container {
|
|
40
|
+
display: flex;
|
|
41
|
+
flex-direction: row;
|
|
42
|
+
flex-wrap: wrap;
|
|
43
|
+
align-content: flex-start;
|
|
44
|
+
justify-content: center;
|
|
45
|
+
align-items: flex-start;
|
|
46
|
+
gap: 5px;
|
|
47
|
+
}
|
|
48
|
+
#container * {
|
|
49
|
+
flex-grow: 1;
|
|
50
|
+
}
|
|
51
|
+
#top {
|
|
52
|
+
width: 100%;
|
|
53
|
+
display: flex;
|
|
54
|
+
}
|
|
55
|
+
.input, .output {
|
|
56
|
+
padding: 5px 10px;
|
|
57
|
+
position: relative;
|
|
58
|
+
border: 1px solid lightgrey;
|
|
59
|
+
border-radius: 5px;
|
|
60
|
+
}
|
|
61
|
+
.input > *, .output > * {
|
|
62
|
+
width: 100%;
|
|
63
|
+
}
|
|
64
|
+
.input > p, .output > p {
|
|
65
|
+
margin: 0px;
|
|
66
|
+
font-size: 16px;
|
|
67
|
+
}
|
|
68
|
+
table {
|
|
69
|
+
width:100%;
|
|
70
|
+
}
|
|
71
|
+
table td {
|
|
72
|
+
padding: 0px 10px;
|
|
73
|
+
}
|
|
74
|
+
`
|
|
75
|
+
|
|
76
|
+
@property()
|
|
77
|
+
accessor model:TF.LayersModel;
|
|
78
|
+
|
|
79
|
+
@property()
|
|
80
|
+
accessor rawDataset: Dataset;
|
|
81
|
+
|
|
82
|
+
@property()
|
|
83
|
+
accessor tensorDataset: TransformedDataset;
|
|
84
|
+
|
|
85
|
+
constructor() {
|
|
86
|
+
super();
|
|
87
|
+
let that = this;
|
|
88
|
+
setTimeout(function() {
|
|
89
|
+
that.requestUpdate();
|
|
90
|
+
}, 1000)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async getBadSamples() {
|
|
94
|
+
let model = this.model;
|
|
95
|
+
let errors = [];
|
|
96
|
+
|
|
97
|
+
for (let i = this.rawDataset.validationEnd; i < this.rawDataset.length(); i++) {
|
|
98
|
+
let sample = await this.tensorDataset.getSample(i);
|
|
99
|
+
tf.tidy(() => {
|
|
100
|
+
let inputs = Object.entries(sample).filter(([s,v]) => model.inputNames.indexOf("in_" + s) != -1).map(([s,v]) => v)
|
|
101
|
+
inputs = inputs.map(i => i.reshape([1 , ...i.shape]))
|
|
102
|
+
let out = model.predict(inputs, {batchSize:1});
|
|
103
|
+
let err;
|
|
104
|
+
if (out instanceof Array) {
|
|
105
|
+
|
|
106
|
+
} else {
|
|
107
|
+
out = out.squeeze();
|
|
108
|
+
tf.keep(out);
|
|
109
|
+
let diff = sample[model.outputNames[0].replace("out_","")].sub(out);
|
|
110
|
+
err = diff.abs().sum();
|
|
111
|
+
}
|
|
112
|
+
errors.push({sample: i, loss:err.arraySync(), pred:out})
|
|
113
|
+
})
|
|
114
|
+
Object.values(sample).forEach(t => t.dispose());
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let sorted = errors.sort((e1 , e2) => e2.loss - e1.loss).slice(0,6);
|
|
118
|
+
let that = this;
|
|
119
|
+
let output = [];
|
|
120
|
+
for (let err of sorted) {
|
|
121
|
+
let tData = []
|
|
122
|
+
for (let inName of model.inputNames) {
|
|
123
|
+
let featureName = inName.replace("in_","");
|
|
124
|
+
let sample = that.rawDataset.getSample(err.sample)
|
|
125
|
+
let features = that.tensorDataset.featureMaps;
|
|
126
|
+
let featureElement = features[featureName].renderTransformedValue(sample[featureName]);
|
|
127
|
+
tData.push(html`<td>${featureElement}</td>`)
|
|
128
|
+
}
|
|
129
|
+
for (let outName of model.outputNames) {
|
|
130
|
+
let featureName = outName.replace("out_","");
|
|
131
|
+
let sample = that.rawDataset.getSample(err.sample)
|
|
132
|
+
let features = that.tensorDataset.featureMaps;
|
|
133
|
+
let label = await features[featureName].transform(sample[featureName]);
|
|
134
|
+
let featureElement = features[featureName].renderPredictionDifference(err.pred, label);
|
|
135
|
+
//label.dispose();
|
|
136
|
+
tData.push(html`<td>${featureElement}</td>`)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
output.push(html`<tr>${tData}<td>${err.loss.toFixed(3)}</td></tr>`);
|
|
140
|
+
};
|
|
141
|
+
let names = [...model.inputNames.map(name => name.replace("in_","")), ...model.outputNames.map(name => name.replace("out_","")), "Absolute Difference"]
|
|
142
|
+
|
|
143
|
+
return html`<table><thead><tr>${names.map(n => html`<td>${n}</td>`)}</tr></thead><tbody>${output}</tbody></table>`
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
public render(): TemplateResult {
|
|
147
|
+
if (this.model == null)
|
|
148
|
+
return html`<p>${msg("Loading model...")}</p>`
|
|
149
|
+
|
|
150
|
+
return html`${until(this.getBadSamples(), html`<p>${msg("Calculating Loss For Samples...")}</p>`)}`
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { msg } from "@lit/localize";
|
|
2
|
+
import { SlButton, SlButtonGroup, SlIcon, SlIconButton, SlInput, SlOption, SlSelect } from "@shoelace-style/shoelace";
|
|
3
|
+
import { LitElementWw } from "@webwriter/lit";
|
|
4
|
+
import ApexCharts from "apexcharts";
|
|
5
|
+
import { css, html, TemplateResult } from "lit";
|
|
6
|
+
import { until } from 'lit-html/directives/until.js';
|
|
7
|
+
import { property } from "lit/decorators.js";
|
|
8
|
+
import { Dataset, TransformedDataset } from "../../lib/dataset/dataset";
|
|
9
|
+
|
|
10
|
+
import type * as TF from "@tensorflow/tfjs";
|
|
11
|
+
import getTF from "../../lib/tflib";
|
|
12
|
+
let tf: typeof TF;
|
|
13
|
+
(async () => {tf = await getTF()})()
|
|
14
|
+
|
|
15
|
+
async function waitFor(condition: Function, interval = 10) {
|
|
16
|
+
if (condition())
|
|
17
|
+
return;
|
|
18
|
+
return new Promise(async function(res, rej) {
|
|
19
|
+
let inter = setInterval(function() {
|
|
20
|
+
if (condition()) {
|
|
21
|
+
clearInterval(inter)
|
|
22
|
+
res(null);
|
|
23
|
+
}
|
|
24
|
+
}, interval)
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class LossDistribution extends LitElementWw {
|
|
29
|
+
static scopedElements = {
|
|
30
|
+
"sl-button": SlButton,
|
|
31
|
+
"sl-button-group": SlButtonGroup,
|
|
32
|
+
"sl-option": SlOption,
|
|
33
|
+
"sl-select": SlSelect,
|
|
34
|
+
"sl-input":SlInput,
|
|
35
|
+
"sl-icon": SlIcon,
|
|
36
|
+
"sl-icon-button": SlIconButton,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static styles = css`
|
|
40
|
+
#container {
|
|
41
|
+
display: flex;
|
|
42
|
+
flex-direction: row;
|
|
43
|
+
flex-wrap: wrap;
|
|
44
|
+
align-content: flex-start;
|
|
45
|
+
justify-content: center;
|
|
46
|
+
align-items: flex-start;
|
|
47
|
+
gap: 5px;
|
|
48
|
+
}
|
|
49
|
+
#container * {
|
|
50
|
+
flex-grow: 1;
|
|
51
|
+
}
|
|
52
|
+
#top {
|
|
53
|
+
width: 100%;
|
|
54
|
+
display: flex;
|
|
55
|
+
}
|
|
56
|
+
.input, .output {
|
|
57
|
+
padding: 5px 10px;
|
|
58
|
+
position: relative;
|
|
59
|
+
border: 1px solid lightgrey;
|
|
60
|
+
border-radius: 5px;
|
|
61
|
+
}
|
|
62
|
+
.input > *, .output > * {
|
|
63
|
+
width: 100%;
|
|
64
|
+
}
|
|
65
|
+
.input > p, .output > p {
|
|
66
|
+
margin: 0px;
|
|
67
|
+
font-size: 16px;
|
|
68
|
+
}
|
|
69
|
+
`
|
|
70
|
+
|
|
71
|
+
@property()
|
|
72
|
+
accessor model:TF.LayersModel;
|
|
73
|
+
|
|
74
|
+
@property()
|
|
75
|
+
accessor rawDataset: Dataset;
|
|
76
|
+
|
|
77
|
+
@property()
|
|
78
|
+
accessor tensorDataset: TransformedDataset;
|
|
79
|
+
|
|
80
|
+
constructor() {
|
|
81
|
+
super();
|
|
82
|
+
let that = this;
|
|
83
|
+
setTimeout(function() {
|
|
84
|
+
that.requestUpdate();
|
|
85
|
+
}, 1000)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async getDiagram() {
|
|
89
|
+
let model = this.model;
|
|
90
|
+
let errors = [];
|
|
91
|
+
|
|
92
|
+
for (let i = this.rawDataset.validationEnd; i < this.rawDataset.length(); i++) {
|
|
93
|
+
let sample = await this.tensorDataset.getSample(i);
|
|
94
|
+
tf.tidy(() => {
|
|
95
|
+
let inputs = Object.entries(sample).filter(([s,v]) => model.inputNames.indexOf("in_" + s) != -1).map(([s,v]) => v)
|
|
96
|
+
inputs = inputs.map(i => i.reshape([1 , ...i.shape]))
|
|
97
|
+
let out = model.predict(inputs, {batchSize:1}) as TF.Tensor;
|
|
98
|
+
let diff = sample[model.outputNames[0].replace("out_","")].sub(out);
|
|
99
|
+
let err = diff.abs().sum();
|
|
100
|
+
errors.push(err.arraySync())
|
|
101
|
+
})
|
|
102
|
+
Object.values(sample).forEach(t => t.dispose());
|
|
103
|
+
}
|
|
104
|
+
//errors = errors.filter(v => v < 0.1)
|
|
105
|
+
|
|
106
|
+
let min = Math.min(...errors)
|
|
107
|
+
let max = Math.max(...errors)
|
|
108
|
+
let bins = new Array<number>(5);
|
|
109
|
+
let titles = []
|
|
110
|
+
bins.fill(0);
|
|
111
|
+
for (let e of errors) {
|
|
112
|
+
let p = (e - min) / (max - min)
|
|
113
|
+
bins[Math.floor(p * bins.length)] += 1;
|
|
114
|
+
}
|
|
115
|
+
bins.pop(); // Because we always round down the bins
|
|
116
|
+
for (let b = 0; b < bins.length; b++) {
|
|
117
|
+
let p = b / bins.length;
|
|
118
|
+
titles[b] = (p * (max - min) + min).toPrecision(3) + " - " + ((p + 1 / bins.length) * (max - min) + min).toPrecision(3);
|
|
119
|
+
}
|
|
120
|
+
let chartDiv = document.createElement("div");
|
|
121
|
+
let chart = new ApexCharts(chartDiv, {
|
|
122
|
+
series: [{
|
|
123
|
+
name: 'Frequency',
|
|
124
|
+
data: bins
|
|
125
|
+
}],
|
|
126
|
+
chart: {
|
|
127
|
+
id: 'realtime',
|
|
128
|
+
height: 200,
|
|
129
|
+
type: 'bar',
|
|
130
|
+
animations: {
|
|
131
|
+
enabled: false
|
|
132
|
+
},
|
|
133
|
+
toolbar: {
|
|
134
|
+
show: false
|
|
135
|
+
},
|
|
136
|
+
zoom: {
|
|
137
|
+
enabled: false
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
dataLabels: {
|
|
141
|
+
enabled: false
|
|
142
|
+
},
|
|
143
|
+
title: {
|
|
144
|
+
text: 'Training Loss Spread',
|
|
145
|
+
align: 'left'
|
|
146
|
+
},
|
|
147
|
+
markers: {
|
|
148
|
+
size: 0
|
|
149
|
+
},
|
|
150
|
+
xaxis: {
|
|
151
|
+
type: 'number',
|
|
152
|
+
categories: titles,
|
|
153
|
+
},
|
|
154
|
+
yaxis: {
|
|
155
|
+
min: 0
|
|
156
|
+
},
|
|
157
|
+
legend: {
|
|
158
|
+
show: false
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
setTimeout(function() {
|
|
162
|
+
chart.render();
|
|
163
|
+
}, 10)
|
|
164
|
+
|
|
165
|
+
return html`${chartDiv}`
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
public render(): TemplateResult {
|
|
169
|
+
if (this.model == null)
|
|
170
|
+
return html`<p>${msg("Loading model...")}</p>`
|
|
171
|
+
|
|
172
|
+
return html`${until(this.getDiagram(), html`<p>${msg("Calculating Loss Distribution...")}</p>`)}`
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { msg } from "@lit/localize";
|
|
2
|
+
import SlButton from "@shoelace-style/shoelace/dist/components/button/button.component.js";
|
|
3
|
+
import SlOption from "@shoelace-style/shoelace/dist/components/option/option.component.js";
|
|
4
|
+
import SlSelect from "@shoelace-style/shoelace/dist/components/select/select.component.js";
|
|
5
|
+
import "@shoelace-style/shoelace/dist/themes/light.css";
|
|
6
|
+
import { LitElementWw, OptionDeclaration } from "@webwriter/lit";
|
|
7
|
+
import { css, html, TemplateResult } from "lit";
|
|
8
|
+
import { property } from "lit/decorators.js";
|
|
9
|
+
|
|
10
|
+
export class AiWidgetsReferenceSelect extends LitElementWw {
|
|
11
|
+
static scopedElements = {
|
|
12
|
+
"sl-select": SlSelect,
|
|
13
|
+
"sl-option": SlOption,
|
|
14
|
+
"sl-button": SlButton
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static styles = css`
|
|
18
|
+
:host {
|
|
19
|
+
display:block;
|
|
20
|
+
}
|
|
21
|
+
`
|
|
22
|
+
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
let that = this;
|
|
26
|
+
setInterval(function () {
|
|
27
|
+
that.requestUpdate();
|
|
28
|
+
}, 1000);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public options: Record<string, OptionDeclaration> = {}
|
|
32
|
+
|
|
33
|
+
@property({ type: String, attribute: true })
|
|
34
|
+
accessor elemId: string;
|
|
35
|
+
|
|
36
|
+
@property({ type: String, attribute: true })
|
|
37
|
+
accessor elementType: string;
|
|
38
|
+
|
|
39
|
+
@property({ type: String, attribute: true })
|
|
40
|
+
accessor typeName: string;
|
|
41
|
+
|
|
42
|
+
@property({ type: String }) ownerId;
|
|
43
|
+
|
|
44
|
+
private lastRef:HTMLElement;
|
|
45
|
+
|
|
46
|
+
firstUpdated() {
|
|
47
|
+
if (this.elemId == "" || this.elemId == null) {
|
|
48
|
+
let testSibblingForElementType = document.getElementById(this.ownerId);
|
|
49
|
+
console.log(testSibblingForElementType, this.elementType);
|
|
50
|
+
while (testSibblingForElementType != null && testSibblingForElementType.tagName.toLowerCase() != this.elementType) {
|
|
51
|
+
testSibblingForElementType = testSibblingForElementType.previousElementSibling as HTMLElement;
|
|
52
|
+
console.log(testSibblingForElementType);
|
|
53
|
+
}
|
|
54
|
+
this.elemId = testSibblingForElementType.id;
|
|
55
|
+
}
|
|
56
|
+
this.dispatchEvent(new CustomEvent('refchange', {
|
|
57
|
+
detail: {
|
|
58
|
+
id: this.elemId
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public render(): TemplateResult {
|
|
64
|
+
let that = this;
|
|
65
|
+
let elements = document.querySelectorAll(this.elementType)
|
|
66
|
+
let options = [];
|
|
67
|
+
let index = 1;
|
|
68
|
+
elements.forEach(function (elem: LitElementWw) {
|
|
69
|
+
let option = document.createElement("sl-option")
|
|
70
|
+
option.innerText = that.typeName + " " + index;
|
|
71
|
+
option.value = elem.id;
|
|
72
|
+
options.push(option)
|
|
73
|
+
index++;
|
|
74
|
+
})
|
|
75
|
+
function changeElem(e: Event) {
|
|
76
|
+
this.elemId = (e.target as SlSelect).value as string;
|
|
77
|
+
highlight();
|
|
78
|
+
this.dispatchEvent(new CustomEvent('refchange', {
|
|
79
|
+
detail: {
|
|
80
|
+
id: that.elemId,
|
|
81
|
+
lastRef: this.lastRef
|
|
82
|
+
}
|
|
83
|
+
}));
|
|
84
|
+
this.lastRef = this.getRefElement();
|
|
85
|
+
}
|
|
86
|
+
function highlight() {
|
|
87
|
+
if (that.elemId == "")
|
|
88
|
+
return;
|
|
89
|
+
let elem = that.getRefElement();
|
|
90
|
+
elem.style.boxShadow = "0px 0px 5px 5px orange";
|
|
91
|
+
setTimeout(function () {
|
|
92
|
+
elem.style.boxShadow = "";
|
|
93
|
+
}, 1000);
|
|
94
|
+
}
|
|
95
|
+
return html`<sl-select id="elemselect" value=${this.elemId} placeholder=${msg("Select Source Element")} @sl-focus=${highlight} @sl-change=${changeElem}>
|
|
96
|
+
${options}
|
|
97
|
+
</sl-select>
|
|
98
|
+
<sl-button @click=${highlight} id="btn">${msg("Show selection")}</sl-button>
|
|
99
|
+
`
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public getRefElement() {
|
|
103
|
+
return document.querySelector("#" + this.elemId) as HTMLElement
|
|
104
|
+
}
|
|
105
|
+
}
|