Buckets:

download
raw
98 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;processors&quot;,&quot;local&quot;:&quot;processors&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;On this page&quot;,&quot;local&quot;:&quot;on-this-page&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Classes&quot;,&quot;local&quot;:&quot;classes&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;FeatureExtractor&quot;,&quot;local&quot;:&quot;featureextractor&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;FeatureExtractor.constructor(config)&quot;,&quot;local&quot;:&quot;featureextractorconstructorconfig&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;FeatureExtractor.from_pretrained(pretrained_model_name_or_path, options)&quot;,&quot;local&quot;:&quot;featureextractorfrompretrainedpretrainedmodelnameorpath-options&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3},{&quot;title&quot;:&quot;ImageProcessor&quot;,&quot;local&quot;:&quot;imageprocessor&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;ImageProcessor(images, args)&quot;,&quot;local&quot;:&quot;imageprocessorimages-args&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.constructor(config)&quot;,&quot;local&quot;:&quot;imageprocessorconstructorconfig&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.thumbnail(image, size, [resample])&quot;,&quot;local&quot;:&quot;imageprocessorthumbnailimage-size-resample&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.crop_margin(image, gray_threshold)&quot;,&quot;local&quot;:&quot;imageprocessorcropmarginimage-graythreshold&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.pad_image(pixelData, imgDims, padSize, options)&quot;,&quot;local&quot;:&quot;imageprocessorpadimagepixeldata-imgdims-padsize-options&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.rescale(pixelData)&quot;,&quot;local&quot;:&quot;imageprocessorrescalepixeldata&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.get_resize_output_image_size(image, size)&quot;,&quot;local&quot;:&quot;imageprocessorgetresizeoutputimagesizeimage-size&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.resize(image)&quot;,&quot;local&quot;:&quot;imageprocessorresizeimage&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.preprocess(image, overrides)&quot;,&quot;local&quot;:&quot;imageprocessorpreprocessimage-overrides&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.from_pretrained(pretrained_model_name_or_path, options)&quot;,&quot;local&quot;:&quot;imageprocessorfrompretrainedpretrainedmodelnameorpath-options&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3},{&quot;title&quot;:&quot;AutoFeatureExtractor&quot;,&quot;local&quot;:&quot;autofeatureextractor&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;AutoFeatureExtractor.from_pretrained(pretrained_model_name_or_path, options)&quot;,&quot;local&quot;:&quot;autofeatureextractorfrompretrainedpretrainedmodelnameorpath-options&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3},{&quot;title&quot;:&quot;AutoImageProcessor&quot;,&quot;local&quot;:&quot;autoimageprocessor&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;AutoImageProcessor.from_pretrained(pretrained_model_name_or_path, options)&quot;,&quot;local&quot;:&quot;autoimageprocessorfrompretrainedpretrainedmodelnameorpath-options&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3},{&quot;title&quot;:&quot;AutoProcessor&quot;,&quot;local&quot;:&quot;autoprocessor&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;AutoProcessor.from_pretrained(pretrained_model_name_or_path, options)&quot;,&quot;local&quot;:&quot;autoprocessorfrompretrainedpretrainedmodelnameorpath-options&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Processor&quot;,&quot;local&quot;:&quot;processor&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Processor(input, args)&quot;,&quot;local&quot;:&quot;processorinput-args&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;Processor.constructor(config, components, chat_template)&quot;,&quot;local&quot;:&quot;processorconstructorconfig-components-chattemplate&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;Processor.apply_chat_template(messages, options)&quot;,&quot;local&quot;:&quot;processorapplychattemplatemessages-options&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;Processor.batch_decode(batch, decode_args)&quot;,&quot;local&quot;:&quot;processorbatchdecodebatch-decodeargs&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;Processor.decode(token_ids, [decode_args])&quot;,&quot;local&quot;:&quot;processordecodetokenids-decodeargs&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;Processor.from_pretrained(pretrained_model_name_or_path, options)&quot;,&quot;local&quot;:&quot;processorfrompretrainedpretrainedmodelnameorpath-options&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Type Definitions&quot;,&quot;local&quot;:&quot;type-definitions&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;HeightWidth&quot;,&quot;local&quot;:&quot;heightwidth&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;ImageProcessorResult&quot;,&quot;local&quot;:&quot;imageprocessorresult&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;ImageProcessorConfig&quot;,&quot;local&quot;:&quot;imageprocessorconfig&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;PreprocessedImage&quot;,&quot;local&quot;:&quot;preprocessedimage&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;ProcessorProperties&quot;,&quot;local&quot;:&quot;processorproperties&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;PretrainedProcessorOptions&quot;,&quot;local&quot;:&quot;pretrainedprocessoroptions&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2}],&quot;depth&quot;:1}">
<link href="/docs/transformers.js/pr_1665/en/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload">
<link rel="modulepreload" href="/docs/transformers.js/pr_1665/en/_app/immutable/entry/start.cb58eb6f.js">
<link rel="modulepreload" href="/docs/transformers.js/pr_1665/en/_app/immutable/chunks/scheduler.6efaaf90.js">
<link rel="modulepreload" href="/docs/transformers.js/pr_1665/en/_app/immutable/chunks/singletons.08239980.js">
<link rel="modulepreload" href="/docs/transformers.js/pr_1665/en/_app/immutable/chunks/paths.611c3944.js">
<link rel="modulepreload" href="/docs/transformers.js/pr_1665/en/_app/immutable/entry/app.9eafcf9d.js">
<link rel="modulepreload" href="/docs/transformers.js/pr_1665/en/_app/immutable/chunks/preload-helper.4b821645.js">
<link rel="modulepreload" href="/docs/transformers.js/pr_1665/en/_app/immutable/chunks/index.eb3e1f0f.js">
<link rel="modulepreload" href="/docs/transformers.js/pr_1665/en/_app/immutable/nodes/0.d361a553.js">
<link rel="modulepreload" href="/docs/transformers.js/pr_1665/en/_app/immutable/chunks/each.e59479a4.js">
<link rel="modulepreload" href="/docs/transformers.js/pr_1665/en/_app/immutable/nodes/13.caabb023.js">
<link rel="modulepreload" href="/docs/transformers.js/pr_1665/en/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.699f2734.js">
<link rel="modulepreload" href="/docs/transformers.js/pr_1665/en/_app/immutable/chunks/CodeBlock.b303f0b9.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;processors&quot;,&quot;local&quot;:&quot;processors&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;On this page&quot;,&quot;local&quot;:&quot;on-this-page&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Classes&quot;,&quot;local&quot;:&quot;classes&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;FeatureExtractor&quot;,&quot;local&quot;:&quot;featureextractor&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;FeatureExtractor.constructor(config)&quot;,&quot;local&quot;:&quot;featureextractorconstructorconfig&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;FeatureExtractor.from_pretrained(pretrained_model_name_or_path, options)&quot;,&quot;local&quot;:&quot;featureextractorfrompretrainedpretrainedmodelnameorpath-options&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3},{&quot;title&quot;:&quot;ImageProcessor&quot;,&quot;local&quot;:&quot;imageprocessor&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;ImageProcessor(images, args)&quot;,&quot;local&quot;:&quot;imageprocessorimages-args&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.constructor(config)&quot;,&quot;local&quot;:&quot;imageprocessorconstructorconfig&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.thumbnail(image, size, [resample])&quot;,&quot;local&quot;:&quot;imageprocessorthumbnailimage-size-resample&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.crop_margin(image, gray_threshold)&quot;,&quot;local&quot;:&quot;imageprocessorcropmarginimage-graythreshold&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.pad_image(pixelData, imgDims, padSize, options)&quot;,&quot;local&quot;:&quot;imageprocessorpadimagepixeldata-imgdims-padsize-options&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.rescale(pixelData)&quot;,&quot;local&quot;:&quot;imageprocessorrescalepixeldata&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.get_resize_output_image_size(image, size)&quot;,&quot;local&quot;:&quot;imageprocessorgetresizeoutputimagesizeimage-size&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.resize(image)&quot;,&quot;local&quot;:&quot;imageprocessorresizeimage&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.preprocess(image, overrides)&quot;,&quot;local&quot;:&quot;imageprocessorpreprocessimage-overrides&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;ImageProcessor.from_pretrained(pretrained_model_name_or_path, options)&quot;,&quot;local&quot;:&quot;imageprocessorfrompretrainedpretrainedmodelnameorpath-options&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3},{&quot;title&quot;:&quot;AutoFeatureExtractor&quot;,&quot;local&quot;:&quot;autofeatureextractor&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;AutoFeatureExtractor.from_pretrained(pretrained_model_name_or_path, options)&quot;,&quot;local&quot;:&quot;autofeatureextractorfrompretrainedpretrainedmodelnameorpath-options&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3},{&quot;title&quot;:&quot;AutoImageProcessor&quot;,&quot;local&quot;:&quot;autoimageprocessor&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;AutoImageProcessor.from_pretrained(pretrained_model_name_or_path, options)&quot;,&quot;local&quot;:&quot;autoimageprocessorfrompretrainedpretrainedmodelnameorpath-options&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3},{&quot;title&quot;:&quot;AutoProcessor&quot;,&quot;local&quot;:&quot;autoprocessor&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;AutoProcessor.from_pretrained(pretrained_model_name_or_path, options)&quot;,&quot;local&quot;:&quot;autoprocessorfrompretrainedpretrainedmodelnameorpath-options&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Processor&quot;,&quot;local&quot;:&quot;processor&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Processor(input, args)&quot;,&quot;local&quot;:&quot;processorinput-args&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;Processor.constructor(config, components, chat_template)&quot;,&quot;local&quot;:&quot;processorconstructorconfig-components-chattemplate&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;Processor.apply_chat_template(messages, options)&quot;,&quot;local&quot;:&quot;processorapplychattemplatemessages-options&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;Processor.batch_decode(batch, decode_args)&quot;,&quot;local&quot;:&quot;processorbatchdecodebatch-decodeargs&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;Processor.decode(token_ids, [decode_args])&quot;,&quot;local&quot;:&quot;processordecodetokenids-decodeargs&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4},{&quot;title&quot;:&quot;Processor.from_pretrained(pretrained_model_name_or_path, options)&quot;,&quot;local&quot;:&quot;processorfrompretrainedpretrainedmodelnameorpath-options&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Type Definitions&quot;,&quot;local&quot;:&quot;type-definitions&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;HeightWidth&quot;,&quot;local&quot;:&quot;heightwidth&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;ImageProcessorResult&quot;,&quot;local&quot;:&quot;imageprocessorresult&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;ImageProcessorConfig&quot;,&quot;local&quot;:&quot;imageprocessorconfig&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;PreprocessedImage&quot;,&quot;local&quot;:&quot;preprocessedimage&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;ProcessorProperties&quot;,&quot;local&quot;:&quot;processorproperties&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;PretrainedProcessorOptions&quot;,&quot;local&quot;:&quot;pretrainedprocessoroptions&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2}],&quot;depth&quot;:1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg></button></div> </div> <h1 class="relative group"><a id="processors" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#processors"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>processors</span></h1> <p data-svelte-h="svelte-ght87e">Processors turn raw inputs (images, audio, text) into the tensor
shapes a model expects. Pipelines pick the right processor automatically;
call one directly only when you need to preprocess without running
inference.</p> <p data-svelte-h="svelte-9tzqhj">Three <code>Auto*</code> entry points cover the common cases:</p> <ul data-svelte-h="svelte-1dskz5s"><li><code>AutoProcessor</code> — multi-modal (tokenizer + image/audio), e.g. Whisper, CLIP.</li> <li><code>AutoImageProcessor</code> — vision-only models.</li> <li><code>AutoFeatureExtractor</code> — audio-only models.</li></ul> <p data-svelte-h="svelte-n5kq4f"><strong>Example:</strong> Prepare audio for Whisper.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-javascript "><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> { <span class="hljs-title class_">AutoProcessor</span>, load_audio } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@huggingface/transformers&#x27;</span>;
<span class="hljs-keyword">const</span> processor = <span class="hljs-keyword">await</span> <span class="hljs-title class_">AutoProcessor</span>.<span class="hljs-title function_">from_pretrained</span>(<span class="hljs-string">&#x27;onnx-community/whisper-tiny.en&#x27;</span>);
<span class="hljs-keyword">const</span> audio = <span class="hljs-keyword">await</span> <span class="hljs-title function_">load_audio</span>(<span class="hljs-string">&#x27;https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/mlk.flac&#x27;</span>, <span class="hljs-number">16000</span>);
<span class="hljs-keyword">const</span> { input_features } = <span class="hljs-keyword">await</span> <span class="hljs-title function_">processor</span>(audio);
<span class="hljs-comment">// Tensor {</span>
<span class="hljs-comment">// data: Float32Array(240000) [0.4752984642982483, 0.5597258806228638, 0.56434166431427, ...],</span>
<span class="hljs-comment">// dims: [1, 80, 3000],</span>
<span class="hljs-comment">// type: &#x27;float32&#x27;,</span>
<span class="hljs-comment">// size: 240000,</span>
<span class="hljs-comment">// }</span><!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="on-this-page" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#on-this-page"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>On this page</span></h2> <p data-svelte-h="svelte-l1i84"><strong>Classes</strong><a href="#module_processors.FeatureExtractor"><code>FeatureExtractor</code></a> · <a href="#module_processors.ImageProcessor"><code>ImageProcessor</code></a> · <a href="#module_processors.AutoFeatureExtractor"><code>AutoFeatureExtractor</code></a> · <a href="#module_processors.AutoImageProcessor"><code>AutoImageProcessor</code></a> · <a href="#module_processors.AutoProcessor"><code>AutoProcessor</code></a> · <a href="#module_processors.Processor"><code>Processor</code></a></p> <h2 class="relative group"><a id="classes" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#classes"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Classes</span></h2> <a id="module_processors.FeatureExtractor"></a> <h3 class="relative group"><a id="featureextractor" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#featureextractor"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>FeatureExtractor</span></h3> <p data-svelte-h="svelte-1pzzjtd">Base class for audio feature extractors.</p> <a id="module_processors.FeatureExtractor.constructor"></a> <h4 class="relative group"><a id="featureextractorconstructorconfig" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#featureextractorconstructorconfig"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>FeatureExtractor.constructor(config)</span></h4> <p data-svelte-h="svelte-tzonmo">Create a feature extractor from a parsed <code>preprocessor_config.json</code>.</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-1iztbzq"><li><code>config</code> (<code>Object</code>) — The configuration for the feature extractor.</li></ul> <a id="module_processors.FeatureExtractor.from_pretrained"></a> <h4 class="relative group"><a id="featureextractorfrompretrainedpretrainedmodelnameorpath-options" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#featureextractorfrompretrainedpretrainedmodelnameorpath-options"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>FeatureExtractor.from_pretrained(pretrained_model_name_or_path, options)</span></h4> <p data-svelte-h="svelte-1pqhi8n">Instantiate one of the feature extractor classes of the library from a pretrained model.</p> <p data-svelte-h="svelte-1yhrgqg">The feature extractor class to instantiate is selected based on the <code>feature_extractor_type</code> property of
the config object (either passed as an argument or loaded from <code>pretrained_model_name_or_path</code> if possible)</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-1pgtdjr"><li><code>pretrained_model_name_or_path</code> (<code>string</code>) — The name or path of the pretrained model. Can be either:
<ul><li>A string, the <em>model ID</em> of a pretrained feature extractor hosted inside a model repo on huggingface.co.
Valid model IDs can be located at the root level, like <code>bert-base-uncased</code>, or namespaced under a
user or organization name, like <code>dbmdz/bert-base-german-cased</code>.</li> <li>A path to a <em>directory</em> containing feature_extractor files, e.g., <code>./my_model_directory/</code>.</li></ul></li> <li><code>options</code> (<a href="./utils/hub#module_utils/hub.PretrainedOptions"><code>PretrainedOptions</code></a>) — Additional options for loading the feature_extractor.</li></ul> <p data-svelte-h="svelte-z0ii4l"><strong>Returns:</strong> <code>Promise</code>&lt;<a href="./processors#module_processors.FeatureExtractor"><code>FeatureExtractor</code></a>&gt; — A new feature extractor instance.</p> <a id="module_processors.ImageProcessor"></a> <h3 class="relative group"><a id="imageprocessor" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#imageprocessor"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ImageProcessor</span></h3> <p data-svelte-h="svelte-bbplu2">Base class for image processors.</p> <a id="module_processors.ImageProcessor.call"></a> <h4 class="relative group"><a id="imageprocessorimages-args" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#imageprocessorimages-args"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ImageProcessor(images, args)</span></h4> <p data-svelte-h="svelte-1t1x6ef">Preprocess one or more images and batch the result into <code>pixel_values</code>.</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-1vo2ane"><li><code>images</code> (<a href="./utils/image.md#module_utils/image.RawImage"><code>RawImage[]?</code></a>) — The image or images to preprocess.</li> <li><code>args</code> (<code>...any</code>) — Additional arguments.</li></ul> <p data-svelte-h="svelte-1d5ez2d"><strong>Returns:</strong> <code>Promise</code>&lt;<a href="./processors#module_processors.ImageProcessorResult"><code>ImageProcessorResult</code></a>&gt; — An object containing the concatenated pixel values (and other metadata) of the preprocessed images.</p> <a id="module_processors.ImageProcessor.constructor"></a> <h4 class="relative group"><a id="imageprocessorconstructorconfig" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#imageprocessorconstructorconfig"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ImageProcessor.constructor(config)</span></h4> <p data-svelte-h="svelte-mymm9b">Create an image processor from a parsed <code>preprocessor_config.json</code>.</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-zwlywy"><li><code>config</code> (<a href="./processors#module_processors.ImageProcessorConfig"><code>ImageProcessorConfig</code></a>) — The configuration object.</li></ul> <a id="module_processors.ImageProcessor.thumbnail"></a> <h4 class="relative group"><a id="imageprocessorthumbnailimage-size-resample" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#imageprocessorthumbnailimage-size-resample"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ImageProcessor.thumbnail(image, size, [resample])</span></h4> <p data-svelte-h="svelte-1q6eyx4">Resize the image to make a thumbnail. The image is resized so that no dimension is larger than any
corresponding dimension of the specified size.</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-qot73z"><li><code>image</code> (<a href="./utils/image#module_utils/image.RawImage"><code>RawImage</code></a>) — The image to be resized.</li> <li><code>size</code> (<code>{height:number, width:number}</code>) — The size <code>{&quot;height&quot;: h, &quot;width&quot;: w}</code> to resize the image to.</li> <li><code>resample</code> (<code>string</code> | <code>0</code> | <code>1</code> | <code>2</code> | <code>3</code> | <code>4</code> | <code>5</code>) <em>optional</em> — defaults to <code>2</code> — The resampling filter to use.</li></ul> <p data-svelte-h="svelte-m8ap67"><strong>Returns:</strong> <code>Promise</code>&lt;<a href="./utils/image#module_utils/image.RawImage"><code>RawImage</code></a>&gt; — The resized image.</p> <a id="module_processors.ImageProcessor.crop_margin"></a> <h4 class="relative group"><a id="imageprocessorcropmarginimage-graythreshold" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#imageprocessorcropmarginimage-graythreshold"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ImageProcessor.crop_margin(image, gray_threshold)</span></h4> <p data-svelte-h="svelte-7fx89a">Crops the margin of the image. Gray pixels are considered margin (i.e., pixels with a value below the threshold).</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-16tm74b"><li><code>image</code> (<a href="./utils/image#module_utils/image.RawImage"><code>RawImage</code></a>) — The image to be cropped.</li> <li><code>gray_threshold</code> (<code>number</code>) — Value below which pixels are considered to be gray.</li></ul> <p data-svelte-h="svelte-b6jtyk"><strong>Returns:</strong> <code>Promise</code>&lt;<a href="./utils/image#module_utils/image.RawImage"><code>RawImage</code></a>&gt; — The cropped image.</p> <a id="module_processors.ImageProcessor.pad_image"></a> <h4 class="relative group"><a id="imageprocessorpadimagepixeldata-imgdims-padsize-options" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#imageprocessorpadimagepixeldata-imgdims-padsize-options"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ImageProcessor.pad_image(pixelData, imgDims, padSize, options)</span></h4> <p data-svelte-h="svelte-1mmkb9p">Pad the image by a certain amount.</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-1otys4e"><li><code>pixelData</code> (<code>Float32Array</code>) — The pixel data to pad.</li> <li><code>imgDims</code> (<code>number[]</code>) — The dimensions of the image (height, width, channels).</li> <li><code>padSize</code> (<code>{width:number; height:number}</code> | <code>number</code> | <code>&#39;square&#39;</code>) — The dimensions of the padded image.</li> <li><code>options</code> (<code>Object</code>) — The options for padding.
<ul><li><code>mode</code> (<code>&#39;constant&#39;</code> | <code>&#39;symmetric&#39;</code>) <em>optional</em> — defaults to <code>&#39;constant&#39;</code> — The type of padding to add.</li> <li><code>center</code> (<code>boolean</code>) <em>optional</em> — defaults to <code>false</code> — Whether to center the image.</li> <li><code>constant_values</code> (<code>number[]?</code>) <em>optional</em> — defaults to <code>0</code> — The constant value to use for padding.</li></ul></li></ul> <p data-svelte-h="svelte-jk2g0x"><strong>Returns:</strong> [<code>Float32Array</code>, <code>number[]</code>] — The padded pixel data and image dimensions.</p> <a id="module_processors.ImageProcessor.rescale"></a> <h4 class="relative group"><a id="imageprocessorrescalepixeldata" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#imageprocessorrescalepixeldata"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ImageProcessor.rescale(pixelData)</span></h4> <p data-svelte-h="svelte-e0htiw">Rescale the image pixel values by <code>this.rescale_factor</code>.</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-ljugp7"><li><code>pixelData</code> (<code>Float32Array</code>) — The pixel data to rescale.</li></ul> <p data-svelte-h="svelte-hak07j"><strong>Returns:</strong> <code>void</code></p> <a id="module_processors.ImageProcessor.get_resize_output_image_size"></a> <h4 class="relative group"><a id="imageprocessorgetresizeoutputimagesizeimage-size" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#imageprocessorgetresizeoutputimagesizeimage-size"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ImageProcessor.get_resize_output_image_size(image, size)</span></h4> <p data-svelte-h="svelte-8leww2">Find the target (width, height) dimension of the output image after
resizing given the input image and the desired size.</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-z8e3rn"><li><code>image</code> (<a href="./utils/image#module_utils/image.RawImage"><code>RawImage</code></a>) — The image to resize.</li> <li><code>size</code> (<code>any</code>) — The size to use for resizing the image.</li></ul> <p data-svelte-h="svelte-r3jf11"><strong>Returns:</strong> [<code>number</code>, <code>number</code>] — The target (width, height) dimension of the output image after resizing.</p> <a id="module_processors.ImageProcessor.resize"></a> <h4 class="relative group"><a id="imageprocessorresizeimage" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#imageprocessorresizeimage"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ImageProcessor.resize(image)</span></h4> <p data-svelte-h="svelte-5iny39">Resizes the image.</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-v8rpjs"><li><code>image</code> (<a href="./utils/image#module_utils/image.RawImage"><code>RawImage</code></a>) — The image to resize.</li></ul> <p data-svelte-h="svelte-m8ap67"><strong>Returns:</strong> <code>Promise</code>&lt;<a href="./utils/image#module_utils/image.RawImage"><code>RawImage</code></a>&gt; — The resized image.</p> <a id="module_processors.ImageProcessor.preprocess"></a> <h4 class="relative group"><a id="imageprocessorpreprocessimage-overrides" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#imageprocessorpreprocessimage-overrides"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ImageProcessor.preprocess(image, overrides)</span></h4> <p data-svelte-h="svelte-10g8wi9">Preprocesses the given image.</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-1n1axqa"><li><code>image</code> (<a href="./utils/image#module_utils/image.RawImage"><code>RawImage</code></a>) — The image to preprocess.</li> <li><code>overrides</code> (<code>Object</code>) — The overrides for the preprocessing options.</li></ul> <p data-svelte-h="svelte-ogozpg"><strong>Returns:</strong> <code>Promise</code>&lt;<a href="./processors#module_processors.PreprocessedImage"><code>PreprocessedImage</code></a>&gt; — The preprocessed image.</p> <a id="module_processors.ImageProcessor.from_pretrained"></a> <h4 class="relative group"><a id="imageprocessorfrompretrainedpretrainedmodelnameorpath-options" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#imageprocessorfrompretrainedpretrainedmodelnameorpath-options"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ImageProcessor.from_pretrained(pretrained_model_name_or_path, options)</span></h4> <p data-svelte-h="svelte-jwfdp9">Instantiate one of the processor classes of the library from a pretrained model.</p> <p data-svelte-h="svelte-1l7cuz8">The processor class to instantiate is selected based on the <code>image_processor_type</code> (or <code>feature_extractor_type</code>; legacy)
property of the config object (either passed as an argument or loaded from <code>pretrained_model_name_or_path</code> if possible)</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-fsvowo"><li><code>pretrained_model_name_or_path</code> (<code>string</code>) — The name or path of the pretrained model. Can be either:
<ul><li>A string, the <em>model id</em> of a pretrained processor hosted inside a model repo on huggingface.co.
Valid model ids can be located at the root-level, like <code>bert-base-uncased</code>, or namespaced under a
user or organization name, like <code>dbmdz/bert-base-german-cased</code>.</li> <li>A path to a <em>directory</em> containing processor files, e.g., <code>./my_model_directory/</code>.</li></ul></li> <li><code>options</code> (<a href="./utils/hub#module_utils/hub.PretrainedOptions"><code>PretrainedOptions</code></a>) — Additional options for loading the processor.</li></ul> <p data-svelte-h="svelte-1erw2cq"><strong>Returns:</strong> <code>Promise</code>&lt;<a href="./processors#module_processors.ImageProcessor"><code>ImageProcessor</code></a>&gt; — A new image processor instance.</p> <a id="module_processors.AutoFeatureExtractor"></a> <h3 class="relative group"><a id="autofeatureextractor" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#autofeatureextractor"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>AutoFeatureExtractor</span></h3> <p data-svelte-h="svelte-3bd2c">Loads a feature extractor from a pretrained id. The concrete class is
selected from the <code>feature_extractor_type</code> in <code>preprocessor_config.json</code>.
Most commonly used for audio models.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-javascript "><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> { <span class="hljs-title class_">AutoFeatureExtractor</span>, load_audio } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@huggingface/transformers&#x27;</span>;
<span class="hljs-keyword">const</span> extractor = <span class="hljs-keyword">await</span> <span class="hljs-title class_">AutoFeatureExtractor</span>.<span class="hljs-title function_">from_pretrained</span>(<span class="hljs-string">&#x27;onnx-community/whisper-tiny.en&#x27;</span>);
<span class="hljs-keyword">const</span> audio = <span class="hljs-keyword">await</span> <span class="hljs-title function_">load_audio</span>(<span class="hljs-string">&#x27;https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav&#x27;</span>, <span class="hljs-number">16000</span>);
<span class="hljs-keyword">const</span> { input_features } = <span class="hljs-keyword">await</span> <span class="hljs-title function_">extractor</span>(audio);<!-- HTML_TAG_END --></pre></div> <a id="module_processors.AutoFeatureExtractor.from_pretrained"></a> <h4 class="relative group"><a id="autofeatureextractorfrompretrainedpretrainedmodelnameorpath-options" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#autofeatureextractorfrompretrainedpretrainedmodelnameorpath-options"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>AutoFeatureExtractor.from_pretrained(pretrained_model_name_or_path, options)</span></h4> <p data-svelte-h="svelte-1pqhi8n">Instantiate one of the feature extractor classes of the library from a pretrained model.</p> <p data-svelte-h="svelte-1yhrgqg">The feature extractor class to instantiate is selected based on the <code>feature_extractor_type</code> property of
the config object (either passed as an argument or loaded from <code>pretrained_model_name_or_path</code> if possible)</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-1pgtdjr"><li><code>pretrained_model_name_or_path</code> (<code>string</code>) — The name or path of the pretrained model. Can be either:
<ul><li>A string, the <em>model ID</em> of a pretrained feature extractor hosted inside a model repo on huggingface.co.
Valid model IDs can be located at the root level, like <code>bert-base-uncased</code>, or namespaced under a
user or organization name, like <code>dbmdz/bert-base-german-cased</code>.</li> <li>A path to a <em>directory</em> containing feature_extractor files, e.g., <code>./my_model_directory/</code>.</li></ul></li> <li><code>options</code> (<a href="./utils/hub#module_utils/hub.PretrainedOptions"><code>PretrainedOptions</code></a>) — Additional options for loading the feature_extractor.</li></ul> <p data-svelte-h="svelte-z0ii4l"><strong>Returns:</strong> <code>Promise</code>&lt;<a href="./processors#module_processors.FeatureExtractor"><code>FeatureExtractor</code></a>&gt; — A new feature extractor instance.</p> <a id="module_processors.AutoImageProcessor"></a> <h3 class="relative group"><a id="autoimageprocessor" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#autoimageprocessor"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>AutoImageProcessor</span></h3> <p data-svelte-h="svelte-1au4wph">Loads an image processor from a pretrained id. The concrete class is
selected from the <code>image_processor_type</code> in <code>preprocessor_config.json</code>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-javascript "><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> { <span class="hljs-title class_">AutoImageProcessor</span>, load_image } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@huggingface/transformers&#x27;</span>;
<span class="hljs-keyword">const</span> processor = <span class="hljs-keyword">await</span> <span class="hljs-title class_">AutoImageProcessor</span>.<span class="hljs-title function_">from_pretrained</span>(<span class="hljs-string">&#x27;Xenova/clip-vit-base-patch16&#x27;</span>);
<span class="hljs-keyword">const</span> image = <span class="hljs-keyword">await</span> <span class="hljs-title function_">load_image</span>(<span class="hljs-string">&#x27;https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/artemis.jpeg&#x27;</span>);
<span class="hljs-keyword">const</span> { pixel_values } = <span class="hljs-keyword">await</span> <span class="hljs-title function_">processor</span>(image);<!-- HTML_TAG_END --></pre></div> <a id="module_processors.AutoImageProcessor.from_pretrained"></a> <h4 class="relative group"><a id="autoimageprocessorfrompretrainedpretrainedmodelnameorpath-options" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#autoimageprocessorfrompretrainedpretrainedmodelnameorpath-options"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>AutoImageProcessor.from_pretrained(pretrained_model_name_or_path, options)</span></h4> <p data-svelte-h="svelte-jwfdp9">Instantiate one of the processor classes of the library from a pretrained model.</p> <p data-svelte-h="svelte-1l7cuz8">The processor class to instantiate is selected based on the <code>image_processor_type</code> (or <code>feature_extractor_type</code>; legacy)
property of the config object (either passed as an argument or loaded from <code>pretrained_model_name_or_path</code> if possible)</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-fsvowo"><li><code>pretrained_model_name_or_path</code> (<code>string</code>) — The name or path of the pretrained model. Can be either:
<ul><li>A string, the <em>model id</em> of a pretrained processor hosted inside a model repo on huggingface.co.
Valid model ids can be located at the root-level, like <code>bert-base-uncased</code>, or namespaced under a
user or organization name, like <code>dbmdz/bert-base-german-cased</code>.</li> <li>A path to a <em>directory</em> containing processor files, e.g., <code>./my_model_directory/</code>.</li></ul></li> <li><code>options</code> (<a href="./utils/hub#module_utils/hub.PretrainedOptions"><code>PretrainedOptions</code></a>) — Additional options for loading the processor.</li></ul> <p data-svelte-h="svelte-1erw2cq"><strong>Returns:</strong> <code>Promise</code>&lt;<a href="./processors#module_processors.ImageProcessor"><code>ImageProcessor</code></a>&gt; — A new image processor instance.</p> <a id="module_processors.AutoProcessor"></a> <h3 class="relative group"><a id="autoprocessor" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#autoprocessor"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>AutoProcessor</span></h3> <p data-svelte-h="svelte-1u732h3">Loads a processor from a pretrained id. Unlike <code>AutoImageProcessor</code> and
<code>AutoFeatureExtractor</code>, <code>AutoProcessor</code> returns a multi-modal <a href="./processors#module_processors.Processor"><code>Processor</code></a>
that bundles together a tokenizer, image processor, and/or feature extractor
— use it when a single model needs more than one.</p> <p data-svelte-h="svelte-1s81h2t"><strong>Example:</strong> Load a Whisper processor (tokenizer + audio feature extractor).</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-javascript "><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> { <span class="hljs-title class_">AutoProcessor</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@huggingface/transformers&#x27;</span>;
<span class="hljs-keyword">const</span> processor = <span class="hljs-keyword">await</span> <span class="hljs-title class_">AutoProcessor</span>.<span class="hljs-title function_">from_pretrained</span>(<span class="hljs-string">&#x27;onnx-community/whisper-tiny.en&#x27;</span>);<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-e1x17w"><strong>Example:</strong> Run an image through a CLIP processor.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-javascript "><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> { <span class="hljs-title class_">AutoProcessor</span>, load_image } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@huggingface/transformers&#x27;</span>;
<span class="hljs-keyword">const</span> processor = <span class="hljs-keyword">await</span> <span class="hljs-title class_">AutoProcessor</span>.<span class="hljs-title function_">from_pretrained</span>(<span class="hljs-string">&#x27;Xenova/clip-vit-base-patch16&#x27;</span>);
<span class="hljs-keyword">const</span> image = <span class="hljs-keyword">await</span> <span class="hljs-title function_">load_image</span>(<span class="hljs-string">&#x27;https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/football-match.jpg&#x27;</span>);
<span class="hljs-keyword">const</span> { pixel_values } = <span class="hljs-keyword">await</span> <span class="hljs-title function_">processor</span>(image);<!-- HTML_TAG_END --></pre></div> <a id="module_processors.AutoProcessor.from_pretrained"></a> <h4 class="relative group"><a id="autoprocessorfrompretrainedpretrainedmodelnameorpath-options" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#autoprocessorfrompretrainedpretrainedmodelnameorpath-options"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>AutoProcessor.from_pretrained(pretrained_model_name_or_path, options)</span></h4> <p data-svelte-h="svelte-jwfdp9">Instantiate one of the processor classes of the library from a pretrained model.</p> <p data-svelte-h="svelte-1l7cuz8">The processor class to instantiate is selected based on the <code>image_processor_type</code> (or <code>feature_extractor_type</code>; legacy)
property of the config object (either passed as an argument or loaded from <code>pretrained_model_name_or_path</code> if possible)</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-18f58xd"><li><code>pretrained_model_name_or_path</code> (<code>string</code>) — The name or path of the pretrained model. Can be either:
<ul><li>A string, the <em>model ID</em> of a pretrained processor hosted inside a model repo on huggingface.co.
Valid model IDs can be located at the root level, like <code>bert-base-uncased</code>, or namespaced under a
user or organization name, like <code>dbmdz/bert-base-german-cased</code>.</li> <li>A path to a <em>directory</em> containing processor files, e.g., <code>./my_model_directory/</code>.</li></ul></li> <li><code>options</code> (<a href="./processors#module_processors.PretrainedProcessorOptions"><code>PretrainedProcessorOptions</code></a>) — Additional options for loading the processor.</li></ul> <p data-svelte-h="svelte-1vfrkk5"><strong>Returns:</strong> <code>Promise</code>&lt;<a href="./processors#module_processors.Processor"><code>Processor</code></a>&gt; — A new processor instance.</p> <a id="module_processors.Processor"></a> <h3 class="relative group"><a id="processor" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#processor"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Processor</span></h3> <p data-svelte-h="svelte-1ehzo88">Multi-modal preprocessor that delegates to the tokenizer, image processor,
and/or feature extractor required by a model.</p> <a id="module_processors.Processor.call"></a> <h4 class="relative group"><a id="processorinput-args" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#processorinput-args"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Processor(input, args)</span></h4> <p data-svelte-h="svelte-zbbm3j">Calls the feature_extractor function with the given input.</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-ieiehw"><li><code>input</code> (<code>any</code>) — The input to extract features from.</li> <li><code>args</code> (<code>...any</code>) — Additional arguments.</li></ul> <p data-svelte-h="svelte-t2bc0h"><strong>Returns:</strong> <code>Promise</code>&lt;<code>any</code>&gt; — A Promise that resolves with the extracted features.</p> <a id="module_processors.Processor.constructor"></a> <h4 class="relative group"><a id="processorconstructorconfig-components-chattemplate" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#processorconstructorconfig-components-chattemplate"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Processor.constructor(config, components, chat_template)</span></h4> <p data-svelte-h="svelte-14o07fq">Create a processor from parsed config and its component preprocessors.</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-1p3vz7z"><li><code>config</code> (<code>Object</code>) — Processor configuration.</li> <li><code>components</code> (<code>Record</code>&lt;<code>string</code>, <code>Object</code>&gt;) — Loaded tokenizer, image processor, and/or feature extractor.</li> <li><code>chat_template</code> (<code>string</code> | <code>null</code>) — Optional chat template loaded from the model repo.</li></ul> <a id="module_processors.Processor.apply_chat_template"></a> <h4 class="relative group"><a id="processorapplychattemplatemessages-options" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#processorapplychattemplatemessages-options"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Processor.apply_chat_template(messages, options)</span></h4> <p data-svelte-h="svelte-1d7ndh9">Delegates to the underlying tokenizer’s <code>apply_chat_template</code>.</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-1e9uouz"><li><code>messages</code> (<a href="./tokenizers#module_tokenizers.Message"><code>Message</code></a>[])</li> <li><code>options</code> (<a href="./tokenizers#module_tokenizers.ApplyChatTemplateOptions"><code>ApplyChatTemplateOptions</code></a>&lt;<code>TTokenize</code>, <code>TReturnTensor</code>, <code>TReturnDict</code>&gt;)</li></ul> <p data-svelte-h="svelte-13uz7m8"><strong>Returns:</strong> <code>ApplyChatTemplateReturn</code>&lt;<code>TTokenize</code>, <code>TReturnTensor</code>, <code>TReturnDict</code>&gt;</p> <a id="module_processors.Processor.batch_decode"></a> <h4 class="relative group"><a id="processorbatchdecodebatch-decodeargs" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#processorbatchdecodebatch-decodeargs"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Processor.batch_decode(batch, decode_args)</span></h4> <p data-svelte-h="svelte-1mdovz8">Decode a batch of tokenized sequences via the underlying tokenizer.</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-quebp8"><li><code>batch</code> (<code>number[][]</code> | <a href="./utils/tensor#module_utils/tensor.Tensor"><code>Tensor</code></a>) — List/Tensor of tokenized input sequences.</li> <li><code>decode_args</code> (<code>Object</code>) — (Optional) Object with decoding arguments.</li></ul> <p data-svelte-h="svelte-19yfxz6"><strong>Returns:</strong> <code>string[]</code></p> <a id="module_processors.Processor.decode"></a> <h4 class="relative group"><a id="processordecodetokenids-decodeargs" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#processordecodetokenids-decodeargs"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Processor.decode(token_ids, [decode_args])</span></h4> <p data-svelte-h="svelte-182n84i">Decode a single tokenized sequence via the underlying tokenizer.</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-174tohb"><li><code>token_ids</code> (<code>number[]</code> | <code>bigint[]</code> | <a href="./utils/tensor#module_utils/tensor.Tensor"><code>Tensor</code></a>) — List/Tensor of token IDs to decode.</li> <li><code>decode_args</code> (<code>Object</code>) <em>optional</em> — defaults to <code>{}</code> <ul><li><code>skip_special_tokens</code> (<code>boolean</code>) <em>optional</em> — defaults to <code>false</code> — If true, special tokens are removed from the output string.</li> <li><code>clean_up_tokenization_spaces</code> (<code>boolean</code>) <em>optional</em> — defaults to <code>true</code> — If true, spaces before punctuation and abbreviated forms are removed.</li></ul></li></ul> <p data-svelte-h="svelte-1kzuwv6"><strong>Returns:</strong> <code>string</code></p> <a id="module_processors.Processor.from_pretrained"></a> <h4 class="relative group"><a id="processorfrompretrainedpretrainedmodelnameorpath-options" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#processorfrompretrainedpretrainedmodelnameorpath-options"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Processor.from_pretrained(pretrained_model_name_or_path, options)</span></h4> <p data-svelte-h="svelte-jwfdp9">Instantiate one of the processor classes of the library from a pretrained model.</p> <p data-svelte-h="svelte-1l7cuz8">The processor class to instantiate is selected based on the <code>image_processor_type</code> (or <code>feature_extractor_type</code>; legacy)
property of the config object (either passed as an argument or loaded from <code>pretrained_model_name_or_path</code> if possible)</p> <p data-svelte-h="svelte-11fqvcp"><strong>Parameters</strong></p> <ul data-svelte-h="svelte-18f58xd"><li><code>pretrained_model_name_or_path</code> (<code>string</code>) — The name or path of the pretrained model. Can be either:
<ul><li>A string, the <em>model ID</em> of a pretrained processor hosted inside a model repo on huggingface.co.
Valid model IDs can be located at the root level, like <code>bert-base-uncased</code>, or namespaced under a
user or organization name, like <code>dbmdz/bert-base-german-cased</code>.</li> <li>A path to a <em>directory</em> containing processor files, e.g., <code>./my_model_directory/</code>.</li></ul></li> <li><code>options</code> (<a href="./processors#module_processors.PretrainedProcessorOptions"><code>PretrainedProcessorOptions</code></a>) — Additional options for loading the processor.</li></ul> <p data-svelte-h="svelte-1vfrkk5"><strong>Returns:</strong> <code>Promise</code>&lt;<a href="./processors#module_processors.Processor"><code>Processor</code></a>&gt; — A new processor instance.</p> <h2 class="relative group"><a id="type-definitions" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#type-definitions"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Type Definitions</span></h2> <a id="module_processors.HeightWidth"></a> <h3 class="relative group"><a id="heightwidth" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#heightwidth"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>HeightWidth</span></h3> <p data-svelte-h="svelte-vz770h">Named tuple to indicate the order we are using is (height x width),
even though the Graphics’ industry standard is (width x height).</p> <p data-svelte-h="svelte-c4v47a"><em>Type:</em> [<code>height: number</code>, <code>width: number</code>]</p> <a id="module_processors.ImageProcessorResult"></a> <h3 class="relative group"><a id="imageprocessorresult" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#imageprocessorresult"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ImageProcessorResult</span></h3> <p data-svelte-h="svelte-drbxoe"><strong>Properties</strong></p> <ul data-svelte-h="svelte-1kpb484"><li><code>pixel_values</code> (<a href="./utils/tensor#module_utils/tensor.Tensor"><code>Tensor</code></a>) — The pixel values of the batched preprocessed images.</li> <li><code>original_sizes</code> (<a href="./processors#module_processors.HeightWidth"><code>HeightWidth</code></a>[]) — Array of two-dimensional tuples like [[480, 640]].</li> <li><code>reshaped_input_sizes</code> (<a href="./processors#module_processors.HeightWidth"><code>HeightWidth</code></a>[]) — Array of two-dimensional tuples like [[1000, 1330]].</li></ul> <a id="module_processors.ImageProcessorConfig"></a> <h3 class="relative group"><a id="imageprocessorconfig" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#imageprocessorconfig"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ImageProcessorConfig</span></h3> <p data-svelte-h="svelte-rll43y">A configuration object used to create an image processor.</p> <p data-svelte-h="svelte-drbxoe"><strong>Properties</strong></p> <ul data-svelte-h="svelte-kgsyiq"><li><code>progress_callback</code> (<code>function</code>) <em>optional</em> — defaults to <code>null</code> — If specified, this function is called during model construction with progress updates.</li> <li><code>image_mean</code> (<code>number[]</code>) <em>optional</em> — The mean values for image normalization.</li> <li><code>image_std</code> (<code>number[]</code>) <em>optional</em> — The standard deviation values for image normalization.</li> <li><code>do_rescale</code> (<code>boolean</code>) <em>optional</em> — Whether to rescale the image pixel values to the [0,1] range.</li> <li><code>rescale_factor</code> (<code>number</code>) <em>optional</em> — The factor to use for rescaling the image pixel values.</li> <li><code>do_normalize</code> (<code>boolean</code>) <em>optional</em> — Whether to normalize the image pixel values.</li> <li><code>do_resize</code> (<code>boolean</code>) <em>optional</em> — Whether to resize the image.</li> <li><code>resample</code> (<code>number</code>) <em>optional</em> — What method to use for resampling.</li> <li><code>size</code> (<code>number</code> | <code>Object</code>) <em>optional</em> — The size to resize the image to.</li> <li><code>image_size</code> (<code>number</code> | <code>Object</code>) <em>optional</em> — The size to resize the image to (same as <code>size</code>).</li> <li><code>do_flip_channel_order</code> (<code>boolean</code>) <em>optional</em> — defaults to <code>false</code> — Whether to flip the color channels from RGB to BGR.
Can be overridden by the <code>do_flip_channel_order</code> parameter in the <code>preprocess</code> method.</li> <li><code>do_center_crop</code> (<code>boolean</code>) <em>optional</em> — Whether to center crop the image to the specified <code>crop_size</code>.
Can be overridden by <code>do_center_crop</code> in the <code>preprocess</code> method.</li> <li><code>do_thumbnail</code> (<code>boolean</code>) <em>optional</em> — Whether to resize the image using thumbnail method.</li> <li><code>keep_aspect_ratio</code> (<code>boolean</code>) <em>optional</em> — If <code>true</code>, the image is resized to the largest possible size such that the aspect ratio is preserved.
Can be overridden by <code>keep_aspect_ratio</code> in <code>preprocess</code>.</li> <li><code>ensure_multiple_of</code> (<code>number</code>) <em>optional</em> — If <code>do_resize</code> is <code>true</code>, the image is resized to a size that is a multiple of this value.
Can be overridden by <code>ensure_multiple_of</code> in <code>preprocess</code>.</li> <li><code>mean</code> (<code>number[]</code>) <em>optional</em> — The mean values for image normalization (same as <code>image_mean</code>).</li> <li><code>std</code> (<code>number[]</code>) <em>optional</em> — The standard deviation values for image normalization (same as <code>image_std</code>).</li></ul> <a id="module_processors.PreprocessedImage"></a> <h3 class="relative group"><a id="preprocessedimage" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#preprocessedimage"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>PreprocessedImage</span></h3> <p data-svelte-h="svelte-drbxoe"><strong>Properties</strong></p> <ul data-svelte-h="svelte-9tdli7"><li><code>original_size</code> (<a href="./processors#module_processors.HeightWidth"><code>HeightWidth</code></a>) — The original size of the image.</li> <li><code>reshaped_input_size</code> (<a href="./processors#module_processors.HeightWidth"><code>HeightWidth</code></a>) — The reshaped input size of the image.</li> <li><code>pixel_values</code> (<a href="./utils/tensor#module_utils/tensor.Tensor"><code>Tensor</code></a>) — The pixel values of the preprocessed image.</li></ul> <a id="module_processors.ProcessorProperties"></a> <h3 class="relative group"><a id="processorproperties" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#processorproperties"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ProcessorProperties</span></h3> <p data-svelte-h="svelte-ivm759">Additional processor-specific properties.</p> <a id="module_processors.PretrainedProcessorOptions"></a> <h3 class="relative group"><a id="pretrainedprocessoroptions" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#pretrainedprocessoroptions"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>PretrainedProcessorOptions</span></h3> <p data-svelte-h="svelte-1p1l4h9"><em>Type:</em> <a href="./utils/hub#module_utils/hub.PretrainedOptions"><code>PretrainedOptions</code></a> &amp; <a href="./processors#module_processors.ProcessorProperties"><code>ProcessorProperties</code></a></p> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/transformers.js/blob/main/packages/transformers/docs/source/api/processors.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg> <span data-svelte-h="svelte-zjs2n5"><span class="underline">Update</span> on GitHub</span></a> <p></p>
<script>
{
__sveltekit_1t06csc = {
assets: "/docs/transformers.js/pr_1665/en",
base: "/docs/transformers.js/pr_1665/en",
env: {}
};
const element = document.currentScript.parentElement;
const data = [null,null];
Promise.all([
import("/docs/transformers.js/pr_1665/en/_app/immutable/entry/start.cb58eb6f.js"),
import("/docs/transformers.js/pr_1665/en/_app/immutable/entry/app.9eafcf9d.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 13],
data,
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
98 kB
·
Xet hash:
2ad6e9f0c396ba802daa51b59fdf3cbf5a900c4e37e2a275d19fc6668dfeb69e

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.