Buckets:

download
raw
84.7 kB
import"../chunks/DsnmJJEf.js";import{i as we,h as je,C as Ve,H as t,a as i,D as o,E as Ze,s as Ce}from"../chunks/CN3cOuQA.js";import{p as Ee,o as ke,s as e,f as ne,a as V,b as We,c as n,d as Z,n as s,r as a}from"../chunks/DdiSzEty.js";import{E as Ie}from"../chunks/BpTh2jDR.js";const ze='{"title":"EdgeTAMVideo","local":"edgetamvideo","sections":[{"title":"Overview","local":"overview","sections":[],"depth":2},{"title":"Usage example","local":"usage-example","sections":[{"title":"Video Segmentation and Tracking","local":"video-segmentation-and-tracking","sections":[{"title":"Basic Video Tracking","local":"basic-video-tracking","sections":[],"depth":4},{"title":"Multi-Object Video Tracking","local":"multi-object-video-tracking","sections":[],"depth":4},{"title":"Refining Video Segmentation","local":"refining-video-segmentation","sections":[],"depth":4}],"depth":3},{"title":"Streaming Video Inference","local":"streaming-video-inference","sections":[{"title":"Video Batch Processing for Multiple Objects","local":"video-batch-processing-for-multiple-objects","sections":[],"depth":4}],"depth":3}],"depth":2},{"title":"EdgeTamVideoMaskDecoderConfig","local":"transformers.EdgeTamVideoMaskDecoderConfig","sections":[],"depth":2},{"title":"EdgeTamVideoPromptEncoderConfig","local":"transformers.EdgeTamVideoPromptEncoderConfig","sections":[],"depth":2},{"title":"EdgeTamVideoConfig","local":"transformers.EdgeTamVideoConfig","sections":[],"depth":2},{"title":"EdgeTamVideoInferenceSession","local":"transformers.EdgeTamVideoInferenceSession","sections":[],"depth":2},{"title":"EdgeTamVideoModel","local":"transformers.EdgeTamVideoModel","sections":[],"depth":2}],"depth":1}';var Ne=Z('<meta name="hf:doc:metadata"/>'),Be=Z("<p>Example:</p> <!>",1),Re=Z(`<p></p> <p><em>This model was published in HF papers on 2025-01-13 and contributed to Hugging Face Transformers on 2025-09-29.</em></p> <!> <div style="float: right;"><div class="flex flex-wrap space-x-1"><img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&amp;logo=pytorch&amp;logoColor=white"/> <img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat"/></div></div> <!> <!> <p>The EdgeTAM model was proposed in <a href="https://huggingface.co/papers/2501.07256" rel="nofollow">EdgeTAM: On-Device Track Anything Model</a> Chong Zhou, Chenchen Zhu, Yunyang Xiong, Saksham Suri, Fanyi Xiao, Lemeng Wu, Raghuraman Krishnamoorthi, Bo Dai, Chen Change Loy, Vikas Chandra, Bilge Soran.</p> <p>EdgeTAM is an efficient adaptation of SAM 2 that introduces a 2D Spatial Perceiver architecture to optimize memory attention mechanisms for real-time video segmentation on mobile devices.</p> <p>The abstract from the paper is the following:</p> <p><em>On top of Segment Anything Model (SAM), SAM 2 further extends its capability from image to video inputs through a memory bank mechanism and obtains a remarkable performance compared with previous methods, making it a foundation model for video segmentation task. In this paper, we aim at making SAM 2 much more efficient so that it even runs on mobile devices while maintaining a comparable performance. Despite several works optimizing SAM for better efficiency, we find they are not sufficient for SAM 2 because they all focus on compressing the image encoder, while our benchmark shows that the newly introduced memory attention blocks are also the latency bottleneck. Given this observation, we propose EdgeTAM, which leverages a novel 2D Spatial Perceiver to reduce the computational cost. In particular, the proposed 2D Spatial Perceiver encodes the densely stored frame-level memories with a lightweight Transformer that contains a fixed set of learnable queries. Given that video segmentation is a dense prediction task, we find preserving the spatial structure of the memories is essential so that the queries are split into global-level and patch-level groups. We also propose a distillation pipeline that further improves the performance without inference overhead. As a result, EdgeTAM achieves 87.7, 70.0, 72.3, and 71.7 J&F on DAVIS 2017, MOSE, SA-V val, and SA-V test, while running at 16 FPS on iPhone 15 Pro Max.</em></p> <p>This model was contributed by <a href="https://huggingface.co/yonigozlan" rel="nofollow">yonigozlan</a>.
The original code can be found <a href="https://github.com/facebookresearch/EdgeTAM" rel="nofollow">here</a>.</p> <!> <!> <p>EdgeTAM Video’s key strength is its ability to track objects across video frames efficiently on mobile devices. Here’s how to use it for video segmentation:</p> <!> <!> <!> <p>Track multiple objects simultaneously across video frames:</p> <!> <!> <p>You can add additional clicks on any frame to refine the tracking:</p> <!> <!> <p>For real-time applications, EdgeTAM Video supports processing video frames as they arrive:</p> <!> <!> <p>Track multiple objects simultaneously in video by adding them all at once:</p> <!> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>This is the configuration class to store the configuration of a EdgeTamVideoModel. It is used to instantiate a Edgetam Video
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configuration to that of the <a href="https://huggingface.co/yonigozlan/EdgeTAM-hf" rel="nofollow">yonigozlan/EdgeTAM-hf</a></p> <p>Configuration objects inherit from <a href="/docs/transformers/pr_51549/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> and can be used to control the model outputs. Read the
documentation from <a href="/docs/transformers/pr_51549/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> for more information.</p></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>This is the configuration class to store the configuration of a EdgeTamVideoModel. It is used to instantiate a Edgetam Video
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configuration to that of the <a href="https://huggingface.co/yonigozlan/EdgeTAM-hf" rel="nofollow">yonigozlan/EdgeTAM-hf</a></p> <p>Configuration objects inherit from <a href="/docs/transformers/pr_51549/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> and can be used to control the model outputs. Read the
documentation from <a href="/docs/transformers/pr_51549/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> for more information.</p></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>This is the configuration class to store the configuration of a EdgeTamVideoModel. It is used to instantiate a Edgetam Video
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configuration to that of the <a href="https://huggingface.co/yonigozlan/EdgeTAM-hf" rel="nofollow">yonigozlan/EdgeTAM-hf</a></p> <p>Configuration objects inherit from <a href="/docs/transformers/pr_51549/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> and can be used to control the model outputs. Read the
documentation from <a href="/docs/transformers/pr_51549/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> for more information.</p> <!></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Manages video inference session parameters, state and cache.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Add mask inputs with automatic device placement.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Add new frame with automatic device placement.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Add point inputs with automatic device placement.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Get frame from video.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Get the total number of unique object ids received so far in this session.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Get output with smart device management.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Map object ID to index, creating new entry if needed.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Map model-side object index to client-side object id.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Remove mask inputs.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Remove point inputs.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Reset tracking data and cache.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Reset tracking data but keep cache.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Store output with smart device management.
If output_key is None, the output is stored as a dictionary.</p></div></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The bare Edgetam Video Model outputting raw hidden-states without any specific head on top.</p> <p>This model inherits from <a href="/docs/transformers/pr_51549/en/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)</p> <p>This model is also a PyTorch <a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module" rel="nofollow">torch.nn.Module</a> subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Propagate the objects through a streamed video frame.</p> <ul><li><strong>object_ids</strong> (<code>list[int]</code>, <em>optional</em>) — List of object IDs being tracked in the current frame.</li> <li><strong>pred_masks</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, num_masks, height, width)</code>) — The predicted masks stored at the model’s resolution.</li> <li><strong>object_score_logits</strong> (<code>torch.Tensor</code> of shape <code>(batch_size,)</code>, <em>optional</em>) — Logits for the object scores, indicating if objects are present.</li> <li><strong>frame_idx</strong> (<code>int</code>, <em>optional</em>) — The frame index of the video.</li></ul></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <ul><li><p><strong>last_hidden_state</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, height, width, hidden_size)</code>) — Sequence of hidden-states at the output of the last layer of the model.</p></li> <li><p><strong>pooler_output</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, hidden_size)</code>) — Last layer hidden-state of the first token of the sequence (classification token) after further processing
through the layers used for the auxiliary pretraining task. E.g. for BERT-family of models, this returns
the classification token after processing through a linear layer and a tanh activation function. The linear
layer weights are trained from the next sentence prediction (classification) objective during pretraining.</p></li> <li><p><strong>hidden_states</strong> (<code>tuple(torch.Tensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>torch.Tensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p> <p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p></li> <li><p><strong>attentions</strong> (<code>tuple(torch.Tensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>torch.Tensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p> <p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
heads.</p></li> <li><p><strong>fpn_hidden_states</strong> (<code>tuple(torch.Tensor)</code>) — Tuple of <code>torch.Tensor</code> (one for each feature level, from high to low resolution) of shape <code>(batch_size, hidden_size, height, width)</code>. Feature maps from the Feature Pyramid Network neck.</p></li> <li><p><strong>fpn_position_encoding</strong> (<code>tuple(torch.Tensor)</code>) — Tuple of <code>torch.Tensor</code> (one for each feature level, from high to low resolution) of shape <code>(batch_size, hidden_size, height, width)</code>. Positional encodings corresponding to the <code>fpn_hidden_states</code>.</p></li></ul></div></div> <!> <p></p>`,1);function Ye(ae,se){Ee(se,!1),ke(()=>{new URLSearchParams(window.location.search).get("fw")}),we();var C=Re();je("vgud6p",r=>{var j=Ne();Ce(j,"content",ze),V(r,j)});var E=e(ne(C),4);Ve(E,{containerStyle:"float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"});var k=e(E,4);t(k,{title:"EdgeTAMVideo",local:"edgetamvideo",headingTag:"h1"});var W=e(k,2);t(W,{title:"Overview",local:"overview",headingTag:"h2"});var I=e(W,12);t(I,{title:"Usage example",local:"usage-example",headingTag:"h2"});var z=e(I,2);t(z,{title:"Video Segmentation and Tracking",local:"video-segmentation-and-tracking",headingTag:"h3"});var N=e(z,4);t(N,{title:"Basic Video Tracking",local:"basic-video-tracking",headingTag:"h4"});var B=e(N,2);i(B,{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEVkZ2VUYW1WaWRlb01vZGVsJTJDJTIwU2FtMlZpZGVvUHJvY2Vzc29yJTBBaW1wb3J0JTIwdG9yY2glMEElMEFtb2RlbCUyMCUzRCUyMEVkZ2VUYW1WaWRlb01vZGVsLmZyb21fcHJldHJhaW5lZCglMjJ5b25pZ296bGFuJTJGZWRnZXRhbS12aWRlby0xJTIyJTJDJTIwZGV2aWNlX21hcCUzRCUyMmF1dG8lMjIpJTBBcHJvY2Vzc29yJTIwJTNEJTIwU2FtMlZpZGVvUHJvY2Vzc29yLmZyb21fcHJldHJhaW5lZCglMjJ5b25pZ296bGFuJTJGZWRnZXRhbS12aWRlby0xJTIyKSUwQSUwQSUyMyUyMExvYWQlMjB2aWRlbyUyMGZyYW1lcyUyMChleGFtcGxlJTIwYXNzdW1lcyUyMHlvdSUyMGhhdmUlMjBhJTIwbGlzdCUyMG9mJTIwUElMJTIwSW1hZ2VzKSUwQSUyMyUyMHZpZGVvX2ZyYW1lcyUyMCUzRCUyMCU1QkltYWdlLm9wZW4oZiUyMmZyYW1lXyU3QmklM0EwNWQlN0QuanBnJTIyKSUyMGZvciUyMGklMjBpbiUyMHJhbmdlKG51bV9mcmFtZXMpJTVEJTBBJTBBJ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B0aHJvdWdoJTIwdGhlJTIwZW50aXJlJTIwdmlkZW8lMEF2aWRlb19zZWdtZW50cyUyMCUzRCUyMCU3QiU3RCUwQWZvciUyMHNhbTJfdmlkZW9fb3V0cHV0JTIwaW4lMjBtb2RlbC5wcm9wYWdhdGVfaW5fdmlkZW9faXRlcmF0b3IoaW5mZXJlbmNlX3Nlc3Npb24pJTNBJTBBJTIwJTIwJTIwJTIwdmlkZW9fcmVzX21hc2tzJTIwJTNEJTIwcHJvY2Vzc29yLnBvc3RfcHJvY2Vzc19tYXNrcyglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlNUJzYW0yX3ZpZGVvX291dHB1dC5wcmVkX21hc2tzJTVEJTJDJTIwb3JpZ2luYWxfc2l6ZXMlM0QlNUIlNUJpbmZlcmVuY2Vfc2Vzc2lvbi52aWRlb19oZWlnaHQlMkMlMjBpbmZlcmVuY2Vfc2Vzc2lvbi52aWRlb193aWR0aCU1RCU1RCUyQyUyMGJpbmFyaXplJTNERmFsc2UlMEElMjAlMjAlMjAlMjApJTVCMCU1RCUwQSUyMCUyMCUyMCUyMHZpZGVvX3NlZ21lbnRzJTVCc2FtMl92aWRlb19vdXRwdXQuZnJhbWVfaWR4JTVEJTIwJTNEJTIwdmlkZW9fcmVzX21hc2tzJTBBJTBBcHJpbnQoZiUyMlRyYWNrZWQlMjBvYmplY3QlMjB0aHJvdWdoJTIwJTdCbGVuKHZpZGVvX3NlZ21lbnRzKSU3RCUyMGZyYW1lcyUyMiklMEFUcmFja2VkJTIwb2JqZWN0JTIwdGhyb3VnaCUyMDIwMCUyMGZyYW1lcw==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> EdgeTamVideoModel, Sam2VideoProcessor
<span class="hljs-keyword">import</span> torch
model = EdgeTamVideoModel.from_pretrained(<span class="hljs-string">&quot;yonigozlan/edgetam-video-1&quot;</span>, device_map=<span class="hljs-string">&quot;auto&quot;</span>)
processor = Sam2VideoProcessor.from_pretrained(<span class="hljs-string">&quot;yonigozlan/edgetam-video-1&quot;</span>)
<span class="hljs-comment"># Load video frames (example assumes you have a list of PIL Images)</span>
<span class="hljs-comment"># video_frames = [Image.open(f&quot;frame_{i:05d}.jpg&quot;) for i in range(num_frames)]</span>
<span class="hljs-comment"># For this example, we&#x27;ll use the video loading utility</span>
<span class="hljs-keyword">from</span> transformers.video_utils <span class="hljs-keyword">import</span> load_video
video_url = <span class="hljs-string">&quot;https://huggingface.co/datasets/hf-internal-testing/sam2-fixtures/resolve/main/bedroom.mp4&quot;</span>
video_frames, _ = load_video(video_url)
<span class="hljs-comment"># Initialize video inference session</span>
inference_session = processor.init_video_session(
video=video_frames,
inference_device=device,
)
<span class="hljs-comment"># Add click on first frame to select object</span>
ann_frame_idx = <span class="hljs-number">0</span>
ann_obj_id = <span class="hljs-number">1</span>
points = [[[[<span class="hljs-number">210</span>, <span class="hljs-number">350</span>]]]]
labels = [[[<span class="hljs-number">1</span>]]]
processor.add_inputs_to_inference_session(
inference_session=inference_session,
frame_idx=ann_frame_idx,
obj_ids=ann_obj_id,
input_points=points,
input_labels=labels,
)
<span class="hljs-comment"># Segment the object on the first frame</span>
outputs = model(
inference_session=inference_session,
frame_idx=ann_frame_idx,
)
video_res_masks = processor.post_process_masks(
[outputs.pred_masks], original_sizes=[[inference_session.video_height, inference_session.video_width]], binarize=<span class="hljs-literal">False</span>
)[<span class="hljs-number">0</span>]
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Segmentation shape: <span class="hljs-subst">{video_res_masks.shape}</span>&quot;</span>)
Segmentation shape: torch.Size([<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">540</span>, <span class="hljs-number">960</span>])
<span class="hljs-comment"># Propagate through the entire video</span>
video_segments = {}
<span class="hljs-keyword">for</span> sam2_video_output <span class="hljs-keyword">in</span> model.propagate_in_video_iterator(inference_session):
video_res_masks = processor.post_process_masks(
[sam2_video_output.pred_masks], original_sizes=[[inference_session.video_height, inference_session.video_width]], binarize=<span class="hljs-literal">False</span>
)[<span class="hljs-number">0</span>]
video_segments[sam2_video_output.frame_idx] = video_res_masks
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Tracked object through <span class="hljs-subst">{<span class="hljs-built_in">len</span>(video_segments)}</span> frames&quot;</span>)
Tracked <span class="hljs-built_in">object</span> through <span class="hljs-number">200</span> frames`,lang:"python",wrap:!1});var R=e(B,2);t(R,{title:"Multi-Object Video Tracking",local:"multi-object-video-tracking",headingTag:"h4"});var x=e(R,4);i(x,{code:"JTIzJTIwUmVzZXQlMjBmb3IlMjBuZXclMjB0cmFja2luZyUyMHNlc3Npb24lMEFpbmZlcmVuY2Vfc2Vzc2lvbi5yZXNldF9pbmZlcmVuY2Vfc2Vzc2lvbigpJTBBJTBBJTIzJTIwQWRkJTIwbXVsdGlwbGUlMjBvYmplY3RzJTIwb24lMjB0aGUlMjBmaXJzdCUyMGZyYW1lJTBBYW5uX2ZyYW1lX2lkeCUyMCUzRCUyMDAlMEFvYmpfaWRzJTIwJTNEJTIwJTVCMiUyQyUyMDMlNUQlMEFpbnB1dF9wb2ludHMlMjAlM0QlMjAlNUIlNUIlNUIlNUIyMDAlMkMlMjAzMDAlNUQlNUQlMkMlMjAlNUIlNUI0MDAlMkMlMjAxNTAlNUQlNUQlNUQlNUQlMjAlMjAlMjMlMjBQb2ludHMlMjBmb3IlMjB0d28lMjBvYmplY3RzJTIwKGJhdGNoZWQpJTBBaW5wdXRfbGFiZWxzJTIwJTNEJTIwJTVCJTVCJTVCMSU1RCUyQyUyMCU1QjElNUQlNUQlNUQlMEElMEFwcm9jZXNzb3IuYWRkX2lucHV0c190b19pbmZlcmVuY2Vfc2Vzc2lvbiglMEElMjAlMjAlMjAlMjBpbmZlcmVuY2Vfc2Vzc2lvbiUzRGluZmVyZW5jZV9zZXNzaW9uJTJDJTBBJTIwJTIwJTIwJTIwZnJhbWVfaWR4JTNEYW5uX2ZyYW1lX2lkeCUyQyUwQSUyMC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HZpZGVvX3NlZ21lbnRzJTVCc2FtMl92aWRlb19vdXRwdXQuZnJhbWVfaWR4JTVEJTIwJTNEJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwb2JqX2lkJTNBJTIwdmlkZW9fcmVzX21hc2tzJTVCaSU1RCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZvciUyMGklMkMlMjBvYmpfaWQlMjBpbiUyMGVudW1lcmF0ZShpbmZlcmVuY2Vfc2Vzc2lvbi5vYmpfaWRzKSUwQSUyMCUyMCUyMCUyMCU3RCUwQSUwQXByaW50KGYlMjJUcmFja2VkJTIwJTdCbGVuKGluZmVyZW5jZV9zZXNzaW9uLm9ial9pZHMpJTdEJTIwb2JqZWN0cyUyMHRocm91Z2glMjAlN0JsZW4odmlkZW9fc2VnbWVudHMpJTdEJTIwZnJhbWVzJTIyKSUwQVRyYWNrZWQlMjAyJTIwb2JqZWN0cyUyMHRocm91Z2glMjAyMDAlMjBmcmFtZXM=",highlighted:`<span class="hljs-comment"># Reset for new tracking session</span>
inference_session.reset_inference_session()
<span class="hljs-comment"># Add multiple objects on the first frame</span>
ann_frame_idx = <span class="hljs-number">0</span>
obj_ids = [<span class="hljs-number">2</span>, <span class="hljs-number">3</span>]
input_points = [[[[<span class="hljs-number">200</span>, <span class="hljs-number">300</span>]], [[<span class="hljs-number">400</span>, <span class="hljs-number">150</span>]]]] <span class="hljs-comment"># Points for two objects (batched)</span>
input_labels = [[[<span class="hljs-number">1</span>], [<span class="hljs-number">1</span>]]]
processor.add_inputs_to_inference_session(
inference_session=inference_session,
frame_idx=ann_frame_idx,
obj_ids=obj_ids,
input_points=input_points,
input_labels=input_labels,
)
<span class="hljs-comment"># Get masks for both objects on first frame</span>
outputs = model(
inference_session=inference_session,
frame_idx=ann_frame_idx,
)
<span class="hljs-comment"># Propagate both objects through video</span>
video_segments = {}
<span class="hljs-keyword">for</span> sam2_video_output <span class="hljs-keyword">in</span> model.propagate_in_video_iterator(inference_session):
video_res_masks = processor.post_process_masks(
[sam2_video_output.pred_masks], original_sizes=[[inference_session.video_height, inference_session.video_width]], binarize=<span class="hljs-literal">False</span>
)[<span class="hljs-number">0</span>]
video_segments[sam2_video_output.frame_idx] = {
obj_id: video_res_masks[i]
<span class="hljs-keyword">for</span> i, obj_id <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(inference_session.obj_ids)
}
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Tracked <span class="hljs-subst">{<span class="hljs-built_in">len</span>(inference_session.obj_ids)}</span> objects through <span class="hljs-subst">{<span class="hljs-built_in">len</span>(video_segments)}</span> frames&quot;</span>)
Tracked <span class="hljs-number">2</span> objects through <span class="hljs-number">200</span> frames`,lang:"python",wrap:!1});var X=e(x,2);t(X,{title:"Refining Video Segmentation",local:"refining-video-segmentation",headingTag:"h4"});var G=e(X,4);i(G,{code:"JTIzJTIwQWRkJTIwcmVmaW5lbWVudCUyMGNsaWNrJTIwb24lMjBhJTIwbGF0ZXIlMjBmcmFtZSUwQXJlZmluZV9mcmFtZV9pZHglMjAlM0QlMjA1MCUwQWFubl9vYmpfaWQlMjAlM0QlMjAyJTIwJTIwJTIzJTIwUmVmaW5pbmclMjBmaXJzdCUyMG9iamVjdCUwQXBvaW50cyUyMCUzRCUyMCU1QiU1QiU1QiU1QjIyMCUyQyUyMDI4MCU1RCU1RCU1RCU1RCUyMCUyMCUyMyUyMEFkZGl0aW9uYWwlMjBwb2ludCUwQWxhYmVscyUyMCUzRCUyMCU1QiU1QiU1QjElNUQlNUQlNUQlMjAlMjAlMjMlMjBQb3NpdGl2ZSUyMGNsaWNrJTBBJTBBcHJvY2Vzc29yLmFkZF9pbnB1dHNfdG9faW5mZXJlbmNlX3Nlc3Npb24oJTBBJTIwJTIwJTIwJTIwaW5mZXJlbmNlX3Nlc3Npb24lM0RpbmZlcmVuY2Vfc2Vzc2lvbiUyQyUwQSUyMCUyMCUyMCUyMGZyYW1lX2lkeCUzRHJlZmluZV9mcmFtZV9pZHglMkMlMEElMjAlMjAlMjAlMjBvYmpfaWRzJTNEYW5uX29ial9pZCUyQyUwQSUyMCUyMCUyMCUyMGlucHV0X3BvaW50cyUzRHBvaW50cyUyQyUwQSUyMCUyMCUyMCUyMGlucHV0X2xhYmVscyUzRGxhYmVscyUyQyUwQSklMEElMEElMjMlMjBSZS1wcm9wYWdhdGUlMjB3aXRoJTIwdGhlJTIwYWRkaXRpb25hbCUyMGluZm9ybWF0aW9uJTBBdmlkZW9fc2VnbWVudHMlMjAlM0QlMjAlN0IlN0QlMEFmb3IlMjBzYW0yX3ZpZGVvX291dHB1dCUyMGluJTIwbW9kZWwucHJvcGFnYXRlX2luX3ZpZGVvX2l0ZXJhdG9yKGluZmVyZW5jZV9zZXNzaW9uKSUzQSUwQSUyMCUyMCUyMCUyMHZpZGVvX3Jlc19tYXNrcyUyMCUzRCUyMHByb2Nlc3Nvci5wb3N0X3Byb2Nlc3NfbWFza3MoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTVCc2FtMl92aWRlb19vdXRwdXQucHJlZF9tYXNrcyU1RCUyQyUyMG9yaWdpbmFsX3NpemVzJTNEJTVCJTVCaW5mZXJlbmNlX3Nlc3Npb24udmlkZW9faGVpZ2h0JTJDJTIwaW5mZXJlbmNlX3Nlc3Npb24udmlkZW9fd2lkdGglNUQlNUQlMkMlMjBiaW5hcml6ZSUzREZhbHNlJTBBJTIwJTIwJTIwJTIwKSU1QjAlNUQlMEElMjAlMjAlMjAlMjB2aWRlb19zZWdtZW50cyU1QnNhbTJfdmlkZW9fb3V0cHV0LmZyYW1lX2lkeCU1RCUyMCUzRCUyMHZpZGVvX3Jlc19tYXNrcw==",highlighted:`<span class="hljs-comment"># Add refinement click on a later frame</span>
refine_frame_idx = <span class="hljs-number">50</span>
ann_obj_id = <span class="hljs-number">2</span> <span class="hljs-comment"># Refining first object</span>
points = [[[[<span class="hljs-number">220</span>, <span class="hljs-number">280</span>]]]] <span class="hljs-comment"># Additional point</span>
labels = [[[<span class="hljs-number">1</span>]]] <span class="hljs-comment"># Positive click</span>
processor.add_inputs_to_inference_session(
inference_session=inference_session,
frame_idx=refine_frame_idx,
obj_ids=ann_obj_id,
input_points=points,
input_labels=labels,
)
<span class="hljs-comment"># Re-propagate with the additional information</span>
video_segments = {}
<span class="hljs-keyword">for</span> sam2_video_output <span class="hljs-keyword">in</span> model.propagate_in_video_iterator(inference_session):
video_res_masks = processor.post_process_masks(
[sam2_video_output.pred_masks], original_sizes=[[inference_session.video_height, inference_session.video_width]], binarize=<span class="hljs-literal">False</span>
)[<span class="hljs-number">0</span>]
video_segments[sam2_video_output.frame_idx] = video_res_masks`,lang:"python",wrap:!1});var Q=e(G,2);t(Q,{title:"Streaming Video Inference",local:"streaming-video-inference",headingTag:"h3"});var Y=e(Q,4);i(Y,{code:"JTBB",highlighted:`<span class="hljs-comment"># Initialize session for streaming</span>
inference_session = processor.init_video_session(
inference_device=device,
)
<span class="hljs-comment"># Process frames one by one</span>
<span class="hljs-keyword">for</span> frame_idx, frame <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(video_frames[:<span class="hljs-number">10</span>]): <span class="hljs-comment"># Process first 10 frames</span>
inputs = processor(images=frame, device=device, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(model.device)
...
<span class="hljs-keyword">if</span> frame_idx == <span class="hljs-number">0</span>:
<span class="hljs-comment"># Add point input on first frame</span>
processor.add_inputs_to_inference_session(
inference_session=inference_session,
frame_idx=<span class="hljs-number">0</span>,
obj_ids=<span class="hljs-number">1</span>,
input_points=[[[[<span class="hljs-number">210</span>, <span class="hljs-number">350</span>], [<span class="hljs-number">250</span>, <span class="hljs-number">220</span>]]]],
input_labels=[[[<span class="hljs-number">1</span>, <span class="hljs-number">1</span>]]],
original_size=inputs.original_sizes[<span class="hljs-number">0</span>], <span class="hljs-comment"># need to be provided when using streaming video inference</span>
)
...
<span class="hljs-comment"># Process current frame</span>
sam2_video_output = model(inference_session=inference_session, frame=inputs.pixel_values[<span class="hljs-number">0</span>])
...
video_res_masks = processor.post_process_masks(
[sam2_video_output.pred_masks], original_sizes=inputs.original_sizes, binarize=<span class="hljs-literal">False</span>
)[<span class="hljs-number">0</span>]
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Frame <span class="hljs-subst">{frame_idx}</span>: mask shape <span class="hljs-subst">{video_res_masks.shape}</span>&quot;</span>)
Frame <span class="hljs-number">0</span>: mask shape torch.Size([<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">540</span>, <span class="hljs-number">960</span>])
...`,lang:"python",wrap:!1});var S=e(Y,2);t(S,{title:"Video Batch Processing for Multiple Objects",local:"video-batch-processing-for-multiple-objects",headingTag:"h4"});var A=e(S,4);i(A,{code:"JTIzJTIwSW5pdGlhbGl6ZSUyMHZpZGVvJTIwc2Vzc2lvbiUwQWluZmVyZW5jZV9zZXNzaW9uJTIwJTNEJTIwcHJvY2Vzc29yLmluaXRfdmlkZW9fc2Vzc2lvbiglMEElMjAlMjAlMjAlMjB2aWRlbyUzRHZpZGVvX2ZyYW1lcyUyQyUwQSUyMCUyMCUyMCUyMGluZmVyZW5jZV9kZXZpY2UlM0RkZXZpY2UlMkMlMEEpJTBBJTBBJTIzJTIwQWRkJTIwbXVsdGlwbGUlMjBvYmplY3RzJTIwb24lMjB0aGUlMjBmaXJzdCUyMGZyYW1lJTIwdXNpbmclMjBiYXRjaCUyMHByb2Nlc3NpbmclMEFhbm5fZnJhbWVfaWR4JTIwJTNEJTIwMCUwQW9ial9pZHMlMjAlM0QlMjAlNUIyJTJDJTIwMyU1RCUyMCUyMCUyMyUyMFRyYWNrJTIwdHdvJTIwZGlmZmVyZW50JTIwb2JqZWN0cyUwQWlucHV0X3BvaW50cyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCU1QiU1QiU1QjIwMCUyQyUyMDMwMCU1RCUyQyUyMCU1QjIzMCUyQyUyMDI1MCU1R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W9uLnZpZGVvX3dpZHRoJTVEJTVEJTJDJTIwYmluYXJpemUlM0RGYWxzZSUwQSUyMCUyMCUyMCUyMCklNUIwJTVEJTBBJTIwJTIwJTIwJTIwdmlkZW9fc2VnbWVudHMlNUJzYW0yX3ZpZGVvX291dHB1dC5mcmFtZV9pZHglNUQlMjAlM0QlMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBvYmpfaWQlM0ElMjB2aWRlb19yZXNfbWFza3MlNUJpJTVEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZm9yJTIwaSUyQyUyMG9ial9pZCUyMGluJTIwZW51bWVyYXRlKGluZmVyZW5jZV9zZXNzaW9uLm9ial9pZHMpJTBBJTIwJTIwJTIwJTIwJTdEJTBBJTBBcHJpbnQoZiUyMlRyYWNrZWQlMjAlN0JsZW4oaW5mZXJlbmNlX3Nlc3Npb24ub2JqX2lkcyklN0QlMjBvYmplY3RzJTIwdGhyb3VnaCUyMCU3Qmxlbih2aWRlb19zZWdtZW50cyklN0QlMjBmcmFtZXMlMjIpJTBBVHJhY2tlZCUyMDIlMjBvYmplY3RzJTIwdGhyb3VnaCUyMDIwMCUyMGZyYW1lcw==",highlighted:`<span class="hljs-comment"># Initialize video session</span>
inference_session = processor.init_video_session(
video=video_frames,
inference_device=device,
)
<span class="hljs-comment"># Add multiple objects on the first frame using batch processing</span>
ann_frame_idx = <span class="hljs-number">0</span>
obj_ids = [<span class="hljs-number">2</span>, <span class="hljs-number">3</span>] <span class="hljs-comment"># Track two different objects</span>
input_points = [
[[[<span class="hljs-number">200</span>, <span class="hljs-number">300</span>], [<span class="hljs-number">230</span>, <span class="hljs-number">250</span>], [<span class="hljs-number">275</span>, <span class="hljs-number">175</span>]], [[<span class="hljs-number">400</span>, <span class="hljs-number">150</span>]]]
] <span class="hljs-comment"># Object 2: 3 points (2 positive, 1 negative); Object 3: 1 point</span>
input_labels = [
[[<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">0</span>], [<span class="hljs-number">1</span>]]
] <span class="hljs-comment"># Object 2: positive, positive, negative; Object 3: positive</span>
processor.add_inputs_to_inference_session(
inference_session=inference_session,
frame_idx=ann_frame_idx,
obj_ids=obj_ids,
input_points=input_points,
input_labels=input_labels,
)
<span class="hljs-comment"># Get masks for all objects on the first frame</span>
outputs = model(
inference_session=inference_session,
frame_idx=ann_frame_idx,
)
video_res_masks = processor.post_process_masks(
[outputs.pred_masks], original_sizes=[[inference_session.video_height, inference_session.video_width]], binarize=<span class="hljs-literal">False</span>
)[<span class="hljs-number">0</span>]
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Generated masks for <span class="hljs-subst">{video_res_masks.shape[<span class="hljs-number">0</span>]}</span> objects&quot;</span>)
Generated masks <span class="hljs-keyword">for</span> <span class="hljs-number">2</span> objects
<span class="hljs-comment"># Propagate all objects through the video</span>
video_segments = {}
<span class="hljs-keyword">for</span> sam2_video_output <span class="hljs-keyword">in</span> model.propagate_in_video_iterator(inference_session):
video_res_masks = processor.post_process_masks(
[sam2_video_output.pred_masks], original_sizes=[[inference_session.video_height, inference_session.video_width]], binarize=<span class="hljs-literal">False</span>
)[<span class="hljs-number">0</span>]
video_segments[sam2_video_output.frame_idx] = {
obj_id: video_res_masks[i]
<span class="hljs-keyword">for</span> i, obj_id <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(inference_session.obj_ids)
}
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Tracked <span class="hljs-subst">{<span class="hljs-built_in">len</span>(inference_session.obj_ids)}</span> objects through <span class="hljs-subst">{<span class="hljs-built_in">len</span>(video_segments)}</span> frames&quot;</span>)
Tracked <span class="hljs-number">2</span> objects through <span class="hljs-number">200</span> frames`,lang:"python",wrap:!1});var F=e(A,2);t(F,{title:"EdgeTamVideoMaskDecoderConfig",local:"transformers.EdgeTamVideoMaskDecoderConfig",headingTag:"h2"});var d=e(F,2),te=n(d);o(te,{name:"class transformers.EdgeTamVideoMaskDecoderConfig",anchor:"transformers.EdgeTamVideoMaskDecoderConfig",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/configuration_edgetam_video.py#L57",parameters:[{name:"transformers_version",val:": str | None = None"},{name:"architectures",val:": list[str] | None = None"},{name:"output_hidden_states",val:": bool | None = False"},{name:"return_dict",val:": bool | None = True"},{name:"dtype",val:": str | torch.dtype | None = None"},{name:"chunk_size_feed_forward",val:": int = 0"},{name:"is_encoder_decoder",val:": bool = False"},{name:"id2label",val:": dict[int, str] | dict[str, str] | None = None"},{name:"label2id",val:": dict[str, int] | dict[str, str] | None = None"},{name:"problem_type",val:": Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = None"},{name:"hidden_size",val:": int = 256"},{name:"hidden_act",val:": str = 'gelu'"},{name:"mlp_dim",val:": int = 2048"},{name:"num_hidden_layers",val:": int = 2"},{name:"num_attention_heads",val:": int = 8"},{name:"attention_downsample_rate",val:": int = 2"},{name:"num_multimask_outputs",val:": int = 3"},{name:"iou_head_depth",val:": int = 3"},{name:"iou_head_hidden_dim",val:": int = 256"},{name:"dynamic_multimask_via_stability",val:": bool = True"},{name:"dynamic_multimask_stability_delta",val:": float = 0.05"},{name:"dynamic_multimask_stability_thresh",val:": float = 0.98"}],parametersDescription:[{anchor:"transformers.EdgeTamVideoMaskDecoderConfig.hidden_size",description:`<strong>hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>256</code>) &#x2014;
Dimension of the hidden representations.`,name:"hidden_size"},{anchor:"transformers.EdgeTamVideoMaskDecoderConfig.hidden_act",description:`<strong>hidden_act</strong> (<code>str</code>, <em>optional</em>, defaults to <code>gelu</code>) &#x2014;
The non-linear activation function (function or string) in the decoder. For example, <code>&quot;gelu&quot;</code>,
<code>&quot;relu&quot;</code>, <code>&quot;silu&quot;</code>, etc.`,name:"hidden_act"},{anchor:"transformers.EdgeTamVideoMaskDecoderConfig.mlp_dim",description:`<strong>mlp_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 2048) &#x2014;
The dimension of the MLP in the two-way transformer.`,name:"mlp_dim"},{anchor:"transformers.EdgeTamVideoMaskDecoderConfig.num_hidden_layers",description:`<strong>num_hidden_layers</strong> (<code>int</code>, <em>optional</em>, defaults to <code>2</code>) &#x2014;
Number of hidden layers in the Transformer decoder.`,name:"num_hidden_layers"},{anchor:"transformers.EdgeTamVideoMaskDecoderConfig.num_attention_heads",description:`<strong>num_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to <code>8</code>) &#x2014;
Number of attention heads for each attention layer in the Transformer decoder.`,name:"num_attention_heads"},{anchor:"transformers.EdgeTamVideoMaskDecoderConfig.attention_downsample_rate",description:`<strong>attention_downsample_rate</strong> (<code>int</code>, <em>optional</em>, defaults to 2) &#x2014;
The downsample rate for the attention layers.`,name:"attention_downsample_rate"},{anchor:"transformers.EdgeTamVideoMaskDecoderConfig.num_multimask_outputs",description:`<strong>num_multimask_outputs</strong> (<code>int</code>, <em>optional</em>, defaults to 3) &#x2014;
The number of multimask outputs.`,name:"num_multimask_outputs"},{anchor:"transformers.EdgeTamVideoMaskDecoderConfig.iou_head_depth",description:`<strong>iou_head_depth</strong> (<code>int</code>, <em>optional</em>, defaults to 3) &#x2014;
The depth of the IoU head.`,name:"iou_head_depth"},{anchor:"transformers.EdgeTamVideoMaskDecoderConfig.iou_head_hidden_dim",description:`<strong>iou_head_hidden_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 256) &#x2014;
The hidden dimension of the IoU head.`,name:"iou_head_hidden_dim"},{anchor:"transformers.EdgeTamVideoMaskDecoderConfig.dynamic_multimask_via_stability",description:`<strong>dynamic_multimask_via_stability</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to use dynamic multimask via stability.`,name:"dynamic_multimask_via_stability"},{anchor:"transformers.EdgeTamVideoMaskDecoderConfig.dynamic_multimask_stability_delta",description:`<strong>dynamic_multimask_stability_delta</strong> (<code>float</code>, <em>optional</em>, defaults to 0.05) &#x2014;
The stability delta for the dynamic multimask.`,name:"dynamic_multimask_stability_delta"},{anchor:"transformers.EdgeTamVideoMaskDecoderConfig.dynamic_multimask_stability_thresh",description:`<strong>dynamic_multimask_stability_thresh</strong> (<code>float</code>, <em>optional</em>, defaults to 0.98) &#x2014;
The stability threshold for the dynamic multimask.`,name:"dynamic_multimask_stability_thresh"}]}),s(4),a(d);var H=e(d,2);t(H,{title:"EdgeTamVideoPromptEncoderConfig",local:"transformers.EdgeTamVideoPromptEncoderConfig",headingTag:"h2"});var l=e(H,2),ie=n(l);o(ie,{name:"class transformers.EdgeTamVideoPromptEncoderConfig",anchor:"transformers.EdgeTamVideoPromptEncoderConfig",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/configuration_edgetam_video.py#L32",parameters:[{name:"transformers_version",val:": str | None = None"},{name:"architectures",val:": list[str] | None = None"},{name:"output_hidden_states",val:": bool | None = False"},{name:"return_dict",val:": bool | None = True"},{name:"dtype",val:": str | torch.dtype | None = None"},{name:"chunk_size_feed_forward",val:": int = 0"},{name:"is_encoder_decoder",val:": bool = False"},{name:"id2label",val:": dict[int, str] | dict[str, str] | None = None"},{name:"label2id",val:": dict[str, int] | dict[str, str] | None = None"},{name:"problem_type",val:": Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = None"},{name:"hidden_size",val:": int = 256"},{name:"image_size",val:": int | list[int] | tuple[int, int] = 1024"},{name:"patch_size",val:": int | list[int] | tuple[int, int] = 16"},{name:"mask_input_channels",val:": int = 16"},{name:"num_point_embeddings",val:": int = 4"},{name:"hidden_act",val:": str = 'gelu'"},{name:"layer_norm_eps",val:": float = 1e-06"},{name:"scale",val:": int = 1"}],parametersDescription:[{anchor:"transformers.EdgeTamVideoPromptEncoderConfig.hidden_size",description:`<strong>hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>256</code>) &#x2014;
Dimension of the hidden representations.`,name:"hidden_size"},{anchor:"transformers.EdgeTamVideoPromptEncoderConfig.image_size",description:`<strong>image_size</strong> (<code>Union[int, list[int], tuple[int, int]]</code>, <em>optional</em>, defaults to <code>1024</code>) &#x2014;
The size (resolution) of each image.`,name:"image_size"},{anchor:"transformers.EdgeTamVideoPromptEncoderConfig.patch_size",description:`<strong>patch_size</strong> (<code>Union[int, list[int], tuple[int, int]]</code>, <em>optional</em>, defaults to <code>16</code>) &#x2014;
The size (resolution) of each patch.`,name:"patch_size"},{anchor:"transformers.EdgeTamVideoPromptEncoderConfig.mask_input_channels",description:`<strong>mask_input_channels</strong> (<code>int</code>, <em>optional</em>, defaults to 16) &#x2014;
The number of channels to be fed to the <code>MaskDecoder</code> module.`,name:"mask_input_channels"},{anchor:"transformers.EdgeTamVideoPromptEncoderConfig.num_point_embeddings",description:`<strong>num_point_embeddings</strong> (<code>int</code>, <em>optional</em>, defaults to 4) &#x2014;
The number of point embeddings to be used.`,name:"num_point_embeddings"},{anchor:"transformers.EdgeTamVideoPromptEncoderConfig.hidden_act",description:`<strong>hidden_act</strong> (<code>str</code>, <em>optional</em>, defaults to <code>gelu</code>) &#x2014;
The non-linear activation function (function or string) in the decoder. For example, <code>&quot;gelu&quot;</code>,
<code>&quot;relu&quot;</code>, <code>&quot;silu&quot;</code>, etc.`,name:"hidden_act"},{anchor:"transformers.EdgeTamVideoPromptEncoderConfig.layer_norm_eps",description:`<strong>layer_norm_eps</strong> (<code>float</code>, <em>optional</em>, defaults to <code>1e-06</code>) &#x2014;
The epsilon used by the layer normalization layers.`,name:"layer_norm_eps"},{anchor:"transformers.EdgeTamVideoPromptEncoderConfig.scale",description:`<strong>scale</strong> (<code>float</code>, <em>optional</em>, defaults to 1) &#x2014;
The scale factor for the prompt encoder.`,name:"scale"}]}),s(4),a(l);var D=e(l,2);t(D,{title:"EdgeTamVideoConfig",local:"transformers.EdgeTamVideoConfig",headingTag:"h2"});var m=e(D,2),P=n(m);o(P,{name:"class transformers.EdgeTamVideoConfig",anchor:"transformers.EdgeTamVideoConfig",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/configuration_edgetam_video.py#L96",parameters:[{name:"transformers_version",val:": str | None = None"},{name:"architectures",val:": list[str] | None = None"},{name:"output_hidden_states",val:": bool | None = False"},{name:"return_dict",val:": bool | None = True"},{name:"dtype",val:": str | torch.dtype | None = None"},{name:"chunk_size_feed_forward",val:": int = 0"},{name:"is_encoder_decoder",val:": bool = False"},{name:"id2label",val:": dict[int, str] | dict[str, str] | None = None"},{name:"label2id",val:": dict[str, int] | dict[str, str] | None = None"},{name:"problem_type",val:": Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = None"},{name:"vision_config",val:": dict | transformers.configuration_utils.PreTrainedConfig | None = None"},{name:"prompt_encoder_config",val:": dict | transformers.configuration_utils.PreTrainedConfig | None = None"},{name:"mask_decoder_config",val:": dict | transformers.configuration_utils.PreTrainedConfig | None = None"},{name:"initializer_range",val:": float = 0.02"},{name:"num_maskmem",val:": int = 7"},{name:"image_size",val:": int | list[int] | tuple[int, int] = 1024"},{name:"sigmoid_scale_for_mem_enc",val:": float = 20.0"},{name:"sigmoid_bias_for_mem_enc",val:": float = -10.0"},{name:"enable_occlusion_spatial_embedding",val:": bool = True"},{name:"multimask_output_in_sam",val:": bool = True"},{name:"multimask_min_pt_num",val:": int = 0"},{name:"multimask_max_pt_num",val:": int = 1"},{name:"multimask_output_for_tracking",val:": bool = True"},{name:"max_object_pointers_in_encoder",val:": int = 16"},{name:"max_cond_frame_num",val:": int = -1"},{name:"enable_temporal_pos_encoding_for_object_pointers",val:": bool = True"},{name:"memory_attention_hidden_size",val:": int = 256"},{name:"memory_attention_num_layers",val:": int = 2"},{name:"memory_attention_num_attention_heads",val:": int = 1"},{name:"memory_attention_downsample_rate",val:": int = 1"},{name:"memory_attention_mlp_hidden_size",val:": int = 2048"},{name:"memory_attention_mlp_hidden_act",val:": str = 'relu'"},{name:"memory_attention_dropout",val:": float | int = 0.1"},{name:"memory_attention_rope_feat_sizes",val:": list | None = None"},{name:"memory_attention_rope_k_sizes",val:": list | None = None"},{name:"memory_attention_rope_dropout",val:": float | int = 0.1"},{name:"rope_parameters",val:": dict | None = None"},{name:"perceiver_resampler_num_latents",val:": int = 256"},{name:"perceiver_resampler_num_latents_2d",val:": int = 256"},{name:"perceiver_resampler_hidden_size",val:": int = 64"},{name:"perceiver_resampler_mlp_intermediate_size",val:": int = 256"},{name:"perceiver_resampler_num_attention_heads",val:": int = 1"},{name:"perceiver_resampler_attention_head_dim",val:": int = 64"},{name:"perceiver_resampler_num_layers",val:": int = 2"},{name:"perceiver_resampler_hidden_dropout",val:": float | int = 0.0"},{name:"perceiver_resampler_attention_dropout",val:": float | int = 0.0"},{name:"memory_encoder_hidden_size",val:": int = 256"},{name:"memory_encoder_output_channels",val:": int = 64"},{name:"mask_downsampler_embed_dim",val:": int = 256"},{name:"memory_fuser_intermediate_dim",val:": int = 1024"},{name:"mask_downsampler_kernel_size",val:": int = 3"},{name:"mask_downsampler_stride",val:": int = 2"},{name:"mask_downsampler_padding",val:": int = 1"},{name:"mask_downsampler_total_stride",val:": int = 16"},{name:"mask_downsampler_hidden_act",val:": str = 'gelu'"},{name:"memory_fuser_num_layers",val:": int = 2"},{name:"memory_fuser_embed_dim",val:": int = 256"},{name:"memory_fuser_kernel_size",val:": int = 7"},{name:"memory_fuser_padding",val:": int = 3"},{name:"memory_fuser_layer_scale_init_value",val:": float = 1e-06"},{name:"memory_fuser_hidden_act",val:": str = 'gelu'"}],parametersDescription:[{anchor:"transformers.EdgeTamVideoConfig.vision_config",description:`<strong>vision_config</strong> (<code>Union[dict, ~configuration_utils.PreTrainedConfig]</code>, <em>optional</em>) &#x2014;
The config object or dictionary of the vision backbone.`,name:"vision_config"},{anchor:"transformers.EdgeTamVideoConfig.prompt_encoder_config",description:`<strong>prompt_encoder_config</strong> (Union[<code>dict</code>, <code>EdgeTamVideoPromptEncoderConfig</code>], <em>optional</em>) &#x2014;
Dictionary of configuration options used to initialize <a href="/docs/transformers/pr_51549/en/model_doc/edgetam_video#transformers.EdgeTamVideoPromptEncoderConfig">EdgeTamVideoPromptEncoderConfig</a>.`,name:"prompt_encoder_config"},{anchor:"transformers.EdgeTamVideoConfig.mask_decoder_config",description:`<strong>mask_decoder_config</strong> (Union[<code>dict</code>, <code>EdgeTamVideoMaskDecoderConfig</code>], <em>optional</em>) &#x2014;
Dictionary of configuration options used to initialize <a href="/docs/transformers/pr_51549/en/model_doc/edgetam#transformers.EdgeTamMaskDecoderConfig">EdgeTamMaskDecoderConfig</a>.`,name:"mask_decoder_config"},{anchor:"transformers.EdgeTamVideoConfig.initializer_range",description:`<strong>initializer_range</strong> (<code>float</code>, <em>optional</em>, defaults to <code>0.02</code>) &#x2014;
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.`,name:"initializer_range"},{anchor:"transformers.EdgeTamVideoConfig.num_maskmem",description:`<strong>num_maskmem</strong> (<code>int</code>, <em>optional</em>, defaults to 7) &#x2014;
The number of memory slots for the mask memory.`,name:"num_maskmem"},{anchor:"transformers.EdgeTamVideoConfig.image_size",description:`<strong>image_size</strong> (<code>Union[int, list[int], tuple[int, int]]</code>, <em>optional</em>, defaults to <code>1024</code>) &#x2014;
The size (resolution) of each image.`,name:"image_size"},{anchor:"transformers.EdgeTamVideoConfig.sigmoid_scale_for_mem_enc",description:`<strong>sigmoid_scale_for_mem_enc</strong> (<code>float</code>, <em>optional</em>, defaults to 20.0) &#x2014;
Scale factor for the sigmoid function in the memory encoder.`,name:"sigmoid_scale_for_mem_enc"},{anchor:"transformers.EdgeTamVideoConfig.sigmoid_bias_for_mem_enc",description:`<strong>sigmoid_bias_for_mem_enc</strong> (<code>float</code>, <em>optional</em>, defaults to -10.0) &#x2014;
Bias for the sigmoid function in the memory encoder.`,name:"sigmoid_bias_for_mem_enc"},{anchor:"transformers.EdgeTamVideoConfig.enable_occlusion_spatial_embedding",description:`<strong>enable_occlusion_spatial_embedding</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to enable spatial embedding for occlusions.`,name:"enable_occlusion_spatial_embedding"},{anchor:"transformers.EdgeTamVideoConfig.multimask_output_in_sam",description:`<strong>multimask_output_in_sam</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to output multiple masks from the SAM head.`,name:"multimask_output_in_sam"},{anchor:"transformers.EdgeTamVideoConfig.multimask_min_pt_num",description:`<strong>multimask_min_pt_num</strong> (<code>int</code>, <em>optional</em>, defaults to 0) &#x2014;
The minimum number of points to trigger multimask output.`,name:"multimask_min_pt_num"},{anchor:"transformers.EdgeTamVideoConfig.multimask_max_pt_num",description:`<strong>multimask_max_pt_num</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The maximum number of points to trigger multimask output.`,name:"multimask_max_pt_num"},{anchor:"transformers.EdgeTamVideoConfig.multimask_output_for_tracking",description:`<strong>multimask_output_for_tracking</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to use multimask output for tracking.`,name:"multimask_output_for_tracking"},{anchor:"transformers.EdgeTamVideoConfig.max_object_pointers_in_encoder",description:`<strong>max_object_pointers_in_encoder</strong> (<code>int</code>, <em>optional</em>, defaults to 16) &#x2014;
The maximum number of object pointers in the encoder.`,name:"max_object_pointers_in_encoder"},{anchor:"transformers.EdgeTamVideoConfig.max_cond_frame_num",description:`<strong>max_cond_frame_num</strong> (<code>int</code>, <em>optional</em>, defaults to -1) &#x2014;
Maximum number of conditioning frames to use in memory attention. Set to -1 to use all conditioning frames.`,name:"max_cond_frame_num"},{anchor:"transformers.EdgeTamVideoConfig.enable_temporal_pos_encoding_for_object_pointers",description:`<strong>enable_temporal_pos_encoding_for_object_pointers</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to enable temporal positional encoding for object pointers.`,name:"enable_temporal_pos_encoding_for_object_pointers"},{anchor:"transformers.EdgeTamVideoConfig.memory_attention_hidden_size",description:`<strong>memory_attention_hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to 256) &#x2014;
Dimensionality of the memory attention hidden states.`,name:"memory_attention_hidden_size"},{anchor:"transformers.EdgeTamVideoConfig.memory_attention_num_layers",description:`<strong>memory_attention_num_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 2) &#x2014;
The number of layers in the memory attention module.`,name:"memory_attention_num_layers"},{anchor:"transformers.EdgeTamVideoConfig.memory_attention_num_attention_heads",description:`<strong>memory_attention_num_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
Number of attention heads for each attention layer in the memory attention.`,name:"memory_attention_num_attention_heads"},{anchor:"transformers.EdgeTamVideoConfig.memory_attention_downsample_rate",description:`<strong>memory_attention_downsample_rate</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The downsample rate for the attention layers.`,name:"memory_attention_downsample_rate"},{anchor:"transformers.EdgeTamVideoConfig.memory_attention_mlp_hidden_size",description:`<strong>memory_attention_mlp_hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to 2048) &#x2014;
The dimension of the feedforward network in the memory attention module.`,name:"memory_attention_mlp_hidden_size"},{anchor:"transformers.EdgeTamVideoConfig.memory_attention_mlp_hidden_act",description:`<strong>memory_attention_mlp_hidden_act</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;relu&quot;</code>) &#x2014;
The non-linear activation function in the feedforward network in the memory attention module.`,name:"memory_attention_mlp_hidden_act"},{anchor:"transformers.EdgeTamVideoConfig.memory_attention_dropout",description:`<strong>memory_attention_dropout</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
The dropout rate for the memory attention module.`,name:"memory_attention_dropout"},{anchor:"transformers.EdgeTamVideoConfig.memory_attention_rope_feat_sizes",description:`<strong>memory_attention_rope_feat_sizes</strong> (<code>Tuple[int, int]</code>, <em>optional</em>, defaults to <code>[64, 64]</code>) &#x2014;
The feature sizes for the Rope positional encoding.`,name:"memory_attention_rope_feat_sizes"},{anchor:"transformers.EdgeTamVideoConfig.memory_attention_rope_k_sizes",description:`<strong>memory_attention_rope_k_sizes</strong> (<code>List[int]</code>, <em>optional</em>, defaults to <code>[16, 16]</code>) &#x2014;
The key feature sizes for the RoPE positional encoding in memory attention.`,name:"memory_attention_rope_k_sizes"},{anchor:"transformers.EdgeTamVideoConfig.memory_attention_rope_dropout",description:`<strong>memory_attention_rope_dropout</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
The dropout rate for the Rope positional encoding.`,name:"memory_attention_rope_dropout"},{anchor:"transformers.EdgeTamVideoConfig.rope_parameters",description:`<strong>rope_parameters</strong> (<code>dict</code>, <em>optional</em>) &#x2014;
Dictionary containing the configuration parameters for the RoPE embeddings. The dictionary should contain
a value for <code>rope_theta</code> and optionally parameters used for scaling in case you want to use RoPE
with longer <code>max_position_embeddings</code>.`,name:"rope_parameters"},{anchor:"transformers.EdgeTamVideoConfig.perceiver_resampler_num_latents",description:`<strong>perceiver_resampler_num_latents</strong> (<code>int</code>, <em>optional</em>, defaults to 256) &#x2014;
The number of 1D latent tokens in the perceiver resampler.`,name:"perceiver_resampler_num_latents"},{anchor:"transformers.EdgeTamVideoConfig.perceiver_resampler_num_latents_2d",description:`<strong>perceiver_resampler_num_latents_2d</strong> (<code>int</code>, <em>optional</em>, defaults to 256) &#x2014;
The number of 2D latent tokens in the perceiver resampler.`,name:"perceiver_resampler_num_latents_2d"},{anchor:"transformers.EdgeTamVideoConfig.perceiver_resampler_hidden_size",description:`<strong>perceiver_resampler_hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to 64) &#x2014;
The hidden size of the perceiver resampler.`,name:"perceiver_resampler_hidden_size"},{anchor:"transformers.EdgeTamVideoConfig.perceiver_resampler_mlp_intermediate_size",description:`<strong>perceiver_resampler_mlp_intermediate_size</strong> (<code>int</code>, <em>optional</em>, defaults to 256) &#x2014;
The intermediate size of the feedforward network in the perceiver resampler.`,name:"perceiver_resampler_mlp_intermediate_size"},{anchor:"transformers.EdgeTamVideoConfig.perceiver_resampler_num_attention_heads",description:`<strong>perceiver_resampler_num_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The number of attention heads in the perceiver resampler.`,name:"perceiver_resampler_num_attention_heads"},{anchor:"transformers.EdgeTamVideoConfig.perceiver_resampler_attention_head_dim",description:`<strong>perceiver_resampler_attention_head_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 64) &#x2014;
The dimension of each attention head in the perceiver resampler.`,name:"perceiver_resampler_attention_head_dim"},{anchor:"transformers.EdgeTamVideoConfig.perceiver_resampler_num_layers",description:`<strong>perceiver_resampler_num_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 2) &#x2014;
The number of layers in the perceiver resampler.`,name:"perceiver_resampler_num_layers"},{anchor:"transformers.EdgeTamVideoConfig.perceiver_resampler_hidden_dropout",description:`<strong>perceiver_resampler_hidden_dropout</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
The dropout rate for the hidden layers in the perceiver resampler.`,name:"perceiver_resampler_hidden_dropout"},{anchor:"transformers.EdgeTamVideoConfig.perceiver_resampler_attention_dropout",description:`<strong>perceiver_resampler_attention_dropout</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
The dropout rate for the attention layers in the perceiver resampler.`,name:"perceiver_resampler_attention_dropout"},{anchor:"transformers.EdgeTamVideoConfig.memory_encoder_hidden_size",description:`<strong>memory_encoder_hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to 256) &#x2014;
Dimensionality of the memory encoder hidden states.`,name:"memory_encoder_hidden_size"},{anchor:"transformers.EdgeTamVideoConfig.memory_encoder_output_channels",description:`<strong>memory_encoder_output_channels</strong> (<code>int</code>, <em>optional</em>, defaults to 64) &#x2014;
The number of output channels for the memory encoder.`,name:"memory_encoder_output_channels"},{anchor:"transformers.EdgeTamVideoConfig.mask_downsampler_embed_dim",description:`<strong>mask_downsampler_embed_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 256) &#x2014;
The dimension of the mask downsampler embedding.`,name:"mask_downsampler_embed_dim"},{anchor:"transformers.EdgeTamVideoConfig.memory_fuser_intermediate_dim",description:`<strong>memory_fuser_intermediate_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 1024) &#x2014;
The intermediate dimension of the memory fuser feedforward network.`,name:"memory_fuser_intermediate_dim"},{anchor:"transformers.EdgeTamVideoConfig.mask_downsampler_kernel_size",description:`<strong>mask_downsampler_kernel_size</strong> (<code>int</code>, <em>optional</em>, defaults to 3) &#x2014;
The kernel size for the mask downsampler.`,name:"mask_downsampler_kernel_size"},{anchor:"transformers.EdgeTamVideoConfig.mask_downsampler_stride",description:`<strong>mask_downsampler_stride</strong> (<code>int</code>, <em>optional</em>, defaults to 2) &#x2014;
The stride for the mask downsampler.`,name:"mask_downsampler_stride"},{anchor:"transformers.EdgeTamVideoConfig.mask_downsampler_padding",description:`<strong>mask_downsampler_padding</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The padding for the mask downsampler.`,name:"mask_downsampler_padding"},{anchor:"transformers.EdgeTamVideoConfig.mask_downsampler_total_stride",description:`<strong>mask_downsampler_total_stride</strong> (<code>int</code>, <em>optional</em>, defaults to 16) &#x2014;
The total stride for the mask downsampler.`,name:"mask_downsampler_total_stride"},{anchor:"transformers.EdgeTamVideoConfig.mask_downsampler_hidden_act",description:`<strong>mask_downsampler_hidden_act</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;gelu&quot;</code>) &#x2014;
The non-linear activation function in the mask downsampler.`,name:"mask_downsampler_hidden_act"},{anchor:"transformers.EdgeTamVideoConfig.memory_fuser_num_layers",description:`<strong>memory_fuser_num_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 2) &#x2014;
The number of layers in the memory fuser.`,name:"memory_fuser_num_layers"},{anchor:"transformers.EdgeTamVideoConfig.memory_fuser_embed_dim",description:`<strong>memory_fuser_embed_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 256) &#x2014;
The dimension of the memory fuser embedding.`,name:"memory_fuser_embed_dim"},{anchor:"transformers.EdgeTamVideoConfig.memory_fuser_kernel_size",description:`<strong>memory_fuser_kernel_size</strong> (<code>int</code>, <em>optional</em>, defaults to 7) &#x2014;
The kernel size for the memory fuser.`,name:"memory_fuser_kernel_size"},{anchor:"transformers.EdgeTamVideoConfig.memory_fuser_padding",description:`<strong>memory_fuser_padding</strong> (<code>int</code>, <em>optional</em>, defaults to 3) &#x2014;
The padding for the memory fuser.`,name:"memory_fuser_padding"},{anchor:"transformers.EdgeTamVideoConfig.memory_fuser_layer_scale_init_value",description:`<strong>memory_fuser_layer_scale_init_value</strong> (<code>float</code>, <em>optional</em>, defaults to 1e-06) &#x2014;
The initial value for the layer scale in the memory fuser.`,name:"memory_fuser_layer_scale_init_value"},{anchor:"transformers.EdgeTamVideoConfig.memory_fuser_hidden_act",description:`<strong>memory_fuser_hidden_act</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;gelu&quot;</code>) &#x2014;
The non-linear activation function in the memory fuser.`,name:"memory_fuser_hidden_act"}]});var re=e(P,6);Ie(re,{anchor:"transformers.EdgeTamVideoConfig.example",children:(r,j)=>{var oe=Be(),Ue=e(ne(oe),2);i(Ue,{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMCglMEElMjAlMjAlMjAlMjBFZGdlVGFtVmlzaW9uQ29uZmlnJTJDJTBBJTIwJTIwJTIwJTIwRWRnZVRhbVZpZGVvUHJvbXB0RW5jb2RlckNvbmZpZyUyQyUwQSUyMCUyMCUyMCUyMEVkZ2VUYW1WaWRlb01hc2tEZWNvZGVyQ29uZmlnJTJDJTBBJTIwJTIwJTIwJTIwRWRnZVRhbVZpZGVvTW9kZWwlMkMlMEElMjAlMjAlMjAlMjBFZGdlVGFtVmlkZW9Db25maWclMkMlMEEpJTBBJTBBJTIzJTIwSW5pdGlhbGl6aW5nJTIwYSUyMEVkZ2VUYW1WaWRlb0NvbmZpZyUyMHdpdGglMjAlNjAlMjJmYWNlYm9vay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2Rlcl9jb25maWclMjAlM0QlMjBFZGdlVGFtVmlkZW9NYXNrRGVjb2RlckNvbmZpZygpJTBBJTBBY29uZmlnJTIwJTNEJTIwRWRnZVRhbVZpZGVvQ29uZmlnKHZpc2lvbl9jb25maWclMkMlMjBwcm9tcHRfZW5jb2Rlcl9jb25maWclMkMlMjBtYXNrX2RlY29kZXJfY29uZmlnKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> (
<span class="hljs-meta">... </span> EdgeTamVisionConfig,
<span class="hljs-meta">... </span> EdgeTamVideoPromptEncoderConfig,
<span class="hljs-meta">... </span> EdgeTamVideoMaskDecoderConfig,
<span class="hljs-meta">... </span> EdgeTamVideoModel,
<span class="hljs-meta">... </span> EdgeTamVideoConfig,
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a EdgeTamVideoConfig with \`&quot;facebook/edgetam.1_hiera_tiny&quot;\` style configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = EdgeTamVideoConfig()
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a EdgeTamVideoModel (with random weights) from the \`&quot;facebook/edgetam.1_hiera_tiny&quot;\` style configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = EdgeTamVideoModel(configuration)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Accessing the model configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = model.config
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># We can also initialize a EdgeTamConfig from a EdgeTamVisionConfig, EdgeTamPromptEncoderConfig, and EdgeTamMaskDecoderConfig</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing EDGETAM vision encoder, memory attention, and memory encoder configurations</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>vision_config = EdgeTamVisionConfig()
<span class="hljs-meta">&gt;&gt;&gt; </span>prompt_encoder_config = EdgeTamVideoPromptEncoderConfig()
<span class="hljs-meta">&gt;&gt;&gt; </span>mask_decoder_config = EdgeTamVideoMaskDecoderConfig()
<span class="hljs-meta">&gt;&gt;&gt; </span>config = EdgeTamVideoConfig(vision_config, prompt_encoder_config, mask_decoder_config)`,lang:"python",wrap:!1}),V(r,oe)},$$slots:{default:!0}}),a(m);var q=e(m,2);t(q,{title:"EdgeTamVideoInferenceSession",local:"transformers.EdgeTamVideoInferenceSession",headingTag:"h2"});var c=e(q,2),L=n(c);o(L,{name:"class transformers.EdgeTamVideoInferenceSession",anchor:"transformers.EdgeTamVideoInferenceSession",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/modeling_edgetam_video.py#L940",parameters:[{name:"video",val:": typing.Optional[torch.Tensor] = None"},{name:"video_height",val:": int | None = None"},{name:"video_width",val:": int | None = None"},{name:"inference_device",val:": typing.Union[torch.device, str] = 'cpu'"},{name:"inference_state_device",val:": typing.Union[torch.device, str] = 'cpu'"},{name:"video_storage_device",val:": typing.Union[torch.device, str] = 'cpu'"},{name:"dtype",val:": typing.Union[torch.dtype, str] = 'float32'"},{name:"max_vision_features_cache_size",val:": int = 1"}],parametersDescription:[{anchor:"transformers.EdgeTamVideoInferenceSession.video",description:`<strong>video</strong> (<code>torch.Tensor</code>, <em>optional</em>) &#x2014;
The video to process. No need to provide when streaming.`,name:"video"},{anchor:"transformers.EdgeTamVideoInferenceSession.video_height",description:`<strong>video_height</strong> (<code>int</code>, <em>optional</em>) &#x2014;
The height of the video.`,name:"video_height"},{anchor:"transformers.EdgeTamVideoInferenceSession.video_width",description:`<strong>video_width</strong> (<code>int</code>, <em>optional</em>) &#x2014;
The width of the video.`,name:"video_width"},{anchor:"transformers.EdgeTamVideoInferenceSession.inference_device",description:`<strong>inference_device</strong> (<code>torch.device</code>, <em>optional</em>, defaults to <code>&quot;cpu&quot;</code>) &#x2014;
The device to use for inference.`,name:"inference_device"},{anchor:"transformers.EdgeTamVideoInferenceSession.inference_state_device",description:`<strong>inference_state_device</strong> (<code>torch.device</code>, <em>optional</em>, defaults to <code>&quot;cpu&quot;</code>) &#x2014;
The device to store the inference state on.`,name:"inference_state_device"},{anchor:"transformers.EdgeTamVideoInferenceSession.video_storage_device",description:`<strong>video_storage_device</strong> (<code>torch.device</code>, <em>optional</em>, defaults to <code>&quot;cpu&quot;</code>) &#x2014;
The device to store the video on.`,name:"video_storage_device"},{anchor:"transformers.EdgeTamVideoInferenceSession.dtype",description:`<strong>dtype</strong> (<code>torch.dtype</code>, <em>optional</em>, defaults to <code>&quot;float32&quot;</code>) &#x2014;
The dtype to use for the video.`,name:"dtype"},{anchor:"transformers.EdgeTamVideoInferenceSession.max_vision_features_cache_size",description:`<strong>max_vision_features_cache_size</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The maximum number of vision features to cache.`,name:"max_vision_features_cache_size"}]});var p=e(L,4),de=n(p);o(de,{name:"add_mask_inputs",anchor:"transformers.EdgeTamVideoInferenceSession.add_mask_inputs",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/modeling_edgetam_video.py#L1060",parameters:[{name:"obj_idx",val:": int"},{name:"frame_idx",val:": int"},{name:"inputs",val:": Tensor"}]}),s(2),a(p);var _=e(p,2),le=n(_);o(le,{name:"add_new_frame",anchor:"transformers.EdgeTamVideoInferenceSession.add_new_frame",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/modeling_edgetam_video.py#L1135",parameters:[{name:"pixel_values",val:": Tensor"},{name:"frame_idx",val:": int | None = None"}]}),s(2),a(_);var g=e(_,2),me=n(g);o(me,{name:"add_point_inputs",anchor:"transformers.EdgeTamVideoInferenceSession.add_point_inputs",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/modeling_edgetam_video.py#L1046",parameters:[{name:"obj_idx",val:": int"},{name:"frame_idx",val:": int"},{name:"inputs",val:": dict"}]}),s(2),a(g);var h=e(g,2),ce=n(h);o(ce,{name:"get_frame",anchor:"transformers.EdgeTamVideoInferenceSession.get_frame",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/modeling_edgetam_video.py#L1151",parameters:[{name:"frame_idx",val:": int"}]}),s(2),a(h);var f=e(h,2),pe=n(f);o(pe,{name:"get_obj_num",anchor:"transformers.EdgeTamVideoInferenceSession.get_obj_num",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/modeling_edgetam_video.py#L1041",parameters:[]}),s(2),a(f);var u=e(f,2),_e=n(u);o(_e,{name:"get_output",anchor:"transformers.EdgeTamVideoInferenceSession.get_output",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/modeling_edgetam_video.py#L1108",parameters:[{name:"obj_idx",val:": int"},{name:"frame_idx",val:": int"},{name:"output_key",val:": str"},{name:"is_conditioning_frame",val:": bool = True"}],parametersDescription:[{anchor:"transformers.EdgeTamVideoInferenceSession.get_output.obj_idx",description:"<strong>obj_idx</strong> (int) &#x2014; The index of the object.",name:"obj_idx"},{anchor:"transformers.EdgeTamVideoInferenceSession.get_output.frame_idx",description:"<strong>frame_idx</strong> (int) &#x2014; The index of the frame.",name:"frame_idx"},{anchor:"transformers.EdgeTamVideoInferenceSession.get_output.output_key",description:"<strong>output_key</strong> (str) &#x2014; The key of the output.",name:"output_key"},{anchor:"transformers.EdgeTamVideoInferenceSession.get_output.is_conditioning_frame",description:"<strong>is_conditioning_frame</strong> (bool) &#x2014; Whether the output is for a conditioning frame.",name:"is_conditioning_frame"}]}),s(2),a(u);var y=e(u,2),ge=n(y);o(ge,{name:"obj_id_to_idx",anchor:"transformers.EdgeTamVideoInferenceSession.obj_id_to_idx",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/modeling_edgetam_video.py#L1015",parameters:[{name:"obj_id",val:": int"}]}),s(2),a(y);var b=e(y,2),he=n(b);o(he,{name:"obj_idx_to_id",anchor:"transformers.EdgeTamVideoInferenceSession.obj_idx_to_id",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/modeling_edgetam_video.py#L1037",parameters:[{name:"obj_idx",val:": int"}]}),s(2),a(b);var T=e(b,2),fe=n(T);o(fe,{name:"remove_mask_inputs",anchor:"transformers.EdgeTamVideoInferenceSession.remove_mask_inputs",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/modeling_edgetam_video.py#L1066",parameters:[{name:"obj_idx",val:": int"},{name:"frame_idx",val:": int"}]}),s(2),a(T);var v=e(T,2),ue=n(v);o(ue,{name:"remove_point_inputs",anchor:"transformers.EdgeTamVideoInferenceSession.remove_point_inputs",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/modeling_edgetam_video.py#L1056",parameters:[{name:"obj_idx",val:": int"},{name:"frame_idx",val:": int"}]}),s(2),a(v);var M=e(v,2),ye=n(M);o(ye,{name:"reset_inference_session",anchor:"transformers.EdgeTamVideoInferenceSession.reset_inference_session",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/modeling_edgetam_video.py#L1167",parameters:[]}),s(2),a(M);var J=e(M,2),be=n(J);o(be,{name:"reset_tracking_data",anchor:"transformers.EdgeTamVideoInferenceSession.reset_tracking_data",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/modeling_edgetam_video.py#L1155",parameters:[]}),s(2),a(J);var K=e(J,2),Te=n(K);o(Te,{name:"store_output",anchor:"transformers.EdgeTamVideoInferenceSession.store_output",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/modeling_edgetam_video.py#L1071",parameters:[{name:"obj_idx",val:": int"},{name:"frame_idx",val:": int"},{name:"output_key",val:": str | None = None"},{name:"output_value",val:": typing.Union[torch.Tensor, dict, NoneType] = None"},{name:"is_conditioning_frame",val:": bool = True"}],parametersDescription:[{anchor:"transformers.EdgeTamVideoInferenceSession.store_output.obj_idx",description:"<strong>obj_idx</strong> (int) &#x2014; The index of the object.",name:"obj_idx"},{anchor:"transformers.EdgeTamVideoInferenceSession.store_output.frame_idx",description:"<strong>frame_idx</strong> (int) &#x2014; The index of the frame.",name:"frame_idx"},{anchor:"transformers.EdgeTamVideoInferenceSession.store_output.output_key",description:"<strong>output_key</strong> (Optional[str]) &#x2014; The key of the output. If None, the output is stored as a dictionary.",name:"output_key"},{anchor:"transformers.EdgeTamVideoInferenceSession.store_output.output_value",description:"<strong>output_value</strong> (Optional[Union[torch.Tensor, dict]]) &#x2014; The value of the output.",name:"output_value"},{anchor:"transformers.EdgeTamVideoInferenceSession.store_output.is_conditioning_frame",description:"<strong>is_conditioning_frame</strong> (bool) &#x2014; Whether the output is for a conditioning frame.",name:"is_conditioning_frame"}]}),s(2),a(K),a(c);var O=e(c,2);t(O,{title:"EdgeTamVideoModel",local:"transformers.EdgeTamVideoModel",headingTag:"h2"});var U=e(O,2),$=n(U);o($,{name:"class transformers.EdgeTamVideoModel",anchor:"transformers.EdgeTamVideoModel",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/modeling_edgetam_video.py#L2060",parameters:[{name:"config",val:": EdgeTamVideoConfig"}],parametersDescription:[{anchor:"transformers.EdgeTamVideoModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_51549/en/model_doc/edgetam_video#transformers.EdgeTamVideoConfig">EdgeTamVideoConfig</a>) &#x2014;
Model configuration class with all the parameters of the model. Initializing with a config file does not
load the weights associated with the model, only the configuration. Check out the
<a href="/docs/transformers/pr_51549/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}]});var w=e($,8),ve=n(w);o(ve,{name:"forward",anchor:"transformers.EdgeTamVideoModel.forward",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/modeling_edgetam_video.py#L2194",parameters:[{name:"inference_session",val:": EdgeTamVideoInferenceSession"},{name:"frame_idx",val:": int | None = None"},{name:"frame",val:": typing.Optional[torch.Tensor] = None"},{name:"reverse",val:": bool = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.EdgeTamVideoModel.forward.inference_session",description:`<strong>inference_session</strong> (<code>~models.edgetam_video.modeling_edgetam_video.EdgeTamVideoInferenceSession</code>) &#x2014;
The video inference session object.`,name:"inference_session"},{anchor:"transformers.EdgeTamVideoModel.forward.frame_idx",description:`<strong>frame_idx</strong> (<code>int</code>, <em>optional</em>) &#x2014;
The index of the frame on which to run inference. No need to provide when inferring
on a new streamed frame.`,name:"frame_idx"},{anchor:"transformers.EdgeTamVideoModel.forward.frame",description:`<strong>frame</strong> (<code>torch.Tensor</code>, <em>optional</em>) &#x2014;
The frame to process. Provide when streaming.`,name:"frame"},{anchor:"transformers.EdgeTamVideoModel.forward.reverse",description:`<strong>reverse</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to propagate in reverse.`,name:"reverse"}],returnDescription:`
<p>A <code>EdgeTamVideoSegmentationOutput</code> or a tuple of
<code>torch.Tensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
href="/docs/transformers/pr_51549/en/model_doc/edgetam_video#transformers.EdgeTamVideoConfig"
>EdgeTamVideoConfig</a>) and inputs.</p>
`,returnType:`
<p><code>EdgeTamVideoSegmentationOutput</code> or <code>tuple(torch.Tensor)</code></p>
`}),s(4),a(w);var ee=e(w,2),Me=n(ee);o(Me,{name:"get_image_features",anchor:"transformers.EdgeTamVideoModel.get_image_features",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/edgetam_video/modeling_edgetam_video.py#L2293",parameters:[{name:"pixel_values",val:": Tensor"},{name:"**kwargs",val:": *<class 'transformers.utils.generic.TransformersKwargs'>"}],parametersDescription:[{anchor:"transformers.EdgeTamVideoModel.get_image_features.pixel_values",description:`<strong>pixel_values</strong> (<code>torch.Tensor</code>) &#x2014;
Input pixel values of shape <code>(batch_size, num_channels, height, width)</code>.`,name:"pixel_values"}],returnDescription:`
<p>A <code>EdgeTamVideoVisionEncoderOutput</code> or a tuple of
<code>torch.Tensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
href="/docs/transformers/pr_51549/en/model_doc/edgetam_video#transformers.EdgeTamVideoConfig"
>EdgeTamVideoConfig</a>) and inputs.</p>
`,returnType:`
<p><code>EdgeTamVideoVisionEncoderOutput</code> or <code>tuple(torch.Tensor)</code></p>
`}),s(2),a(ee),a(U);var Je=e(U,2);Ze(Je,{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/model_doc/edgetam_video.md"}),s(2),V(ae,C),We()}export{Ye as component};

Xet Storage Details

Size:
84.7 kB
·
Xet hash:
dc14d722fa20ea700e33d432aedf18c7e3c04be54aeb9d670fc05509ba34c53d

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