icekun commited on
Commit
88636d2
·
verified ·
1 Parent(s): 3810429

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +23 -7
index.html CHANGED
@@ -338,17 +338,17 @@
338
  </div>
339
  </div>
340
  </div>
341
-
342
  <script>
343
- // --- 変更部分: モデルリストに仕様(type)を明記して定義 ---
344
  const models = [
 
345
  { file: "tinymodelV3.onnx", type: "hsc" }, // 異常検知スコア (1出力)
346
  { file: "tinymodelV2.onnx", type: "softmax" } // 通常の分類 (2出力)
347
  ];
348
 
349
  let session = null;
350
  let isReady = false;
351
- let currentModelConfig = null; // 現在選択されているモデルの設定を保持
352
 
353
  const modelSelect = document.getElementById('modelSelect');
354
  const fileInput = document.getElementById('fileInput');
@@ -360,13 +360,13 @@
360
  const resultOutput = document.getElementById('resultOutput');
361
 
362
  function initSelect() {
 
363
  models.forEach((m, index) => {
364
  const opt = document.createElement('option');
365
- opt.value = index; // インデックスをvalueに設定
366
  opt.textContent = m.file;
367
  modelSelect.appendChild(opt);
368
  });
369
- // 選択時に該当するオブジェクトを渡す
370
  modelSelect.addEventListener('change', (e) => loadModel(models[e.target.value]));
371
  }
372
 
@@ -447,7 +447,7 @@
447
  const output = results[session.outputNames[0]].data;
448
  let probNeed, probTrash;
449
 
450
- // --- 事前定義されたモデルの仕様(type)に基づいて計算を分岐 ---
451
  if (currentModelConfig.type === "hsc") {
452
  const trashScore = output[0];
453
  probTrash = trashScore * 100;
@@ -458,9 +458,25 @@
458
  const sum = exp0 + exp1;
459
  probNeed = (exp0 / sum) * 100;
460
  probTrash = (exp1 / sum) * 100;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
461
  }
462
 
463
- // UI Render
464
  emptyOutput.style.display = 'none';
465
  resultOutput.style.display = 'flex';
466
  const topClass = probNeed >= probTrash ? "need" : "trash";
 
338
  </div>
339
  </div>
340
  </div>
 
341
  <script>
342
+ // モデル定義(新モデル tinymodelV9s.onnx を追加)
343
  const models = [
344
+ { file: "tinymodelV9s.onnx", type: "auto" }, // 自動判定
345
  { file: "tinymodelV3.onnx", type: "hsc" }, // 異常検知スコア (1出力)
346
  { file: "tinymodelV2.onnx", type: "softmax" } // 通常の分類 (2出力)
347
  ];
348
 
349
  let session = null;
350
  let isReady = false;
351
+ let currentModelConfig = null;
352
 
353
  const modelSelect = document.getElementById('modelSelect');
354
  const fileInput = document.getElementById('fileInput');
 
360
  const resultOutput = document.getElementById('resultOutput');
361
 
362
  function initSelect() {
363
+ modelSelect.innerHTML = '';
364
  models.forEach((m, index) => {
365
  const opt = document.createElement('option');
366
+ opt.value = index;
367
  opt.textContent = m.file;
368
  modelSelect.appendChild(opt);
369
  });
 
370
  modelSelect.addEventListener('change', (e) => loadModel(models[e.target.value]));
371
  }
372
 
 
447
  const output = results[session.outputNames[0]].data;
448
  let probNeed, probTrash;
449
 
450
+ // モデル仕様に応じた確率計算の分岐
451
  if (currentModelConfig.type === "hsc") {
452
  const trashScore = output[0];
453
  probTrash = trashScore * 100;
 
458
  const sum = exp0 + exp1;
459
  probNeed = (exp0 / sum) * 100;
460
  probTrash = (exp1 / sum) * 100;
461
+ } else {
462
+ // 自動判定 (出力数に応じて判定)
463
+ if (output.length === 1) {
464
+ let score = output[0];
465
+ if (score < 0 || score > 1) { // ロジットの場合は Sigmoid 変換
466
+ score = 1 / (1 + Math.exp(-score));
467
+ }
468
+ probTrash = score * 100;
469
+ probNeed = (1.0 - score) * 100;
470
+ } else {
471
+ const exp0 = Math.exp(output[0]);
472
+ const exp1 = Math.exp(output[1]);
473
+ const sum = exp0 + exp1;
474
+ probNeed = (exp0 / sum) * 100;
475
+ probTrash = (exp1 / sum) * 100;
476
+ }
477
  }
478
 
479
+ // UI描画
480
  emptyOutput.style.display = 'none';
481
  resultOutput.style.display = 'flex';
482
  const topClass = probNeed >= probTrash ? "need" : "trash";