Update index.html
Browse files- index.html +18 -18
index.html
CHANGED
|
@@ -338,13 +338,12 @@
|
|
| 338 |
</div>
|
| 339 |
</div>
|
| 340 |
</div>
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
// モデル定義(各モデルの入力サイズを設定)
|
| 344 |
const models = [
|
| 345 |
-
{ file: "tinymodelV9s.onnx", type: "hsc", size: 256 },
|
| 346 |
-
{ file: "tinymodelV3.onnx", type: "hsc", size: 224
|
| 347 |
-
{ file: "tinymodelV2.onnx", type: "softmax", size: 224
|
| 348 |
];
|
| 349 |
|
| 350 |
let session = null;
|
|
@@ -384,7 +383,7 @@
|
|
| 384 |
}
|
| 385 |
session = await ort.InferenceSession.create('./' + modelConfig.file);
|
| 386 |
isReady = true;
|
| 387 |
-
statusText.innerText = "✅ " + modelConfig.file + " の準備完了";
|
| 388 |
|
| 389 |
if (previewImg.src && previewImg.style.display !== 'none') {
|
| 390 |
submitBtn.disabled = false;
|
|
@@ -410,7 +409,6 @@
|
|
| 410 |
|
| 411 |
fileInput.addEventListener('change', (e) => handleFile(e.target.files[0]));
|
| 412 |
|
| 413 |
-
// モデルごとの targetSize に合わせてリサイズと標準化処理を行う
|
| 414 |
async function preprocess(imgElement, targetSize) {
|
| 415 |
const canvas = document.createElement('canvas');
|
| 416 |
canvas.width = targetSize;
|
|
@@ -419,7 +417,6 @@
|
|
| 419 |
ctx.drawImage(imgElement, 0, 0, targetSize, targetSize);
|
| 420 |
const data = ctx.getImageData(0, 0, targetSize, targetSize).data;
|
| 421 |
|
| 422 |
-
// inf.py と同じ mean / std
|
| 423 |
const mean = [0.485, 0.456, 0.406];
|
| 424 |
const std = [0.229, 0.224, 0.225];
|
| 425 |
|
|
@@ -445,10 +442,11 @@
|
|
| 445 |
const origW = previewImg.naturalWidth;
|
| 446 |
const origH = previewImg.naturalHeight;
|
| 447 |
|
| 448 |
-
let probNeed, probTrash;
|
| 449 |
|
| 450 |
-
//
|
| 451 |
if (currentModelConfig.file === "tinymodelV9s.onnx" && (origW <= 256 || origH <= 256)) {
|
|
|
|
| 452 |
probTrash = 100.0;
|
| 453 |
probNeed = 0.0;
|
| 454 |
statusText.innerText = "⚠️ 低解像度のため判定をスキップ (Trash)";
|
|
@@ -464,26 +462,28 @@
|
|
| 464 |
const output = results[session.outputNames[0]].data;
|
| 465 |
|
| 466 |
if (currentModelConfig.type === "hsc") {
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
probNeed = (1.0 - trashScore) * 100;
|
| 471 |
} else if (currentModelConfig.type === "softmax") {
|
| 472 |
-
// 2次元出力 Logits
|
| 473 |
const exp0 = Math.exp(output[0]);
|
| 474 |
const exp1 = Math.exp(output[1]);
|
| 475 |
const sum = exp0 + exp1;
|
| 476 |
probNeed = (exp0 / sum) * 100;
|
| 477 |
probTrash = (exp1 / sum) * 100;
|
|
|
|
| 478 |
}
|
| 479 |
statusText.innerText = "✅ 完了 (" + duration + "ms)";
|
| 480 |
}
|
| 481 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 482 |
// UI描画
|
| 483 |
emptyOutput.style.display = 'none';
|
| 484 |
resultOutput.style.display = 'flex';
|
| 485 |
-
const topClass = probNeed >= probTrash ? "need" : "trash";
|
| 486 |
-
const topConf = Math.max(probNeed, probTrash).toFixed(1);
|
| 487 |
|
| 488 |
document.getElementById('topClassName').innerText = topClass;
|
| 489 |
document.getElementById('topClassConf').innerText = "信頼度: " + topConf + "%";
|
|
|
|
| 338 |
</div>
|
| 339 |
</div>
|
| 340 |
</div>
|
| 341 |
+
<script>
|
| 342 |
+
// モデル定義(JSONの閾値 threshold: 0.19671 を追加)
|
|
|
|
| 343 |
const models = [
|
| 344 |
+
{ file: "tinymodelV9s.onnx", type: "hsc", size: 256, threshold: 0.3 }, // 最適化閾値を適用
|
| 345 |
+
{ file: "tinymodelV3.onnx", type: "hsc", size: 224, threshold: 0.5 },
|
| 346 |
+
{ file: "tinymodelV2.onnx", type: "softmax", size: 224, threshold: 0.5 }
|
| 347 |
];
|
| 348 |
|
| 349 |
let session = null;
|
|
|
|
| 383 |
}
|
| 384 |
session = await ort.InferenceSession.create('./' + modelConfig.file);
|
| 385 |
isReady = true;
|
| 386 |
+
statusText.innerText = "✅ " + modelConfig.file + " の準備完了 (閾値: " + (modelConfig.threshold * 100).toFixed(1) + "%)";
|
| 387 |
|
| 388 |
if (previewImg.src && previewImg.style.display !== 'none') {
|
| 389 |
submitBtn.disabled = false;
|
|
|
|
| 409 |
|
| 410 |
fileInput.addEventListener('change', (e) => handleFile(e.target.files[0]));
|
| 411 |
|
|
|
|
| 412 |
async function preprocess(imgElement, targetSize) {
|
| 413 |
const canvas = document.createElement('canvas');
|
| 414 |
canvas.width = targetSize;
|
|
|
|
| 417 |
ctx.drawImage(imgElement, 0, 0, targetSize, targetSize);
|
| 418 |
const data = ctx.getImageData(0, 0, targetSize, targetSize).data;
|
| 419 |
|
|
|
|
| 420 |
const mean = [0.485, 0.456, 0.406];
|
| 421 |
const std = [0.229, 0.224, 0.225];
|
| 422 |
|
|
|
|
| 442 |
const origW = previewImg.naturalWidth;
|
| 443 |
const origH = previewImg.naturalHeight;
|
| 444 |
|
| 445 |
+
let probNeed, probTrash, rawTrashScore;
|
| 446 |
|
| 447 |
+
// 256px 以下の低解像度画像の除外判定 (inf.py 仕様)
|
| 448 |
if (currentModelConfig.file === "tinymodelV9s.onnx" && (origW <= 256 || origH <= 256)) {
|
| 449 |
+
rawTrashScore = 1.0;
|
| 450 |
probTrash = 100.0;
|
| 451 |
probNeed = 0.0;
|
| 452 |
statusText.innerText = "⚠️ 低解像度のため判定をスキップ (Trash)";
|
|
|
|
| 462 |
const output = results[session.outputNames[0]].data;
|
| 463 |
|
| 464 |
if (currentModelConfig.type === "hsc") {
|
| 465 |
+
rawTrashScore = output[0];
|
| 466 |
+
probTrash = rawTrashScore * 100;
|
| 467 |
+
probNeed = (1.0 - rawTrashScore) * 100;
|
|
|
|
| 468 |
} else if (currentModelConfig.type === "softmax") {
|
|
|
|
| 469 |
const exp0 = Math.exp(output[0]);
|
| 470 |
const exp1 = Math.exp(output[1]);
|
| 471 |
const sum = exp0 + exp1;
|
| 472 |
probNeed = (exp0 / sum) * 100;
|
| 473 |
probTrash = (exp1 / sum) * 100;
|
| 474 |
+
rawTrashScore = probTrash / 100.0;
|
| 475 |
}
|
| 476 |
statusText.innerText = "✅ 完了 (" + duration + "ms)";
|
| 477 |
}
|
| 478 |
|
| 479 |
+
// 判定閾値 (threshold) を使用した判定ロジック
|
| 480 |
+
const threshold = currentModelConfig.threshold ?? 0.5;
|
| 481 |
+
const topClass = rawTrashScore > threshold ? "trash" : "need";
|
| 482 |
+
const topConf = (topClass === "trash" ? probTrash : probNeed).toFixed(1);
|
| 483 |
+
|
| 484 |
// UI描画
|
| 485 |
emptyOutput.style.display = 'none';
|
| 486 |
resultOutput.style.display = 'flex';
|
|
|
|
|
|
|
| 487 |
|
| 488 |
document.getElementById('topClassName').innerText = topClass;
|
| 489 |
document.getElementById('topClassConf').innerText = "信頼度: " + topConf + "%";
|