0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

Transformers.js 2.13、2.14 發(fā)布,新增8個(gè)新的架構(gòu)

新機(jī)器視覺(jué) ? 來(lái)源:前段圈 ? 2024-01-23 16:31 ? 次閱讀
Transformers.js 作者 Joshua Lochner 在 GitHub 宣傳 Transformers.js v2.13 和 v2.14 發(fā)布。具體更新如下(文中提到的鏈接,可通過(guò)閱讀原文獲取):
8 個(gè)新的架構(gòu)!這個(gè)版本支持了很多新的多模態(tài)架構(gòu),能夠支持的架構(gòu)總數(shù)達(dá)到了 80 個(gè)!1.支持超過(guò) 1000 種語(yǔ)言的多語(yǔ)種文本轉(zhuǎn)語(yǔ)音的 VITS!(#466)
import { pipeline } from '@xenova/transformers';


// Create English text-to-speech pipeline
const synthesizer = await pipeline('text-to-speech', 'Xenova/mms-tts-eng');


// Generate speech
const output = await synthesizer('I love transformers');
// {
//   audio: Float32Array(26112) [...],
//   sampling_rate: 16000
// }
請(qǐng)參閱此處了解可用模型的列表。首先,我們?cè)?Hugging Face Hub 上轉(zhuǎn)換了約 1140 個(gè)模型中的 12 個(gè)。如果其中沒(méi)有你想要的,可以使用我們的轉(zhuǎn)換腳本自行轉(zhuǎn)換。

2. CLIPSeg 用于零樣本圖像分割。(#478)

import { AutoTokenizer, AutoProcessor, CLIPSegForImageSegmentation, RawImage } from '@xenova/transformers';


// Load tokenizer, processor, and model
const tokenizer = await AutoTokenizer.from_pretrained('Xenova/clipseg-rd64-refined');
const processor = await AutoProcessor.from_pretrained('Xenova/clipseg-rd64-refined');
const model = await CLIPSegForImageSegmentation.from_pretrained('Xenova/clipseg-rd64-refined');


// Run tokenization
const texts = ['a glass', 'something to fill', 'wood', 'a jar'];
const text_inputs = tokenizer(texts, { padding: true, truncation: true });


// Read image and run processor
const image = await RawImage.read('https://github.com/timojl/clipseg/blob/master/example_image.jpg?raw=true');
const image_inputs = await processor(image);


// Run model with both text and pixel inputs
const { logits } = await model({ ...text_inputs, ...image_inputs });
// logits: Tensor {
//   dims: [4, 352, 352],
//   type: 'float32',
//   data: Float32Array(495616)[ ... ],
//   size: 495616
// }

您可以按如下方式可視化預(yù)測(cè)結(jié)果:

const preds = logits
  .unsqueeze_(1)
  .sigmoid_()
  .mul_(255)
  .round_()
  .to('uint8');


for (let i = 0; i < preds.dims[0]; ++i) {
  const img = RawImage.fromTensor(preds[i]);
  img.save(`prediction_${i}.png`);
}

Original "a glass" "something to fill" "wood" "a jar"
7431df5a-b9b7-11ee-8b88-92fbcf53809c.png 745c99e8-b9b7-11ee-8b88-92fbcf53809c.png 7466c42c-b9b7-11ee-8b88-92fbcf53809c.png 7478712c-b9b7-11ee-8b88-92fbcf53809c.png 7481d276-b9b7-11ee-8b88-92fbcf53809c.png

請(qǐng)查看此處以獲取可用模型列表。

3. SegFormer 用于語(yǔ)義分割和圖像分類。(#480)

import { pipeline } from '@xenova/transformers';


// Create an image segmentation pipeline
const segmenter = await pipeline('image-segmentation', 'Xenova/segformer_b2_clothes');


// Segment an image
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/young-man-standing-and-leaning-on-car.jpg';
const output = await segmenter(url);

748c26fe-b9b7-11ee-8b88-92fbcf53809c.jpg

4. Table Transformer 用于從非結(jié)構(gòu)化文檔中提取表格。(#477)

import { pipeline } from '@xenova/transformers';


// Create an object detection pipeline
const detector = await pipeline('object-detection', 'Xenova/table-transformer-detection', { quantized: false });


// Detect tables in an image
const img = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/invoice-with-table.png';
const output = await detector(img);
// [{ score: 0.9967531561851501, label: 'table', box: { xmin: 52, ymin: 322, xmax: 546, ymax: 525 } }]

5. DiT用于文檔圖像分類。(#474)

import { pipeline } from '@xenova/transformers';


// Create an image classification pipeline
const classifier = await pipeline('image-classification', 'Xenova/dit-base-finetuned-rvlcdip');


// Classify an image 
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/coca_cola_advertisement.png';
const output = await classifier(url);
// [{ label: 'advertisement', score: 0.9035086035728455 }]

6. SigLIP用于零樣本圖像分類。(#473)

import { pipeline } from '@xenova/transformers';


// Create a zero-shot image classification pipeline
const classifier = await pipeline('zero-shot-image-classification', 'Xenova/siglip-base-patch16-224');


// Classify images according to provided labels
const url = 'http://images.cocodataset.org/val2017/000000039769.jpg';
const output = await classifier(url, ['2 cats', '2 dogs'], {
    hypothesis_template: 'a photo of {}',
});
// [
//   { score: 0.16770583391189575, label: '2 cats' },
//   { score: 0.000022096000975579955, label: '2 dogs' }
// ]

7. RoFormer 用于蒙版語(yǔ)言建模、序列分類、標(biāo)記分類和問(wèn)題回答。(#464)

import { pipeline } from '@xenova/transformers';


// Create a masked language modelling pipeline
const pipe = await pipeline('fill-mask', 'Xenova/antiberta2');


// Predict missing token
const output = await pipe('? Q V Q ... C A [MASK] D ... T V S S');

8.分段任意模型 (SAM)

分段任意模型(SAM)可以在給定輸入圖像和輸入點(diǎn)的情況下,用于生成場(chǎng)景中對(duì)象的分割蒙版。請(qǐng)查看此處以獲取完整的預(yù)轉(zhuǎn)換模型列表。對(duì)該模型的支持已在#510中添加。

例子+源碼:https://huggingface.co/spaces/Xenova/segment-anything-web

示例:使用 Xenova/slimsam-77-uniform 執(zhí)行掩模生成。

import { SamModel, AutoProcessor, RawImage } from '@xenova/transformers';


const model = await SamModel.from_pretrained('Xenova/slimsam-77-uniform');
const processor = await AutoProcessor.from_pretrained('Xenova/slimsam-77-uniform');


const img_url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/corgi.jpg';
const raw_image = await RawImage.read(img_url);
const input_points = [[[340, 250]]] // 2D localization of a window


const inputs = await processor(raw_image, input_points);
const outputs = await model(inputs);


const masks = await processor.post_process_masks(outputs.pred_masks, inputs.original_sizes, inputs.reshaped_input_sizes);
console.log(masks);
// [
//   Tensor {
//     dims: [ 1, 3, 410, 614 ],
//     type: 'bool',
//     data: Uint8Array(755220) [ ... ],
//     size: 755220
//   }
// ]
const scores = outputs.iou_scores;
console.log(scores);
// Tensor {
//   dims: [ 1, 1, 3 ],
//   type: 'float32',
//   data: Float32Array(3) [
//     0.8350210189819336,
//     0.9786665439605713,
//     0.8379436731338501
//   ],
//   size: 3
// }

這樣可以將這三個(gè)預(yù)測(cè)蒙板可視化:

const image = RawImage.fromTensor(masks[0][0].mul(255));
image.save('mask.png');
Input image Visualized output

74990bbc-b9b7-11ee-8b88-92fbcf53809c.jpg

74aecbbe-b9b7-11ee-8b88-92fbcf53809c.png

接下來(lái),選擇 IoU 分?jǐn)?shù)最高的通道,在本例中是第二個(gè)(綠色)通道。將其與原始圖像相交,我們得到了該主題的孤立版本:

Selected Mask Intersected

74b58dbe-b9b7-11ee-8b88-92fbcf53809c.png

74b98e00-b9b7-11ee-8b88-92fbcf53809c.png

其他改進(jìn)

  • 修復(fù)了@Lian1230在#461中提交的關(guān)于Next.js Dockerfile的HOSTNAME 問(wèn)題。

  • 在#467中,在 README 中添加了空模板的鏈接。

  • 在 #503 中添加對(duì)使用 ConvNextFeatureExtractor 處理非方形圖像的支持

  • 通過(guò) #507 對(duì)遠(yuǎn)程 URL 中的修訂進(jìn)行編碼

  • @Lian1230 在 #461 中進(jìn)行了他們的首次貢獻(xiàn)。

改進(jìn)#485中的pipeline函數(shù)的類型。感謝@wesbos提出的建議!

意味著當(dāng)您將鼠標(biāo)懸停在類名稱上時(shí),您將獲得示例代碼來(lái)幫助您。

74c71cc8-b9b7-11ee-8b88-92fbcf53809c.gif

此版本是 #485 的后續(xù)版本,具有額外的以智能感知為中心的改進(jìn)(請(qǐng)參閱 PR)。

添加對(duì)跨編碼器模型的支持(+修復(fù)令牌類型 ID)(#501)

示例:使用 Xenova/ms-marco-TinyBERT-L-2-v2 進(jìn)行信息檢索。

import { AutoTokenizer, AutoModelForSequenceClassification } from '@xenova/transformers';


const model = await AutoModelForSequenceClassification.from_pretrained('Xenova/ms-marco-TinyBERT-L-2-v2');
const tokenizer = await AutoTokenizer.from_pretrained('Xenova/ms-marco-TinyBERT-L-2-v2');


const features = tokenizer(
    ['How many people live in Berlin?', 'How many people live in Berlin?'],
    {
        text_pair: [
            'Berlin has a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers.',
            'New York City is famous for the Metropolitan Museum of Art.',
        ],
        padding: true,
        truncation: true,
    }
)


const { logits } = await model(features)
console.log(logits.data);
// quantized:   [ 7.210887908935547, -11.559350967407227 ]
// unquantized: [ 7.235750675201416, -11.562294006347656 ]


聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 源碼
    +關(guān)注

    關(guān)注

    8

    文章

    630

    瀏覽量

    29074
  • 模型
    +關(guān)注

    關(guān)注

    1

    文章

    3062

    瀏覽量

    48575
  • 架構(gòu)
    +關(guān)注

    關(guān)注

    1

    文章

    505

    瀏覽量

    25422

原文標(biāo)題:Transformers.js 2.13、2.14 發(fā)布,新增 8 個(gè)新的架構(gòu)

文章出處:【微信號(hào):vision263com,微信公眾號(hào):新機(jī)器視覺(jué)】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。

收藏 人收藏

    評(píng)論

    相關(guān)推薦

    鴻蒙跨端實(shí)踐-JS虛擬機(jī)架構(gòu)實(shí)現(xiàn)

    類似的框架,我們需要自行實(shí)現(xiàn)以確保核心基礎(chǔ)能力的完整。 鴻蒙虛擬機(jī)的開(kāi)發(fā)經(jīng)歷了從最初 ArkTs2V8 到 JSVM + Roma新架構(gòu)方案 。在此過(guò)程中,我們實(shí)現(xiàn)了完整的鴻蒙版的“J2V8”和 基于系統(tǒng)JSVM的
    的頭像 發(fā)表于 09-30 14:42 ?2222次閱讀
    鴻蒙跨端實(shí)踐-<b class='flag-5'>JS</b>虛擬機(jī)<b class='flag-5'>架構(gòu)</b>實(shí)現(xiàn)

    使用基于Transformers的API在CPU上實(shí)現(xiàn)LLM高效推理

    英特爾 Extension for Transformers是英特爾推出的一個(gè)創(chuàng)新工具包,可基于英特爾 架構(gòu)平臺(tái),尤其是第四代英特爾 至強(qiáng) 可擴(kuò)展處理器(代號(hào) SapphireRapids,SPR)顯著加速基于
    的頭像 發(fā)表于 01-22 11:11 ?2399次閱讀
    使用基于<b class='flag-5'>Transformers</b>的API在CPU上實(shí)現(xiàn)LLM高效推理

    用戶管理-動(dòng)態(tài)調(diào)用VI(新增用戶插件)

    介紹一種基于動(dòng)態(tài)調(diào)用VI的用戶登錄管理的方法,結(jié)合之前介紹的源代碼發(fā)布,將新增的用戶信息(一個(gè)獨(dú)立的VI)以源代碼發(fā)布的形式(去除程序面板)放入指定User List文件夾下,即使生成
    發(fā)表于 04-26 22:40

    OpenHarmony 3.0 LTS 新增特性功能

    內(nèi)容:標(biāo)準(zhǔn)系統(tǒng)新增特性功能用戶程序框架支持服務(wù)能力(ServiceAbility,DataAbility)和線程模型。支持文件安全訪問(wèn),即文件轉(zhuǎn)成URI和解析URI打開(kāi)文件的能力。支持設(shè)備管理PIN碼
    發(fā)表于 09-30 08:24

    94個(gè)JS/eTS開(kāi)源組件首發(fā)上新,肯定有你要用的一款!

    2021年的華為開(kāi)發(fā)者大會(huì)(HDC2021)上,我們發(fā)布了新一代的聲明式UI框架——方舟開(kāi)發(fā)框架(ArkUI)。 ArkUI框架引入了基于TS擴(kuò)展的聲明式開(kāi)發(fā)范式。自此,越來(lái)越多的開(kāi)發(fā)者加入到JS
    發(fā)表于 05-09 14:51

    HarmonyOS 3.0 Beta版本說(shuō)明

    與OpenHarmony SDK配套使用。配套JS/eTS SDK、Native SDK,推薦使用JS/eTS進(jìn)行應(yīng)用開(kāi)發(fā)。OpenHarmony SDK新增API Version 8
    發(fā)表于 07-07 14:16

    面向開(kāi)發(fā)者的HarmonyOS 3.0 Beta發(fā)布

    與OpenHarmony SDK配套使用?!?配套JS/eTS SDK、Native SDK,推薦使用JS/eTS進(jìn)行應(yīng)用開(kāi)發(fā)?!?OpenHarmony SDK新增API Version 8
    發(fā)表于 07-08 11:14

    OpenHarmony 3.2 Beta2 版本發(fā)布:支持電源管理重啟恢復(fù)機(jī)制等

    worker傳遞I58034 【增強(qiáng)特性】使用libuv統(tǒng)一JS Looper機(jī)制I57ZZH 【新增特性】提供創(chuàng)建不同Hap包上下文能力NA包管理新增默認(rèn)應(yīng)用管理能力,支持眾測(cè)應(yīng)用、獲取包指紋信息等
    發(fā)表于 08-02 10:31

    DevEco Studio 3.1 Beta1版本發(fā)布——新增六大關(guān)鍵特性,開(kāi)發(fā)更高效

    、開(kāi)發(fā)、編譯、調(diào)試等功能。2023年2月16日發(fā)布的DevEco Studio 3.1 Beta1版本,在Canary1版本基礎(chǔ)上,新增以下關(guān)鍵特性:-> 新增支持Windows 11
    發(fā)表于 02-24 11:22

    BJDEEN PULSE TRANSFORMERS

    aboutthe need  for  versatile pulse transformers that meet all the electricalrequirements of Manchester II serial biphas
    發(fā)表于 06-11 08:40 ?9次下載

    node.jsjs要點(diǎn)總結(jié)

    Node.js是一個(gè)面向服務(wù)器的框架,立足于Chrome強(qiáng)大的V8 JS引擎。盡管它由C++編寫而成,但是它及其應(yīng)用是運(yùn)行在JS上的。本文為
    發(fā)表于 10-13 10:39 ?0次下載

    GPU-Z 2.26.0正式發(fā)布 新增對(duì)部分假冒顯卡核心的支持

    TechPowerUp剛剛發(fā)布了最新版的GPU-Z 2.26.0,除了支持部分新硬件,還修復(fù)了大量Bug,并新增了對(duì)部分假冒顯卡核心的支持,再也不怕被JS坑了。
    發(fā)表于 10-09 15:26 ?707次閱讀

    安徽省已累計(jì)建設(shè)完成5G基站2.14萬(wàn)個(gè)

    當(dāng)前,在安徽,5G示范應(yīng)用初見(jiàn)成效,5G發(fā)展開(kāi)局良好。從基站建設(shè)情況來(lái)看,安徽省已累計(jì)建設(shè)完成5G基站2.14萬(wàn)個(gè),預(yù)計(jì)全年將順利完成2.5萬(wàn)個(gè)5G基站鋪設(shè),基本實(shí)現(xiàn)地級(jí)市城區(qū)連續(xù)覆蓋。
    的頭像 發(fā)表于 11-04 16:36 ?1860次閱讀

    貿(mào)澤電子新品推薦:2021年8新增超20000個(gè)物料

     2021年8月,貿(mào)澤總共新增了20,276個(gè)物料,均可在訂單確認(rèn)后當(dāng)天發(fā)貨 。
    的頭像 發(fā)表于 10-08 14:27 ?3693次閱讀

    Transformers的功能概述

    近年來(lái),我們聽(tīng)說(shuō)了很多關(guān)于Transformers的事情,并且在過(guò)去的幾年里,它們已經(jīng)在NLP領(lǐng)域取得了巨大成功。Transformers是一種使用注意力機(jī)制(Attention)顯著改進(jìn)深度學(xué)習(xí)
    的頭像 發(fā)表于 01-23 10:15 ?576次閱讀
    <b class='flag-5'>Transformers</b>的功能概述