seonoh12 commited on
Commit
5569c15
1 Parent(s): 736e977

Update mobilevit.html

Browse files
Files changed (1) hide show
  1. mobilevit.html +5 -1
mobilevit.html CHANGED
@@ -6,6 +6,7 @@
6
  <title>Image Classification - Hugging Face Transformers.js</title>
7
 
8
  <script type="module">
 
9
  // 허깅페이스의 pipeline 모듈을 import하십시오.
10
  // To-Do: ???
11
  // Make it available globally
@@ -111,6 +112,7 @@
111
  let classifier;
112
  // Initialize the sentiment analysis model
113
  async function initializeModel() {
 
114
  // pipeline 함수를 이용하여 Xenova/mobilevit-small 모델의 인스턴스를 생성하여 이를 classifier에 저정하십시오. 인스턴스 생성 시 quantized 파라미터의 값을 false로 설정하십시오.
115
  // To-Do: ???
116
  }
@@ -122,7 +124,7 @@
122
  async function classifyImageLocal() {
123
  // HTML DOM의 element Id가 imageClassificationLocalFile인 element의 값을 fileInput으로 저장하십시오.
124
  // To-Do: const fileInput = ???
125
-
126
  const file = fileInput.files[0];
127
  if (!file) {
128
  alert('Please select an image file first.');
@@ -130,12 +132,14 @@
130
  }
131
 
132
  const url = URL.createObjectURL(file);
 
133
  // classifier에 url을 입력하여 출력된 결과를 result에 저장하십시오.
134
  // To-Do: ???
135
  document.getElementById("outputAreaLocal").innerText = JSON.stringify(result, null, 2);
136
  }
137
  async function classifyTopImage() {
138
  const textFieldValue = document.getElementById("imageClassificationTopURLText").value.trim();
 
139
  // classifier에 textFieldValue를 입력 변수로, topk 파라미터 값을 3으로 설정하여 classifer를 수행하고 그 결과를 result에 저장하십시오.
140
  // To-Do: ???
141
  document.getElementById("outputAreaTop").innerText = JSON.stringify(result, null, 2);
 
6
  <title>Image Classification - Hugging Face Transformers.js</title>
7
 
8
  <script type="module">
9
+ import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.5.4';
10
  // 허깅페이스의 pipeline 모듈을 import하십시오.
11
  // To-Do: ???
12
  // Make it available globally
 
112
  let classifier;
113
  // Initialize the sentiment analysis model
114
  async function initializeModel() {
115
+ classifier = await pipeline('image-classification', 'Xenova/mobilevit-small', { quantized: false });
116
  // pipeline 함수를 이용하여 Xenova/mobilevit-small 모델의 인스턴스를 생성하여 이를 classifier에 저정하십시오. 인스턴스 생성 시 quantized 파라미터의 값을 false로 설정하십시오.
117
  // To-Do: ???
118
  }
 
124
  async function classifyImageLocal() {
125
  // HTML DOM의 element Id가 imageClassificationLocalFile인 element의 값을 fileInput으로 저장하십시오.
126
  // To-Do: const fileInput = ???
127
+ const fileInput = document.getElementById("imageClassificationLocalFile");
128
  const file = fileInput.files[0];
129
  if (!file) {
130
  alert('Please select an image file first.');
 
132
  }
133
 
134
  const url = URL.createObjectURL(file);
135
+ const result = await classifier(url);
136
  // classifier에 url을 입력하여 출력된 결과를 result에 저장하십시오.
137
  // To-Do: ???
138
  document.getElementById("outputAreaLocal").innerText = JSON.stringify(result, null, 2);
139
  }
140
  async function classifyTopImage() {
141
  const textFieldValue = document.getElementById("imageClassificationTopURLText").value.trim();
142
+ const result = await classifier(textFieldValue, { topk: 3 });
143
  // classifier에 textFieldValue를 입력 변수로, topk 파라미터 값을 3으로 설정하여 classifer를 수행하고 그 결과를 result에 저장하십시오.
144
  // To-Do: ???
145
  document.getElementById("outputAreaTop").innerText = JSON.stringify(result, null, 2);