update index.js
Browse files
index.js
CHANGED
@@ -6,6 +6,8 @@ const imageContainer = document.getElementById('image-container');
|
|
6 |
const outputContainer = document.getElementById('output-container');
|
7 |
|
8 |
status.textContent = 'Loading model...';
|
|
|
|
|
9 |
|
10 |
// Load model and processor
|
11 |
const model = await AutoModel.from_pretrained('Xenova/modnet-onnx', { quantized: false });
|
@@ -46,9 +48,9 @@ fileSelect.addEventListener('change', function (e) {
|
|
46 |
});
|
47 |
|
48 |
async function start(source) {
|
|
|
49 |
status.textContent = 'processing';
|
50 |
console.log('start process')
|
51 |
-
const startTime = new Date();
|
52 |
|
53 |
const image = await RawImage.read(source);
|
54 |
// Process image
|
@@ -62,9 +64,6 @@ async function start(source) {
|
|
62 |
const matteImage = await RawImage.fromTensor(output[0].mul(255).to('uint8')).resize(image.width, image.height);
|
63 |
|
64 |
console.log('matteImage', matteImage, output)
|
65 |
-
const endTime = new Date();
|
66 |
-
const diff = (endTime - startTime) / 1000
|
67 |
-
setTimeout(() => status.textContent = 'Finish: ' + diff + 's', 100)
|
68 |
|
69 |
async function renderRawImage(image) {
|
70 |
let rawCanvas = await image.toCanvas();
|
@@ -115,6 +114,9 @@ async function start(source) {
|
|
115 |
|
116 |
// 将图片添加到 body 中或者其他 HTML 元素
|
117 |
outputContainer.appendChild(img);
|
|
|
|
|
|
|
118 |
})
|
119 |
.catch(function (error) {
|
120 |
// 捕获和处理 blob 创建过程中可能出现的错误
|
|
|
6 |
const outputContainer = document.getElementById('output-container');
|
7 |
|
8 |
status.textContent = 'Loading model...';
|
9 |
+
let startTime = null;
|
10 |
+
let endTime = null;
|
11 |
|
12 |
// Load model and processor
|
13 |
const model = await AutoModel.from_pretrained('Xenova/modnet-onnx', { quantized: false });
|
|
|
48 |
});
|
49 |
|
50 |
async function start(source) {
|
51 |
+
startTime = new Date();
|
52 |
status.textContent = 'processing';
|
53 |
console.log('start process')
|
|
|
54 |
|
55 |
const image = await RawImage.read(source);
|
56 |
// Process image
|
|
|
64 |
const matteImage = await RawImage.fromTensor(output[0].mul(255).to('uint8')).resize(image.width, image.height);
|
65 |
|
66 |
console.log('matteImage', matteImage, output)
|
|
|
|
|
|
|
67 |
|
68 |
async function renderRawImage(image) {
|
69 |
let rawCanvas = await image.toCanvas();
|
|
|
114 |
|
115 |
// 将图片添加到 body 中或者其他 HTML 元素
|
116 |
outputContainer.appendChild(img);
|
117 |
+
endTime = new Date();
|
118 |
+
const diff = (endTime - startTime) / 1000
|
119 |
+
setTimeout(() => status.textContent = 'Finish: ' + diff + 's', 0)
|
120 |
})
|
121 |
.catch(function (error) {
|
122 |
// 捕获和处理 blob 创建过程中可能出现的错误
|