-
Notifications
You must be signed in to change notification settings - Fork 2
/
explore.html
217 lines (175 loc) · 9.24 KB
/
explore.html
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
<!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, include an IMG element with id imgPreview
- For image results, include an IMG with element imgPreview and a DIV with
id 'imageMask'.
- You can use a single image for both preview and results if you wish by only
including a imgPreview image. Make sure you have the imageMask DIV though.
- 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>Object Detection (YOLOv8) 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">Object Detection (YOLOv8) Module Test</h2>
<form method="post" action="" enctype="multipart/form-data" id="myform">
<!-- START EXPLORER MARKUP -->
<div class="form-group row">
<label class="col-form-label col-2">Image</label>
<input id="_MID_image" class="col form-control btn-light" type="file" style="width:17rem"
onchange="return previewImage(this)" />
<input id="_MID_things" class="form-control btn-success" type="button" value="Detect Objects"
style="width:11rem" onclick="_MID_onDetectThings(_MID_image, _MID_do_segmentation.checked)"/>
</div>
<div class="form-group d-flex justify-content-end mt-2">
<div>
<label for="_MID_do_segmentation" class="col-form-label">Perform segmentation</label>
<input id="_MID_do_segmentation" class="col-form-check-input ms-1" type="checkbox" />
</div>
</div>
<hr>
<div class="form-group row">
<label class="col-form-label col-2">Image</label>
<input id="_MID_customimage" class="col form-control btn-light" type="file"
style="width:17rem" onchange="return previewImage(this)" />
<input id="_MID_customthings" class="form-control btn-warning" type="button"
value="Custom Detect" style="width:11rem"
onclick="_MID_onCustomDetect(_MID_customModel.value, _MID_customimage)"/>
</div>
<div class="form-group d-flex justify-content-end mt-2">
<label class="col-form-label col-2">Model</label>
<select id="_MID_customModel" class="form-select" style="width:19rem">
</select>
<label style="width:11rem"></label>
</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
async function _MID_onDetectThings(fileChooser, do_segmentation) {
clearImagePreview();
if (fileChooser.files.length == 0) {
alert("No file was selected for vision detection");
return;
}
showPreviewImage(fileChooser.files[0]);
let images = [fileChooser.files[0]];
setResultsHtml("Detecting objects...");
const operation = do_segmentation ? "segmentation" : "detection";
let data = await submitRequest('vision', operation, images, null);
if (data) {
if (do_segmentation)
showResultsMasks(data.predictions);
else
showResultsBoundingBoxes(data.predictions);
showPredictionSummary(data)
};
}
async function _MID_onCustomDetect(model_name, fileChooser) {
clearImagePreview();
if (fileChooser.files.length == 0) {
alert("No file was selected for custom object detection");
return;
}
showPreviewImage(fileChooser.files[0]);
let images = [fileChooser.files[0]];
setResultsHtml(`Detecting objects using model ${model_name}...`);
let data = await submitRequest('vision', 'custom/' + model_name, images, null);
if (data) {
showResultsBoundingBoxes(data.predictions);
showPredictionSummary(data)
};
}
async function _MID_getCustomModelList() {
console.log("Getting custom list")
let data = await submitRequest('vision', 'custom/list', null, null);
if (data?.models?.length) {
// console.log(`Got ${data.models.length} models`);
let options = [];
for (let i = 0; i < data.models.length; i++)
options.push({ name: data.models[i], value: data.models[i]});
return options;
}
return null;
}
async function _MID_setCustomModelList() {
let customModelList = await _MID_getCustomModelList();
if (!customModelList) customModelList = [];
setModelList("_MID_customModel", customModelList);
}
// =====================================================================
// Startup
// Regularly update the custom list dropdown
_MID_setCustomModelList(); // Initial update
setTimeout(_MID_setCustomModelList, serverWarmupSec * 1000); // ...In case warm up time needed
setInterval(_MID_setCustomModelList, customModelUpdateFreqSec * 1000); // ...and now regular updates
// Use our custom model list method to populate the main explorer's benchmark custom list
GetBenchmarkCustomModelList = _MID_getCustomModelList;
// END EXPLORER SCRIPT
</script>
</div>
</body>
</html>