lgonda1998 commited on
Commit
c8b18eb
·
verified ·
1 Parent(s): f15e947

Remove incompatible detectors and stabilize RT-DETR

Browse files

Remove incompatible Faster R-CNN and YOLOv8n pipeline entries

Files changed (1) hide show
  1. classifier.js +10 -23
classifier.js CHANGED
@@ -6,7 +6,7 @@ export const MODEL_OPTIONS = [
6
  label: 'ResNet-18',
7
  modelId: 'Xenova/resnet-18',
8
  task: 'image-classification',
9
- note: 'Recommended classroom default: a compact CNN with 1,000 ImageNet labels.',
10
  dtype: 'q8',
11
  },
12
  {
@@ -22,33 +22,15 @@ export const MODEL_OPTIONS = [
22
  label: 'CLIP ViT-B/32',
23
  modelId: 'Xenova/clip-vit-base-patch32',
24
  task: 'zero-shot-image-classification',
25
- note: 'A vision-language model that ranks your own candidate descriptions.',
26
  dtype: 'q8',
27
  },
28
- {
29
- key: 'faster-rcnn',
30
- label: 'Faster R-CNN (R50-FPN)',
31
- modelId: 'onnxmodelzoo/FasterRCNN-10',
32
- task: 'object-detection',
33
- note: 'A two-stage detector that proposes regions, then classifies and refines each detected object.',
34
- dtype: 'fp32',
35
- experimental: true,
36
- },
37
- {
38
- key: 'yolov8n',
39
- label: 'YOLOv8n',
40
- modelId: 'webnn/yolov8n',
41
- task: 'object-detection',
42
- note: 'A compact one-stage detector designed for fast object detection.',
43
- dtype: 'fp32',
44
- experimental: true,
45
- },
46
  {
47
  key: 'rtdetr-r18',
48
  label: 'RT-DETR R18',
49
  modelId: 'onnx-community/rtdetr_r18vd',
50
  task: 'object-detection',
51
- note: 'A real-time Detection Transformer with a lightweight ResNet-18-style backbone.',
52
  dtype: 'q8',
53
  },
54
  ];
@@ -61,10 +43,14 @@ export function getModelOption(key) {
61
 
62
  export async function loadClassifier(modelKey, progressCallback) {
63
  const option = getModelOption(modelKey);
64
- if (classifierCache.has(option.key)) return classifierCache.get(option.key);
 
 
 
65
 
66
  const classifier = await pipeline(option.task, option.modelId, {
67
  dtype: option.dtype,
 
68
  progress_callback: progressCallback,
69
  });
70
 
@@ -79,6 +65,7 @@ export async function classifyImage(imageDataUrl, options = {}) {
79
  const classifier = await loadClassifier(modelKey, options.progressCallback);
80
 
81
  let predictions;
 
82
  if (option.task === 'zero-shot-image-classification') {
83
  predictions = await classifier(imageDataUrl, options.candidateLabels, {
84
  hypothesis_template: 'a photo of {}',
@@ -95,4 +82,4 @@ export async function classifyImage(imageDataUrl, options = {}) {
95
  return [...predictions]
96
  .sort((a, b) => Number(b.score) - Number(a.score))
97
  .slice(0, topK);
98
- }
 
6
  label: 'ResNet-18',
7
  modelId: 'Xenova/resnet-18',
8
  task: 'image-classification',
9
+ note: 'A compact CNN with 1,000 ImageNet labels.',
10
  dtype: 'q8',
11
  },
12
  {
 
22
  label: 'CLIP ViT-B/32',
23
  modelId: 'Xenova/clip-vit-base-patch32',
24
  task: 'zero-shot-image-classification',
25
+ note: 'A vision-language model that ranks your candidate descriptions.',
26
  dtype: 'q8',
27
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  {
29
  key: 'rtdetr-r18',
30
  label: 'RT-DETR R18',
31
  modelId: 'onnx-community/rtdetr_r18vd',
32
  task: 'object-detection',
33
+ note: 'A browser-compatible object detector packaged for Transformers.js.',
34
  dtype: 'q8',
35
  },
36
  ];
 
43
 
44
  export async function loadClassifier(modelKey, progressCallback) {
45
  const option = getModelOption(modelKey);
46
+
47
+ if (classifierCache.has(option.key)) {
48
+ return classifierCache.get(option.key);
49
+ }
50
 
51
  const classifier = await pipeline(option.task, option.modelId, {
52
  dtype: option.dtype,
53
+ device: 'wasm',
54
  progress_callback: progressCallback,
55
  });
56
 
 
65
  const classifier = await loadClassifier(modelKey, options.progressCallback);
66
 
67
  let predictions;
68
+
69
  if (option.task === 'zero-shot-image-classification') {
70
  predictions = await classifier(imageDataUrl, options.candidateLabels, {
71
  hypothesis_template: 'a photo of {}',
 
82
  return [...predictions]
83
  .sort((a, b) => Number(b.score) - Number(a.score))
84
  .slice(0, topK);
85
+ }