-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexplore.html
More file actions
728 lines (643 loc) · 30.8 KB
/
explore.html
File metadata and controls
728 lines (643 loc) · 30.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<!--
CODEPROJECT.AI SERVER MODULE EXPLORER
This page provides the means to test this module using the same infrastructure as
the CodeProject.AI Server explorer. This page also provides the UI elements that
the explorer will parse and use to build up the UI of the main explorer itself.
RULES AND CONVENTIONS
1. This page should provide sufficient functionality to test and explore this
module.
2. This page should use the functionality in the explorer.js file so that when
the elements of this page are inserted into the main explorer, it all works
seamlessly. Specifically, you will probably use
- clearImagePreview: Clears the image preview area.
- previewImage: Displays an image in the shared image preview area and takes a
input[type=file] as parameter.
- submitRequest: Sends a request to the AI server.
- setResultsHtml: Sets the HTML in the shared 'results' element. Parameter is the HTML
to display.
- getProcessingMetadataHtml: Gets HTML representing the common data returned from a call to a
module.
- displayBaseResults: Displays the common data returned from a call to a module.
- showPredictionSummary: Displays in the shared HTML results pane the list of predictions
returned from an inference operation.
- clearImageResult: Clears the image result area
- showResultsImageData: Displays an image in the shared image results area using the data
returned from a call to a module, and overlays bounding boxes if
present in the data
- showResultsBoundingBoxes: Displays bounding boxes on the shared image results area based on
the boxes returned in the predictions parameter. The first param is
an array of predictions returned from a computer vision operation.
3. There are 3 parts of this page that will be pulled into the main explorer
during runtime: The HTML, the script, and the CSS. These sections are bounded by
- HTML: START EXPLORER MARKUP / END EXPLORER MARKUP pair, each within HTML comment brackets
- Script: START EXPLORER SCRIPT / END EXPLORER SCRIPT pair, each as a // comment on its own line
- CSS: START EXPLORER STYLE / END EXPLORER STYLE pair, each inside /* ... */ comments
These delimiters should be on a line by themselves
4. **Please provide output elements to display the results of operations** if
you wish to use the standard HTML / Image results elements in the main explorer
- For HTML output, include a DIV with id 'results'
- For Image preview/output, include an IMG element with id img and a DIV with
id 'imageMask'
- For Sound preview, include an AUDIO element with id 'snd' that contains a
SOURCE tag
5. When this file is parsed and injected into the larger explorer, the HTML is
injected first, then the script, then the CSS.
6. **To ensure uniqueness of elements** you can include the _MID_ macro in any
name. This will be expanded to be [ModuleId]_ where [ModuleId] is the literal
ID of this module. For instance <div id="_MID_TextBox"> becomes <div id="MyModuleId_TextBox">
-->
<head>
<meta charset="utf-8" />
<title>YOLOv5 Training Module Test</title>
<link id="bootstrapCss" rel="stylesheet" type="text/css" href="http://localhost:32168/assets/bootstrap-dark.min.css">
<link rel="stylesheet" type="text/css" href="http://localhost:32168/assets/server.css?v=2.5.0.0">
<script type="text/javascript" src="http://localhost:32168/assets/server.js"></script>
<script type="text/javascript" src="http://localhost:32168/assets/explorer.js"></script>
<style>
/* START EXPLORER STYLE */
/* END EXPLORER STYLE */
</style>
</head>
<body class="dark-mode">
<div class="mx-auto" style="max-width: 800px;">
<h2 class="mb-3">YoloV5 6.2 Model Training Module Test</h2>
<form method="post" action="" enctype="multipart/form-data" id="myform">
<!-- START EXPLORER MARKUP -->
<div class="row g-3">
<div class="col-2">
<h6 class="card-title fw-bold">Dataset</h6>
</div>
<div class="col-10">
<div class="progress mt-0 bg-transparent" style="height: 20px;">
<div id="_MID_datasetProgress" class="progress-bar bg-success" role="progressbar"
aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"></div>
</div>
</div>
</div>
<div class="row g-3">
<div class="col-2">
<label class="col-form-label">Name</label>
</div>
<div class="col-4">
<input class="form-control" id="_MID_trainingInputDatasetName"
data-bs-toggle="tooltip" type="text"
title="Name of Dataset to create." onchange="_MID_onDatasetNameChange()" />
</div>
<div class="col-2">
<label class="col-form-label">#Images</label>
</div>
<div class="col-4">
<input class="form-control" id="_MID_trainingNumImages" type="number"
data-bs-toggle="tooltip" title="Number of images to use for training (10 - 10,000)"
value="100" />
</div>
</div>
<div class="row g-3">
<div class="col-2">
<label class="col-form-label text-nowrap">
Classes
<div class='dropdown text-wrap d-inline-block'>
<button class='btn btn-sm dropdown d-inline border-none mb-1' type='button'
id='open-images-classes-label' data-bs-toggle='dropdown'>
<svg fill="#aaaaaa" height="16px" width="16px" version="1.1" xml:space="preserve"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 330 330">
<g>
<path d="M165,0C74.019,0,0,74.02,0,165.001C0,255.982,74.019,330,165,330s165-74.018,165-164.999C330,74.02,255.981,0,165,0z M165,300c-74.44,0-135-60.56-135-134.999C30,90.562,90.56,30,165,30s135,60.562,135,135.001C300,239.44,239.439,300,165,300z"/>
<path d="M164.998,70c-11.026,0-19.996,8.976-19.996,20.009c0,11.023,8.97,19.991,19.996,19.991 c11.026,0,19.996-8.968,19.996-19.991C184.994,78.976,176.024,70,164.998,70z"/>
<path d="M165,140c-8.284,0-15,6.716-15,15v90c0,8.284,6.716,15,15,15c8.284,0,15-6.716,15-15v-90C180,146.716,173.284,140,165,140z"/>
</g>
</svg>
</button>
<ul class='dropdown-menu' aria-labelledby="open-images-classes-label">
<li>
<!-- TODO: Pull this from the training module -->
<div id='_MID_openimageClasses' style="width:55rem">
Downloading ...
</div>
</li>
</ul>
</div>
</label>
</div>
<div class="col-10">
<input class="form-control" id="_MID_trainingDatasetClasses" type="text"
data-bs-toggle="tooltip" title="A comma separated list of classes. Click the info button for a list." />
</div>
</div>
<div class="row g-3">
<div class="col-2">
</div>
<div class="col-10 d-flex justify-content-around">
<div>
<input class="btn btn-success" type="button" value="Create Dataset"
onclick="_MID_onDatasetCreate(
_MID_trainingInputDatasetName.value,
_MID_trainingDatasetClasses.value,
_MID_trainingNumImages.value)">
</div>
<div>
<input class="btn btn-info" type="button" value="Dataset Info"
onclick="_MID_onDatasetInfo(_MID_trainingInputDatasetName.value)">
</div>
</div>
</div>
<div class="row g-3 mt-3">
<div class="col-2">
<h6 class="card-title fw-bold">Model</h6>
</div>
<div class="col-10">
<div class="progress mt-0 bg-transparent" style="height: 20px;">
<div id="_MID_trainingProgress" class="progress-bar bg-success" role="progressbar"
aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"></div>
</div>
</div>
</div>
<div class="row g-3">
<div class="col-2">
<label class="col-form-label">Name</label>
</div>
<div class="col-4">
<input class="form-control" id="_MID_trainingInputModelName" type="text"
data-bs-toggle="tooltip" title="Name of YoloV5 Model to train." />
</div>
<div class="col-2">
<label class="col-form-label">Dataset</label>
</div>
<div class="col-4">
<input class="form-control" id="_MID_trainingInputModelDatasetName" type="text"
data-bs-toggle="tooltip"
title="Name of Dataset used to train the Model. Enter the name of the dataset you created above or the full path of a dataset you have created by other means." />
</div>
</div>
<div class="row g-3">
<div class="col-2">
<label class="col-form-label">Model size</label>
</div>
<div class="col-4">
<select class="form-select" id="_MID_trainingModelSize"
data-bs-toggle="tooltip" title="The size of the YoloV5 Model to create.">
<option value="tiny">Tiny</option>
<option value="small" selected>Small</option>
<option value="medium">Medium</option>
<option value="large">Large</option>
</select>
</div>
<div class="col-2">
<label class="col-form-label">Tuning</label>
</div>
<div class="col-4">
<select class="form-select" id="_MID_trainingModelHyp" data-bs-toggle="tooltip"
title="Select which Hyper Parameters file to use when training.">
<option value="fine" selected>Fine</option>
<option value="low">Low</option>
<option value="medium">Medium</option>
<option value="high">High</option>
</select>
</div>
</div>
<div class="row g-3">
<div class="col-2">
<label class="col-form-label">Batch</label>
</div>
<div class="col-4">
<input class="form-control" id="_MID_trainingBatchSize" type="number"
value="4" min="-1" max="256"
data-bs-toggle="tooltip" title="Number of images in each training batch. Higher = more memory use but better performance. Use -1 to auto select (experimental)." />
</div>
<div class="col-2">
<label class="col-form-label">Epochs</label>
</div>
<div class="col-4">
<input class="form-control" id="_MID_trainingNumEpochs" type="number" value="100"
data-bs-toggle="tooltip"
title="Number of Epochs to train. Higher = better, but can lead to overtraining. (10 - 1,000)" />
</div>
</div>
<div class="row g-3">
<div class="col-2">
<label class="col-form-label">Patience</label>
</div>
<div class="col-4">
<input class="form-control" id="_MID_trainingPatience" type="number" value="100"
data-bs-toggle="tooltip" title="Number of epochs to wait for no observable improvement for early stopping of training." />
</div>
<div class="col-2">
<label class="col-form-label">Workers</label>
</div>
<div class="col-4">
<input class="form-control" id="_MID_trainingWorkers" type="number" value="8"
data-bs-toggle="tooltip"
title="Number of number of worker threads. 8=default, range (1 - 128)."/>
</div>
</div>
<div class="row g-3">
<div class="col-2">
<label class="col-form-label">Freeze</label>
</div>
<div class="col-4">
<select class="form-select" id="_MID_trainingFreeze" data-bs-toggle="tooltip"
title="Which layers of the model weights to exclude from training. The more excluded, the faster the training, at the cost of accuracy">
<option value="0">None</option>
<option value="10" selected>Backbone</option>
<option value="24">All</option>
</select>
</div>
<div class="col-2">
<label class="col-form-label">Device</label>
</div>
<div class="col-4">
<input class="form-control" id="_MID_trainingDevice" data-bs-toggle="tooltip"
type="text" value="0"
title="'', 'cpu', '0' or '0,1,2,3' for multiple GPUs." />
</div>
</div>
<div class="row g-3 pt-2">
<div class="col-2">
</div>
<div class="col-10 d-flex justify-content-around">
<div>
<input class="btn btn-success" type="button" value="Train Model"
onclick="_MID_onTrainingStart(
_MID_trainingInputModelName.value,
_MID_trainingInputModelDatasetName.value,
_MID_trainingModelSize.value,
_MID_trainingNumEpochs.value,
_MID_trainingBatchSize.value,
_MID_trainingDevice.value,
_MID_trainingFreeze.value,
_MID_trainingModelHyp.value,
_MID_trainingPatience.value,
_MID_trainingWorkers.value
)">
</div>
<div>
<input class="btn btn-success" type="button" value="Resume Training"
data-bs-toggle="tooltip"
title="Resume training the YoloV5 Model from the last successful epoch with the parameters specified when it was started."
onclick="_MID_onTrainingResumeTraining(_MID_trainingInputModelName.value)">
</div>
<div>
<input class="btn btn-info" type="button" value="Model Info"
onclick="_MID_onTrainingModelInfo(_MID_trainingInputModelName.value)">
</div>
</div>
</div>
<div class="row g-3 mt-4">
<div class="col-2">
<label class="col-form-label">Status</label>
</div>
<div class="col-10">
<input class="form-control" id="_MID_statusMessage" type="text" readonly
title="The status of the last started long running action."/>
</div>
</div>
<div class="row g-3">
<div class="col-2">
<label class="col-form-label">Action</label>
</div>
<div class="col-4">
<input class="form-control" id="_MID_trainingAction"
type="text" readonly />
</div>
<div class="col-2">
<label class="col-form-label">State</label>
</div>
<div class="col-4">
<input class="form-control" id="_MID_trainingState"
type="text" readonly />
</div>
</div>
<div class="row g-3">
<div class="col-2">
<label class="col-form-label">Model</label>
</div>
<div class="col-4">
<input class="form-control" id="_MID_trainingModelName"
type="text" readonly />
</div>
<div class="col-2">
<label class="col-form-label">Dataset</label>
</div>
<div class="col-4">
<input class="form-control" id="_MID_trainingDatasetName"
type="text" readonly />
</div>
</div>
<div class="row g-3 pt-2">
<div class="col-12 text-center">
<input class="btn btn-danger" type="button" value="Cancel"
id="_MID_CancelBtn"
disabled hidden
onclick="_MID_onCancel()">
</div>
</div>
<div class="w-100 position-relative bg-light mt-4">
<img src="" id="_MID_imgTrainingResult" class="w-100" style="height:auto;visibility:hidden">
</div>
<!-- END EXPLORER MARKUP -->
<div class="w-100 position-relative form-control my-4 p-0">
<div id="imgMask" class="position-absolute"
style="left:0;top:0;pointer-events:none;z-index:10"></div>
<img src="" id="imgPreview" class="w-100" style="height:250px;visibility:hidden">
</div>
<div>
<h2>Results</h2>
<div id="results" name="results" class="bg-light p-3" style="min-height: 100px;"></div>
</div>
</form>
<script type="text/javascript">
// START EXPLORER SCRIPT
// Have final training or dataset creation results been displayed? Initialize to true or
// onTrainingModelInfo will be called on the first onTrainingStatus call.
let _MID_trainingResultsShown = true;
let _MID_datasetCreationResultsShown = true;
let _MID_CommandId = '';
let _MID_ModuleId = 'TrainingObjectDetectionYOLOv5';
function _MID_UpdateUI(data) {
_MID_trainingModelName.value = data.model_name ?? "";
_MID_trainingDatasetName.value = data.dataset_name ?? "";
_MID_trainingAction.value = data.action ?? "";
_MID_trainingState.value = data.state ?? "";
_MID_statusMessage.value = data.message ?? "";
}
function _MID_ShowCancelBtn(show) {
if (show) {
_MID_CancelBtn.removeAttribute('disabled');
_MID_CancelBtn.removeAttribute('hidden');
}
else {
_MID_CancelBtn.setAttribute('disabled', true);
_MID_CancelBtn.setAttribute('hidden', true);
}
}
function _MID_UpdateDatasetProgress(data) {
_MID_UpdateProgressBar(data, _MID_datasetProgress);
}
function _MID_UpdateTrainingProgress(data) {
_MID_UpdateProgressBar(data, _MID_trainingProgress);
}
function _MID_UpdateProgressBar(data, progressBar) {
if (data) {
let progressStr = (data.progress ?? 0).toFixed(0);
progressBar.innerHTML = progressStr + "%";
progressBar.parentElement.classList.remove("bg-transparent");
if (data.progress < 1)
progressBar.classList.add("progress-bar-striped", "progress-bar-animated");
else
progressBar.classList.remove("progress-bar-striped", "progress-bar-animated");
progressBar.ariaValueNow = progressStr;
}
else {
progressBar.classList.remove("progress-bar-striped", "progress-bar-animated");
// Previously we wanted the dataset creation progress bar to sit at 100%
// while the training (that presumably used the created dataset) continued.
// This isn't actually realistic :(
// datasetProgress.ariaValueNow = data.dataset_created ? "100" : "0";
progressBar.ariaValueNow = "0";
}
progressBar.style.width = progressBar.ariaValueNow + "%";
}
// ---------------------- Dataset Creation ----------------------
async function _MID_onDatasetCreate(dataset_name, classes, num_images) {
_MID_hideModelGraphs()
let params = [
["dataset_name", dataset_name],
["classes", classes],
["num_images", num_images],
];
setResultsHtml("Starting dataset creation");
_MID_UpdateUI({});
let data = await submitRequest('train', 'create_dataset', null, params);
_MID_UpdateUI(data);
if (data) {
if (data.success) {
_MID_ShowCancelBtn(true);
setResultsHtml(`Creating the Dataset '${dataset_name}'`);
// get the commandId to so we can poll for the results
_MID_CommandId = data.commandId;
_MID_ModuleId = data.moduleId;
params = [['commandId', _MID_CommandId], ['moduleId', _MID_ModuleId]];
let done = false;
while (!done) {
await delay(2000);
let results = await submitRequest(_MID_ModuleId, 'get_command_status', null, params);
if (results) {
if (results.success) {
done = results.commandStatus == "completed";
_MID_showDatasetInfo(results);
_MID_UpdateUI(results);
_MID_UpdateDatasetProgress(results)
if (done) {
_MID_ShowCancelBtn(false);
}
}
else {
setResultsHtml(results?.error ?? "No response from server");
done = true;
}
}
}
}
else
setResultsHtml("Create Dataset failed to start: " + data.error);
}
else {
setResultsHtml("Create Dataset failed to start");
}
}
async function _MID_onDatasetInfo(dataset_name) {
_MID_hideModelGraphs()
if (!dataset_name) {
setResultsHtml("Get Dataset Info Failed: Dataset name is required.")
return
}
let params = [["dataset_name", dataset_name]]
let data = await submitRequest('train', 'dataset_info', null, params);
_MID_showDatasetInfo(data);
}
function _MID_showDatasetInfo(data) {
_MID_hideModelGraphs();
if (data) {
if (data.success) {
let resultHtml = "Dataset Info:"
+ "<br/><b>Dataset Name:</b> " + data.dataset_name + " (" + (data.dataset_size_mb ?? 0) + "Mb)"
+ "<br/><b>Creation State:</b> " + (data.dataset_created ? "Complete" : "Not Complete") // Need to detect "failed"
+ "<br/><br/><b>Dataset Path:</b><br/> " + (data.display_dataset_path ?? "Not yet available")
+ getProcessingMetadataHtml(data);
setResultsHtml(resultHtml);
}
else
setResultsHtml("Training: Unable to get dataset info: " + data.error);
}
else {
setResultsHtml("Training: Unable to get dataset info");
};
}
// Auto-populate the dataset name if nothing there
function _MID_onDatasetNameChange() {
if (!_MID_trainingInputModelDatasetName.value && _MID_trainingInputDatasetName.value)
_MID_trainingInputModelDatasetName.value = _MID_trainingInputDatasetName.value;
}
// ---------------------- Model Training ----------------------
async function _MID_onTrainingStart(model_name, dataset_name, model_size, num_epochs, batch,
device, freeze, hyp, patience, workers) {
_MID_hideModelGraphs()
let params = [
[ "model_name", model_name ],
[ "dataset_name", dataset_name ],
[ "model_size", model_size ],
[ "num_epochs", num_epochs ],
[ "device", device ],
[ "batch", batch ],
[ "freeze", freeze ],
[ "hyp" , hyp ],
[ "patience", patience ],
[ "workers", workers ]
];
_MID_UpdateUI({});
setResultsHtml("Starting model training");
let data = await submitRequest('train', 'train_model', null, params);
_MID_UpdateUI(data);
if (data) {
if (data.success) {
_MID_ShowCancelBtn(true);
_MID_CommandId = data.commandId;
_MID_ModuleId = data.moduleId;
setResultsHtml(`Training model '${model_name}'`);
await _MID_getTrainingCommandStatus(data);
_MID_ShowCancelBtn(false);
}
else
setResultsHtml("Train Model failed to start: " + data.error);
}
else {
setResultsHtml("Train Model failed to start");
}
}
async function _MID_onTrainingResumeTraining(model_name) {
_MID_hideModelGraphs()
let params = [
["model_name", model_name]
];
setResultsHtml("Resume Training model {model_name}");
let data = await submitRequest('train', 'resume_training', null, params);
if (data) {
if (data.success) {
_MID_ShowCancelBtn(true);
// NOTE: if TrainingYOLO has train_in_separate_task = False then the data
// object will contain all the info of the newly created model
_MID_CommandId = data.commandId;
_MID_ModuleId = data.moduleId;
setResultsHtml("Resuming training for model " + model_name);
await _MID_getTrainingCommandStatus(data);
_MID_ShowCancelBtn(false);
}
else
setResultsHtml("Resume Training failed to start: " + data.error);
}
else {
setResultsHtml("Resume Training failed to start");
}
}
async function _MID_getTrainingCommandStatus(data) {
// get the commandId to so we can poll for the results
_MID_ModuleId = data.moduleId;
let params = [['commandId', _MID_CommandId], ['moduleId', _MID_ModuleId]];
let done = false;
while (!done) {
await delay(2000);
let results = await submitRequest(_MID_ModuleId, 'get_command_status', null, params);
if (results) {
if (results.success) {
done = results.commandStatus == "completed";
_MID_showModelInfo(results);
_MID_UpdateUI(results);
_MID_UpdateTrainingProgress(results)
}
else {
// TODO: check for timeouts and other network errors.
done = true;
setResultsHtml(results?.error ?? "No response from server");
}
}
}
}
async function _MID_onCancel() {
clearImagePreview();
let params = [['commandId', _MID_CommandId], ['moduleId', _MID_ModuleId]];
let result = await submitRequest(_MID_ModuleId, 'cancel_command', null, params);
setResultsHtml("Command stop requested");
}
async function _MID_onTrainingModelInfo(model_name) {
_MID_hideModelGraphs()
if (!model_name) {
setResultsHtml("Get Model Info Failed: Model Name is required.")
return
}
let params = [["model_name", model_name]]
let data = await submitRequest('train', 'model_info', null, params);
_MID_showModelInfo(data);
}
function _MID_showModelInfo(data) {
if (data) {
if (data.success) {
let model_created = data.model_created
let resultHtml = "Model Info:"
+ "<br/><b>Model Name:</b> " + (data.model_name ?? "") + " (" + (data.model_size_mb ?? 0)+ "Mb)"
+ "<br/><b>Training State:</b> " + (model_created ? "Complete" : "Not Complete") // Need to detect "failed"
+ "<br/><br/><b>Model Path:</b><br/> " + (data.model_path ?? "Not yet available")
+ "<br/><br/><b>Results Graph Path:</b><br/> " + (data.results_graph_path ?? "Not yet available")
+ "<br/><br/><b>Results CSV:</b><br/> " + (data.results_csv_path ?? "Not yet available")
+ "<br/><br/><b>PR Curve Graph Path:</b><br/> " + (data.pr_curve_path ?? "Not yet available")
+ getProcessingMetadataHtml(data);
setResultsHtml(resultHtml);
if (data.results_graph_image) {
data["imageBase64"] = data.results_graph_image;
showResultsImageData(data);
}
else {
clearImageResult(); }
if (data.pr_curve_image) {
_MID_imgTrainingResult.src = "data:image/png;base64," + data.pr_curve_image;
// results_img.src = "file://" + data.pr_curve_path;
_MID_imgTrainingResult.style.visibility = "visible";
}
else {
_MID_imgTrainingResult.src = "";
_MID_imgTrainingResult.style.visibility = "hidden";
}
}
else
setResultsHtml("Training: Unable to get Model info: " + data.error ?? "no error info");
}
else {
setResultsHtml("Training: Unable to get Model info");
};
}
function _MID_hideModelGraphs() {
clearImageResult();
_MID_imgTrainingResult.src = "";
_MID_imgTrainingResult.style.visibility = "hidden";
_MID_imgTrainingResult.src = "";
_MID_imgTrainingResult.style.visibility = "hidden";
}
async function _MID_getClasses() {
let result = await submitRequest('train', 'list_classes', null, null);
if (result?.success ?? false) {
let classesStr = result.classes.join(", ");
_MID_openimageClasses.innerHTML = classesStr;
}
}
// =====================================================================
// Startup
(async () => {
await _MID_getClasses();
})();
// END EXPLORER SCRIPT
</script>
</div>
</body>
</html>