{ // 获取包含Hugging Face文本的span元素 const spans = link.querySelectorAll('span.whitespace-nowrap, span.hidden.whitespace-nowrap'); spans.forEach(span => { if (span.textContent && span.textContent.trim().match(/Hugging\s*Face/i)) { span.textContent = 'AI快站'; } }); }); // 替换logo图片的alt属性 document.querySelectorAll('img[alt*="Hugging"], img[alt*="Face"]').forEach(img => { if (img.alt.match(/Hugging\s*Face/i)) { img.alt = 'AI快站 logo'; } }); } // 替换导航栏中的链接 function replaceNavigationLinks() { // 已替换标记,防止重复运行 if (window._navLinksReplaced) { return; } // 已经替换过的链接集合,防止重复替换 const replacedLinks = new Set(); // 只在导航栏区域查找和替换链接 const headerArea = document.querySelector('header') || document.querySelector('nav'); if (!headerArea) { return; } // 在导航区域内查找链接 const navLinks = headerArea.querySelectorAll('a'); navLinks.forEach(link => { // 如果已经替换过,跳过 if (replacedLinks.has(link)) return; const linkText = link.textContent.trim(); const linkHref = link.getAttribute('href') || ''; // 替换Spaces链接 - 仅替换一次 if ( (linkHref.includes('/spaces') || linkHref === '/spaces' || linkText === 'Spaces' || linkText.match(/^s*Spacess*$/i)) && linkText !== 'PDF TO Markdown' && linkText !== 'PDF TO Markdown' ) { link.textContent = 'PDF TO Markdown'; link.href = 'https://fast360.xyz'; link.setAttribute('target', '_blank'); link.setAttribute('rel', 'noopener noreferrer'); replacedLinks.add(link); } // 删除Posts链接 else if ( (linkHref.includes('/posts') || linkHref === '/posts' || linkText === 'Posts' || linkText.match(/^s*Postss*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } // 替换Docs链接 - 仅替换一次 else if ( (linkHref.includes('/docs') || linkHref === '/docs' || linkText === 'Docs' || linkText.match(/^s*Docss*$/i)) && linkText !== 'Voice Cloning' ) { link.textContent = 'Voice Cloning'; link.href = 'https://vibevoice.info/'; replacedLinks.add(link); } // 删除Enterprise链接 else if ( (linkHref.includes('/enterprise') || linkHref === '/enterprise' || linkText === 'Enterprise' || linkText.match(/^s*Enterprises*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } }); // 查找可能嵌套的Spaces和Posts文本 const textNodes = []; function findTextNodes(element) { if (element.nodeType === Node.TEXT_NODE) { const text = element.textContent.trim(); if (text === 'Spaces' || text === 'Posts' || text === 'Enterprise') { textNodes.push(element); } } else { for (const child of element.childNodes) { findTextNodes(child); } } } // 只在导航区域内查找文本节点 findTextNodes(headerArea); // 替换找到的文本节点 textNodes.forEach(node => { const text = node.textContent.trim(); if (text === 'Spaces') { node.textContent = node.textContent.replace(/Spaces/g, 'PDF TO Markdown'); } else if (text === 'Posts') { // 删除Posts文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } else if (text === 'Enterprise') { // 删除Enterprise文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } }); // 标记已替换完成 window._navLinksReplaced = true; } // 替换代码区域中的域名 function replaceCodeDomains() { // 特别处理span.hljs-string和span.njs-string元素 document.querySelectorAll('span.hljs-string, span.njs-string, span[class*="hljs-string"], span[class*="njs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换hljs-string类的span中的域名(移除多余的转义符号) document.querySelectorAll('span.hljs-string, span[class*="hljs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换pre和code标签中包含git clone命令的域名 document.querySelectorAll('pre, code').forEach(element => { if (element.textContent && element.textContent.includes('git clone')) { const text = element.innerHTML; if (text.includes('huggingface.co')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 处理特定的命令行示例 document.querySelectorAll('pre, code').forEach(element => { const text = element.innerHTML; if (text.includes('huggingface.co')) { // 针对git clone命令的专门处理 if (text.includes('git clone') || text.includes('GIT_LFS_SKIP_SMUDGE=1')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 特别处理模型下载页面上的代码片段 document.querySelectorAll('.flex.border-t, .svelte_hydrator, .inline-block').forEach(container => { const content = container.innerHTML; if (content && content.includes('huggingface.co')) { container.innerHTML = content.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 特别处理模型仓库克隆对话框中的代码片段 try { // 查找包含"Clone this model repository"标题的对话框 const cloneDialog = document.querySelector('.svelte_hydration_boundary, [data-target="MainHeader"]'); if (cloneDialog) { // 查找对话框中所有的代码片段和命令示例 const codeElements = cloneDialog.querySelectorAll('pre, code, span'); codeElements.forEach(element => { if (element.textContent && element.textContent.includes('huggingface.co')) { if (element.innerHTML.includes('huggingface.co')) { element.innerHTML = element.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { element.textContent = element.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); } // 更精确地定位克隆命令中的域名 document.querySelectorAll('[data-target]').forEach(container => { const codeBlocks = container.querySelectorAll('pre, code, span.hljs-string'); codeBlocks.forEach(block => { if (block.textContent && block.textContent.includes('huggingface.co')) { if (block.innerHTML.includes('huggingface.co')) { block.innerHTML = block.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { block.textContent = block.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); }); } catch (e) { // 错误处理但不打印日志 } } // 当DOM加载完成后执行替换 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); }); } else { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); } // 增加一个MutationObserver来处理可能的动态元素加载 const observer = new MutationObserver(mutations => { // 检查是否导航区域有变化 const hasNavChanges = mutations.some(mutation => { // 检查是否存在header或nav元素变化 return Array.from(mutation.addedNodes).some(node => { if (node.nodeType === Node.ELEMENT_NODE) { // 检查是否是导航元素或其子元素 if (node.tagName === 'HEADER' || node.tagName === 'NAV' || node.querySelector('header, nav')) { return true; } // 检查是否在导航元素内部 let parent = node.parentElement; while (parent) { if (parent.tagName === 'HEADER' || parent.tagName === 'NAV') { return true; } parent = parent.parentElement; } } return false; }); }); // 只在导航区域有变化时执行替换 if (hasNavChanges) { // 重置替换状态,允许再次替换 window._navLinksReplaced = false; replaceHeaderBranding(); replaceNavigationLinks(); } }); // 开始观察document.body的变化,包括子节点 if (document.body) { observer.observe(document.body, { childList: true, subtree: true }); } else { document.addEventListener('DOMContentLoaded', () => { observer.observe(document.body, { childList: true, subtree: true }); }); } })(); \r\n\r\n```\r\n\r\nPlease help to check it. Thank you.","html":"

hi, I try to run demo code but got error at this line:

\n
const { output_image } = await model({ input_image: pixel_values });\n
\n

\"Screenshot

\n

main.js:

\n
import { AutoModel, AutoProcessor, RawImage } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers';\n\n// Load model and processor\nconst model_id = 'onnx-community/BiRefNet_T';\nconst model = await AutoModel.from_pretrained(model_id, { dtype: 'fp32' });\nconst processor = await AutoProcessor.from_pretrained(model_id);\n\n// Load image from URL\nconst url = 'https://images.pexels.com/photos/5965592/pexels-photo-5965592.jpeg?auto=compress&cs=tinysrgb&w=1024';\nconst image = await RawImage.fromURL(url);\n\n// Pre-process image\nconst { pixel_values } = await processor(image);\n\n// Predict alpha matte\nconst { output_image } = await model({ input_image: pixel_values });\n\n// Save output mask\nconst mask = await RawImage.fromTensor(output_image[0].sigmoid().mul(255).to('uint8')).resize(image.width, image.height);\nmask.save('mask.png');\n
\n

index.html:

\n
<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"UTF-8\" />\n  <title>Background Removal</title>\n</head>\n<body>\n<script type=\"module\" src=\"/main.js\"></script>\n</body>\n</html>\n
\n

Please help to check it. Thank you.

\n","updatedAt":"2024-08-25T15:35:21.769Z","author":{"_id":"66666111da1e6adefe1bfd41","avatarUrl":"https://aifasthub.com/avatars/v1/production/uploads/66666111da1e6adefe1bfd41/zEPfIcq4Qwf2obqBxM6As.jpeg","fullname":"Tidus","name":"tidus2102","type":"user","isPro":false,"isHf":false,"isHfAdmin":false,"isMod":false,"followerCount":2}},"numEdits":0,"identifiedLanguage":{"language":"en","probability":0.3637307584285736},"editors":["tidus2102"],"editorAvatarUrls":["https://aifasthub.com/avatars/v1/production/uploads/66666111da1e6adefe1bfd41/zEPfIcq4Qwf2obqBxM6As.jpeg"],"reactions":[],"isReport":false}},{"id":"66cefb3bbee2b9a93b86eae4","author":{"_id":"66666111da1e6adefe1bfd41","avatarUrl":"https://aifasthub.com/avatars/v1/production/uploads/66666111da1e6adefe1bfd41/zEPfIcq4Qwf2obqBxM6As.jpeg","fullname":"Tidus","name":"tidus2102","type":"user","isPro":false,"isHf":false,"isHfAdmin":false,"isMod":false,"followerCount":2,"isOwner":false,"isOrgMember":false},"createdAt":"2024-08-28T10:26:03.000Z","type":"comment","data":{"edited":false,"hidden":false,"latest":{"raw":"Hi @Xenova, please help to check this issue. Thank you.","html":"

Hi \n\n@Xenova\n\t, please help to check this issue. Thank you.

\n","updatedAt":"2024-08-28T10:26:03.836Z","author":{"_id":"66666111da1e6adefe1bfd41","avatarUrl":"https://aifasthub.com/avatars/v1/production/uploads/66666111da1e6adefe1bfd41/zEPfIcq4Qwf2obqBxM6As.jpeg","fullname":"Tidus","name":"tidus2102","type":"user","isPro":false,"isHf":false,"isHfAdmin":false,"isMod":false,"followerCount":2}},"numEdits":0,"identifiedLanguage":{"language":"en","probability":0.9264660477638245},"editors":["tidus2102"],"editorAvatarUrls":["https://aifasthub.com/avatars/v1/production/uploads/66666111da1e6adefe1bfd41/zEPfIcq4Qwf2obqBxM6As.jpeg"],"reactions":[],"isReport":false}},{"id":"66d56491f87ed8c2bc02fe59","author":{"_id":"651fa9db4376ae05d62b36cc","avatarUrl":"https://aifasthub.com/avatars/v1/production/uploads/651fa9db4376ae05d62b36cc/Q9lwi-ZkMVQRGfPB1uuTB.png","fullname":"Jozef Chutka","name":"wide-video","type":"user","isPro":false,"isHf":false,"isHfAdmin":false,"isMod":false,"isOwner":false,"isOrgMember":false},"createdAt":"2024-09-02T07:09:05.000Z","type":"comment","data":{"edited":false,"hidden":false,"latest":{"raw":"I am getting `An error occurred during model execution: \"246040216\".` with 3.0.0-alpha.14","html":"

I am getting An error occurred during model execution: \"246040216\". with 3.0.0-alpha.14

\n","updatedAt":"2024-09-02T07:09:05.318Z","author":{"_id":"651fa9db4376ae05d62b36cc","avatarUrl":"https://aifasthub.com/avatars/v1/production/uploads/651fa9db4376ae05d62b36cc/Q9lwi-ZkMVQRGfPB1uuTB.png","fullname":"Jozef Chutka","name":"wide-video","type":"user","isPro":false,"isHf":false,"isHfAdmin":false,"isMod":false}},"numEdits":0,"identifiedLanguage":{"language":"en","probability":0.9321386814117432},"editors":["wide-video"],"editorAvatarUrls":["https://aifasthub.com/avatars/v1/production/uploads/651fa9db4376ae05d62b36cc/Q9lwi-ZkMVQRGfPB1uuTB.png"],"reactions":[],"isReport":false}},{"id":"66d5a331974c5c6902b574e6","author":{"_id":"61b253b7ac5ecaae3d1efe0c","avatarUrl":"https://aifasthub.com/avatars/v1/production/uploads/61b253b7ac5ecaae3d1efe0c/hwiQ0uvz3t-L5a-NtBIO6.png","fullname":"Joshua","name":"Xenova","type":"user","isPro":false,"isHf":true,"isHfAdmin":false,"isMod":false,"followerCount":6848,"isOwner":false,"isOrgMember":true},"createdAt":"2024-09-02T11:36:17.000Z","type":"comment","data":{"edited":false,"hidden":false,"latest":{"raw":"Hi there! We've only tested with Node.js. The error you're facing seems to be an out-of-memory issue (which may make sense since the images are processed at the full resolution of 1024x1024). cc @schmuell might be able to help.","html":"

Hi there! We've only tested with Node.js. The error you're facing seems to be an out-of-memory issue (which may make sense since the images are processed at the full resolution of 1024x1024). cc \n\n@schmuell\n\t might be able to help.

\n","updatedAt":"2024-09-02T11:36:17.291Z","author":{"_id":"61b253b7ac5ecaae3d1efe0c","avatarUrl":"https://aifasthub.com/avatars/v1/production/uploads/61b253b7ac5ecaae3d1efe0c/hwiQ0uvz3t-L5a-NtBIO6.png","fullname":"Joshua","name":"Xenova","type":"user","isPro":false,"isHf":true,"isHfAdmin":false,"isMod":false,"followerCount":6848}},"numEdits":0,"identifiedLanguage":{"language":"en","probability":0.9622926712036133},"editors":["Xenova"],"editorAvatarUrls":["https://aifasthub.com/avatars/v1/production/uploads/61b253b7ac5ecaae3d1efe0c/hwiQ0uvz3t-L5a-NtBIO6.png"],"reactions":[],"isReport":false}},{"id":"66d74639483bbfc9e42a9bfd","author":{"_id":"66666111da1e6adefe1bfd41","avatarUrl":"https://aifasthub.com/avatars/v1/production/uploads/66666111da1e6adefe1bfd41/zEPfIcq4Qwf2obqBxM6As.jpeg","fullname":"Tidus","name":"tidus2102","type":"user","isPro":false,"isHf":false,"isHfAdmin":false,"isMod":false,"followerCount":2,"isOwner":false,"isOrgMember":false},"createdAt":"2024-09-03T17:24:09.000Z","type":"title-change","data":{"from":"Error when run demo code","to":"Error when run demo code on Chrome"}},{"id":"66d93491204cd0a4f8a92ffe","author":{"_id":"6303fb1e0907b9a115c5b650","avatarUrl":"/avatars/c113a3f21d3bb5214df75fe425e44377.svg","fullname":"schmuell","name":"schmuell","type":"user","isPro":false,"isHf":false,"isHfAdmin":false,"isMod":false,"followerCount":16,"isOwner":false,"isOrgMember":true},"createdAt":"2024-09-05T04:33:21.000Z","type":"comment","data":{"edited":false,"hidden":false,"latest":{"raw":"filed a webgpu issue for this:\nhttps://github.com/microsoft/onnxruntime/issues/21968\nYes, using lots of memory but should still work.\nSomebody is looking into it.","html":"

filed a webgpu issue for this:
https://github.com/microsoft/onnxruntime/issues/21968
Yes, using lots of memory but should still work.
Somebody is looking into it.

\n","updatedAt":"2024-09-05T04:33:21.074Z","author":{"_id":"6303fb1e0907b9a115c5b650","avatarUrl":"/avatars/c113a3f21d3bb5214df75fe425e44377.svg","fullname":"schmuell","name":"schmuell","type":"user","isPro":false,"isHf":false,"isHfAdmin":false,"isMod":false,"followerCount":16}},"numEdits":0,"identifiedLanguage":{"language":"en","probability":0.8786188960075378},"editors":["schmuell"],"editorAvatarUrls":["/avatars/c113a3f21d3bb5214df75fe425e44377.svg"],"reactions":[{"reaction":"👍","users":["Xenova"],"count":1}],"isReport":false}}],"pinned":false,"locked":false,"collection":"discussions","isPullRequest":false,"isReport":false},"repo":{"name":"onnx-community/BiRefNet_lite-ONNX","type":"model"},"activeTab":"discussion","discussionRole":0,"watched":false,"muted":false,"repoDiscussionsLocked":false}">

Error when run demo code on Chrome

#1
by tidus2102 - opened

hi, I try to run demo code but got error at this line:

const { output_image } = await model({ input_image: pixel_values });

Screenshot 2024-08-25 at 22.19.31.jpg

main.js:

import { AutoModel, AutoProcessor, RawImage } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers';

// Load model and processor
const model_id = 'onnx-community/BiRefNet_T';
const model = await AutoModel.from_pretrained(model_id, { dtype: 'fp32' });
const processor = await AutoProcessor.from_pretrained(model_id);

// Load image from URL
const url = 'https://images.pexels.com/photos/5965592/pexels-photo-5965592.jpeg?auto=compress&cs=tinysrgb&w=1024';
const image = await RawImage.fromURL(url);

// Pre-process image
const { pixel_values } = await processor(image);

// Predict alpha matte
const { output_image } = await model({ input_image: pixel_values });

// Save output mask
const mask = await RawImage.fromTensor(output_image[0].sigmoid().mul(255).to('uint8')).resize(image.width, image.height);
mask.save('mask.png');

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Background Removal</title>
</head>
<body>
<script type="module" src="/main.js"></script>
</body>
</html>

Please help to check it. Thank you.

Hi @Xenova , please help to check this issue. Thank you.

I am getting An error occurred during model execution: "246040216". with 3.0.0-alpha.14

ONNX Community org

Hi there! We've only tested with Node.js. The error you're facing seems to be an out-of-memory issue (which may make sense since the images are processed at the full resolution of 1024x1024). cc @schmuell might be able to help.

tidus2102 changed discussion title from Error when run demo code to Error when run demo code on Chrome
ONNX Community org

filed a webgpu issue for this:
https://github.com/microsoft/onnxruntime/issues/21968
Yes, using lots of memory but should still work.
Somebody is looking into it.

Sign up or log in to comment