モデル概要
モデル特徴
モデル能力
使用事例
🚀 任意の画像や動画を詳細にキャプション付けするモデル
Describe Anythingは、画像や動画の指定された領域に詳細なキャプションを付けることができるモデルです。このモデルは、研究や開発のために設計されており、非商用利用に対応しています。
関連リンク
🚀 クイックスタート
この自己完結型モデルを使用した推論のサンプルコードは以下の通りです。
# Copyright 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# SPDX-License-Identifier: Apache-2.0
import torch
import numpy as np
from PIL import Image
from transformers import SamModel, SamProcessor, AutoModel
import cv2
import requests
from io import BytesIO
def apply_sam(image, input_points=None, input_boxes=None, input_labels=None):
inputs = sam_processor(image, input_points=input_points, input_boxes=input_boxes,
input_labels=input_labels, return_tensors="pt").to(device)
with torch.no_grad():
outputs = sam_model(**inputs)
masks = sam_processor.image_processor.post_process_masks(
outputs.pred_masks.cpu(),
inputs["original_sizes"].cpu(),
inputs["reshaped_input_sizes"].cpu()
)[0][0]
scores = outputs.iou_scores[0, 0]
mask_selection_index = scores.argmax()
mask_np = masks[mask_selection_index].numpy()
return mask_np
def add_contour(img, mask, input_points=None, input_boxes=None):
img = img.copy()
mask = mask.astype(np.uint8) * 255
contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(img, contours, -1, (1.0, 1.0, 1.0), thickness=6)
if input_points is not None:
for points in input_points:
for x, y in points:
cv2.circle(img, (int(x), int(y)), radius=10, color=(1.0, 0.0, 0.0), thickness=-1)
cv2.circle(img, (int(x), int(y)), radius=10, color=(1.0, 1.0, 1.0), thickness=2)
if input_boxes is not None:
for box_batch in input_boxes:
for box in box_batch:
x1, y1, x2, y2 = map(int, box)
cv2.rectangle(img, (x1, y1), (x2, y2), color=(1.0, 1.0, 1.0), thickness=4)
cv2.rectangle(img, (x1, y1), (x2, y2), color=(1.0, 0.0, 0.0), thickness=2)
return img
def print_streaming(text):
print(text, end="", flush=True)
if __name__ == '__main__':
# Download the image via HTTP
image_url = 'https://github.com/NVlabs/describe-anything/blob/main/images/1.jpg?raw=true'
response = requests.get(image_url)
img = Image.open(BytesIO(response.content)).convert('RGB')
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
sam_model = SamModel.from_pretrained("facebook/sam-vit-huge").to(device)
sam_processor = SamProcessor.from_pretrained("facebook/sam-vit-huge")
image_size = img.size # (width, height)
# Initialize DAM model once
model = AutoModel.from_pretrained(
'nvidia/DAM-3B-Self-Contained',
trust_remote_code=True,
torch_dtype='torch.float16'
).to(device)
dam = model.init_dam(conv_mode='v1', prompt_mode='full+focal_crop')
# Define two runs: one with points, one with box
runs = [
{
'use_box': False,
'points': [[1172, 812], [1572, 800]],
'output_image_path': 'output_visualization_points.png'
},
{
'use_box': True,
'box': [800, 500, 1800, 1000],
'output_image_path': 'output_visualization_box.png'
}
]
for run in runs:
if run['use_box']:
# Prepare box input
coords = run['box']
input_boxes = [[coords]]
print(f"Running inference with input_boxes: {input_boxes}")
mask_np = apply_sam(img, input_boxes=input_boxes)
vis_points = None
vis_boxes = input_boxes
else:
# Prepare point input
pts = run['points']
input_points = [pts]
input_labels = [[1] * len(pts)]
print(f"Running inference with input_points: {input_points}")
mask_np = apply_sam(img, input_points=input_points, input_labels=input_labels)
vis_points = input_points
vis_boxes = None
# Convert mask and describe
mask = Image.fromarray((mask_np * 255).astype(np.uint8))
print("Description:")
for token in dam.get_description(
img,
mask,
'<image>\nDescribe the masked region in detail.',
streaming=True,
temperature=0.2,
top_p=0.5,
num_beams=1,
max_new_tokens=512
):
print_streaming(token)
print() # newline
# Save visualization with contour
img_np = np.asarray(img).astype(float) / 255.0
img_with_contour_np = add_contour(img_np, mask_np,
input_points=vis_points,
input_boxes=vis_boxes)
img_with_contour_pil = Image.fromarray((img_with_contour_np * 255.0).astype(np.uint8))
img_with_contour_pil.save(run['output_image_path'])
print(f"Output image with contour saved as {run['output_image_path']}")
✨ 主な機能
Describe Anything Model 3B (DAM-3B) は、画像内のユーザー指定領域(点、ボックス、スクライブル、マスク)を入力として受け取り、その領域の詳細なキャプションを生成します。このモデルは、新しいフォーカルプロンプトとゲート付きクロスアテンションで強化された局所化ビジョンバックボーンを使用して、全画像コンテキストと細粒度の局所詳細を統合しています。
📚 ドキュメント
モデルの説明
Describe Anything Model 3B (DAM-3B) は、画像内のユーザー指定領域を入力として受け取り、その領域の詳細なキャプションを生成します。このモデルは、研究と開発のみを目的としており、非商用利用に対応しています。
ライセンス
想定される使用目的
このモデルは、Describe Anythingモデルの理解と使用を示し、促進することを目的としています。主に研究と非商用目的で使用されるべきです。
モデルアーキテクチャ
属性 | 詳情 |
---|---|
モデルタイプ | Transformer |
ネットワークアーキテクチャ | ViTとLlama |
このモデルは VILA-1.5 をベースに開発されています。モデルパラメータは3Bあります。
入力
属性 | 詳情 |
---|---|
入力タイプ | 画像、テキスト、バイナリマスク |
入力フォーマット | RGB画像、バイナリマスク |
入力パラメータ | 2D画像、2Dバイナリマスク |
その他の入力関連プロパティ | RGB画像は3チャンネル、バイナリマスクは1チャンネル。解像度は384x384です。 |
出力
属性 | 詳情 |
---|---|
出力タイプ | テキスト |
出力フォーマット | 文字列 |
出力パラメータ | 1Dテキスト |
その他の出力関連プロパティ | ビジュアル領域の詳細な説明 |
サポートされるハードウェアマイクロアーキテクチャ互換性:
- NVIDIA Ampere
- NVIDIA Hopper
- NVIDIA Lovelace
推奨/サポートされるオペレーティングシステム:
- Linux
学習データセット
Describe Anything Training Datasets
評価データセット
モデルは詳細な局所化キャプショニングベンチマーク DLC-Bench で評価されています。
推論
PyTorch
倫理的な考慮事項
NVIDIAは、信頼できるAIは共有の責任であると考えており、幅広いAIアプリケーションの開発を可能にするためのポリシーと慣行を確立しています。サービス利用規約に従ってダウンロードまたは使用する場合、開発者は内部のモデルチームと協力して、このモデルが関連する業界やユースケースの要件を満たし、予期しない製品の誤用に対応することを確認する必要があります。
セキュリティバグやNVIDIA AIに関する懸念事項は、こちら から報告してください。
📄 ライセンス
このモデルは NVIDIA Noncommercial License の下で提供されています。
📖 引用
もしこのリポジトリの研究や実装を使用した場合、または役に立ったと感じた場合は、以下のように引用してください。
@article{lian2025describe,
title={Describe Anything: Detailed Localized Image and Video Captioning},
author={Long Lian and Yifan Ding and Yunhao Ge and Sifei Liu and Hanzi Mao and Boyi Li and Marco Pavone and Ming-Yu Liu and Trevor Darrell and Adam Yala and Yin Cui},
journal={arXiv preprint arXiv:2504.16072},
year={2025}
}








