Transformers documentation
TIPSv2 DPT
이 모델은 2026-04-13에 HF papers에 게시되었으며, 2026-07-06에 Hugging Face Transformers에 기여되었습니다.
TIPSv2 DPT
개요
Dense prediction transformer head(DPT)를 사용하는 TIPSv2, 자세한 내용은 TIPSv2 문서를 참고하세요.
이 모델은 guarin이(가) 기여했습니다. 원본 코드는 여기에서 찾을 수 있습니다.
모든 원본 TIPSv2 DPT 체크포인트는 TIPSv2 컬렉션에서 찾을 수 있습니다.
TIPSv2 비전 및 언어 백본과 제로 샷 이미지 분류에 대해서는 TIPSv2를 참고하세요.
from transformers import pipeline
pipe = pipeline(task="depth-estimation", model="google/tipsv2-b14-dpt", device_map="auto")
out = pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
out["depth"] # PIL Image normalized to [min, max] of predicted_depth
# Visualization
import matplotlib.pyplot as plt
from transformers.image_utils import load_image
image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
figure, axes = plt.subplots(1, 2, figsize=(10, 5))
axes[0].imshow(image)
axes[1].imshow(out["depth"])
axes[1].set_title("Depth")
for axis in axes:
axis.axis("off")
plt.show()
from transformers import pipeline
pipe = pipeline(task="image-segmentation", model="google/tipsv2-b14-dpt", device_map="auto")
out = pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
out[0]["label"] # string class label
out[0]["mask"] # PIL Image with binary mask set to class id
# Visualization
import matplotlib.pyplot as plt
from transformers.image_utils import load_image
image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
figure, axes = plt.subplots(1, 2, figsize=(10, 5))
axes[0].imshow(image)
axes[1].imshow(out[0]["mask"], cmap="gray")
axes[1].set_title(out[0]["label"])
for axis in axes:
axis.axis("off")
plt.show()
Tipsv2DptForDensePrediction를 사용하면 공유된 backbone에서 단일 forward pass로 세 가지 작업(깊이, 노멀, 분할)을 모두 실행할 수 있습니다.
import torch
from transformers import Tipsv2DptForDensePrediction, AutoImageProcessor
from transformers.image_utils import load_image
model_id = "google/tipsv2-b14-dpt"
model = Tipsv2DptForDensePrediction.from_pretrained(model_id, device_map="auto")
image_processor = AutoImageProcessor.from_pretrained(model_id)
image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
inputs = image_processor(images=image, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model(**inputs)
outputs.predicted_depth # (batch_size, height, width) tensor with predicted depth in meters
outputs.normals # (batch_size, 3, height, width) tensor with normals in XYZ format (unnormalized)
outputs.segmentation_logits # # (batch_size, config.num_labels, height, width) tensor with segmentation logits
depth_results = image_processor.post_process_depth_estimation(outputs, target_sizes=[(image.height, image.width)])
normal_results = image_processor.post_process_normal_estimation(outputs, target_sizes=[(image.height, image.width)])
segmentation_results = image_processor.post_process_semantic_segmentation(outputs, target_sizes=[(image.height, image.width)])
predicted_depth = depth_results[0]["predicted_depth"] # (height, width) tensor with predicted depth in meters
normals = normal_results[0]["normals"] # (3, height, width) tensor with normals in XYZ format (L2-normalized)
segmentation = segmentation_results[0] # (height, width) tensor with class ids
# Visualization
import matplotlib.pyplot as plt
# Convert L2-normalized normals in [-1, 1] to RGB in [0, 255]
normals_rgb = ((normals + 1.0) / 2.0 * 255.0).clamp(0, 255).to(torch.uint8)
figure, axes = plt.subplots(2, 2, figsize=(10, 6))
axes[0, 0].imshow(image)
axes[0, 1].imshow(predicted_depth.cpu())
axes[0, 1].set_title("Depth")
axes[1, 0].imshow(normals_rgb.permute(1, 2, 0).cpu())
axes[1, 0].set_title("Normals")
axes[1, 1].imshow(segmentation.cpu())
axes[1, 1].set_title("Segmentation")
for axis in axes.flat:
axis.axis("off")
plt.show()
import torch
from transformers import AutoModelForDepthEstimation, AutoImageProcessor
from transformers.image_utils import load_image
model_id = "google/tipsv2-b14-dpt"
model = AutoModelForDepthEstimation.from_pretrained(model_id, device_map="auto")
image_processor = AutoImageProcessor.from_pretrained(model_id)
image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
inputs = image_processor(images=image, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model(**inputs)
results = image_processor.post_process_depth_estimation(outputs, target_sizes=[(image.height, image.width)])
predicted_depth = results[0]["predicted_depth"] # (height, width) tensor with predicted depth in meters
# Visualization
import matplotlib.pyplot as plt
figure, axes = plt.subplots(1, 2, figsize=(10, 5))
axes[0].imshow(image)
axes[1].imshow(predicted_depth.cpu())
axes[1].set_title("Depth")
for axis in axes:
axis.axis("off")
plt.show()
import torch
from transformers import Tipsv2DptForNormalEstimation, AutoImageProcessor
from transformers.image_utils import load_image
model_id = "google/tipsv2-b14-dpt"
model = Tipsv2DptForNormalEstimation.from_pretrained(model_id, device_map="auto")
image_processor = AutoImageProcessor.from_pretrained(model_id)
image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
inputs = image_processor(images=image, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model(**inputs)
results = image_processor.post_process_normal_estimation(outputs, target_sizes=[(image.height, image.width)])
normals = results[0]["normals"] # (3, height, width) tensor with normals in XYZ format (L2-normalized)
# Visualization
import matplotlib.pyplot as plt
# Convert L2-normalized normals in [-1, 1] to RGB in [0, 255]
normals_rgb = ((normals + 1.0) / 2.0 * 255.0).clamp(0, 255).to(torch.uint8)
figure, axes = plt.subplots(1, 2, figsize=(10, 5))
axes[0].imshow(image)
axes[1].imshow(normals_rgb.permute(1, 2, 0).cpu())
axes[1].set_title("Normals")
for axis in axes:
axis.axis("off")
plt.show()
import torch
from transformers import AutoModelForSemanticSegmentation, AutoImageProcessor
from transformers.image_utils import load_image
model_id = "google/tipsv2-b14-dpt"
model = AutoModelForSemanticSegmentation.from_pretrained(model_id, device_map="auto")
image_processor = AutoImageProcessor.from_pretrained(model_id)
image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
inputs = image_processor(images=image, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model(**inputs)
results = image_processor.post_process_semantic_segmentation(outputs, target_sizes=[(image.height, image.width)])
segmentation_map = results[0] # (height, width) tensor with class ids
# Visualization
import matplotlib.pyplot as plt
figure, axes = plt.subplots(1, 2, figsize=(10, 5))
axes[0].imshow(image)
axes[1].imshow(segmentation_map.cpu())
axes[1].set_title("Segmentation")
for axis in axes:
axis.axis("off")
plt.show()
The input is a single word "Notes". 참고
- Tipsv2DptForDensePrediction은 단일 공유 backbone의 forward pass를 실행하여
predicted_depth,normals,segmentation_logits세 가지 출력을 동시에 생성합니다. 동일한 이미지에 대해 세 가지 작업을 모두 수행해야 할 때 사용하세요. - Tipsv2DptForDepthEstimation, Tipsv2DptForNormalEstimation, Tipsv2DptForSemanticSegmentation는 다른 헤드를 제거한 단일 작업 변형입니다. 파이프라인 또는 단일 작업 추론에 사용하세요.
Tipsv2DptConfig
class transformers.Tipsv2DptConfig
< source >( transformers_version: str | None = Nonearchitectures: list[str] | None = Noneoutput_hidden_states: bool | None = Falsereturn_dict: bool | None = Truedtype: str | torch.dtype | None = Nonechunk_size_feed_forward: int = 0is_encoder_decoder: bool = Falseid2label: dict[int, str] | dict[str, str] | None = Nonelabel2id: dict[str, int] | dict[str, str] | None = Noneproblem_type: Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = Nonebackbone_config: dict | transformers.configuration_utils.PreTrainedConfig | None = Noneneck_hidden_sizes: list[int] | tuple[int, ...] | None = Nonefusion_hidden_size: int = 256reassemble_factors: list[int | float] | tuple[int | float, ...] | None = Nonereadout_activation: str = 'gelu_pytorch_tanh'num_depth_bins: int = 256min_depth: float = 0.001max_depth: float = 10.0depth_decoder_activation: str = 'relu'semantic_loss_ignore_index: int = 255 )
매개변수
- backbone_config (
Union[dict, ~configuration_utils.PreTrainedConfig], 선택) — backbone 모델의 설정입니다. - neck_hidden_sizes (
list[int], 선택 사항, 기본값[96, 192, 384, 768]) — backbone의 feature map을 투영할 hidden size입니다. - fusion_hidden_size (
int, 선택 사항, 기본값 256) — 퓨전 이전의 채널 수입니다. - reassemble_factors (
list[float], 선택 사항, 기본값[4, 2, 1, 0.5]) — reassemble 레이어의 업/다운샘플링 계수입니다. - readout_activation (
str, 선택 사항, 기본값"gelu_pytorch_tanh") — readout projection layer 이후에 적용되는 활성화 함수입니다. - num_depth_bins (
int, 선택 사항, 기본값 256) — 깊이 추정 헤드에 사용되는 깊이 빈의 수입니다. - min_depth (
float, 선택 사항, 기본값 0.001) — 깊이 bin 계산에 사용되는 최소 깊이 값(미터). - max_depth (
float, 선택 사항, 기본값 10.0) — 깊이 빈 계산에 사용되는 최대 깊이 값(미터). - depth_decoder_activation (
str, 선택 사항, 기본값"relu") — 깊이 디코더 투영 레이어 이후에 적용되는 활성화 함수입니다. - semantic_loss_ignore_index (
int, 선택 사항, 기본값 255) — 의미 분할을 위한 교차 엔트로피 손실에서 무시할 레이블 인덱스.
이것은 Tipsv2 DptModel의 설정을 저장하기 위한 설정 클래스입니다. 지정된 인자에 따라 Tipsv2 Dpt 모델을 초기화하여 모델 아키텍처를 정의하는 데 사용됩니다. 기본값으로 설정을 초기화하면 google/tipsv2-b14-dpt와 유사한 설정이 생성됩니다.
Configuration 객체는 PreTrainedConfig를 상속하며 모델 출력을 제어하는 데 사용할 수 있습니다. 자세한 내용은 PreTrainedConfig의 문서를 참고하세요.
Tipsv2DptImageProcessor
class transformers.Tipsv2DptImageProcessor
< source >( **kwargs: *<class 'transformers.processing_utils.ImagesKwargs'> )
매개변수
- do_convert_rgb (
bool, kwargs, 선택 사항, 기본값True) — 이미지를 RGB로 변환할지 여부. - do_resize (
bool, kwargs, 선택 사항, 기본값True) — 이미지를 리사이즈할지 여부. - size (
Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs, 기본값{'height' -- 448, 'width': 448}): 모델에 전달되는 최대 입력 차원을 설명합니다. - default_to_square (
bool, kwargs, 선택 사항, 기본값True) — size가 int인 경우 리사이즈 시 정사각형 이미지로 기본 설정할지 여부입니다. - crop_size (
Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) —center_crop을 적용한 후 출력 이미지의 크기. - resample (
Annotated[Union[int, PILImageResampling, NoneType], None], kwargs, 기본값2) — 이미지 크기를 조정할 때 사용할 리샘플링 필터입니다.PILImageResamplingenum 중 하나를 사용할 수 있습니다.do_resize가True로 설정된 경우에만 효과가 있습니다. - do_rescale (
bool, kwargs, 선택, 기본값True) — 이미지를 다시 스케일링할지 여부. - rescale_factor (
float, kwargs, 선택 사항, 기본값0.00392156862745098) —do_rescale이True로 설정된 경우 이미지를 재조정(rescale)하는 데 사용할 재조정 계수입니다. - do_normalize (
bool, kwargs, 선택, 기본값False) — 이미지를 정규화할지 여부입니다. - image_mean (
Union[float, list[float], tuple[float, ...]], kwargs, 선택) — 정규화에 사용할 이미지 평균입니다.do_normalize가True로 설정된 경우에만 효과가 있습니다. - image_std (
Union[float, list[float], tuple[float, ...]], kwargs, 선택) — 정규화에 사용할 이미지 표준 편차.do_normalize가True로 설정된 경우에만 효과가 있습니다. - do_pad (
bool, kwargs, optional) — 이미지를 패딩할지 여부입니다. 패딩은 배치 내 가장 큰 크기로 수행하거나, 이미지마다 고정된 정사각형 크기로 수행합니다. 정확한 패딩 전략은 모델에 따라 달라집니다. - pad_size (
Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — 이미지를 패딩할{"height": int, "width" int}크기를 지정합니다. 전처리용으로 제공된 모든 이미지 크기보다 커야 합니다.pad_size가 제공되지 않으면, 배치 내 가장 큰 높이와 너비로 패딩됩니다.do_pad=True.일 때만 적용됩니다. - do_center_crop (
bool, kwargs, 선택) — 이미지를 중앙으로 크롭할지 여부. - data_format (
Union[str, ~image_utils.ChannelDimension], kwargs, 선택 사항) —ChannelDimension.FIRST만 지원됩니다. 느린 프로세서와의 호환성을 위해 추가되었습니다. - input_data_format (
Union[str, ~image_utils.ChannelDimension], kwargs, 선택 사항) — 입력 이미지의 채널 차원 형식입니다. 설정되지 않으면 입력 이미지에서 채널 차원 형식을 추론합니다. 다음 중 하나일 수 있습니다:"channels_first"또는ChannelDimension.FIRST: (num_channels, height, width) 형식의 이미지."channels_last"또는ChannelDimension.LAST: (height, width, num_channels) 형식의 이미지."none"또는ChannelDimension.NONE: (height, width) 형식의 이미지.
- device (
Annotated[Union[str, torch.device, NoneType], None], kwargs) — 동영상을 처리할 장치입니다. 설정되지 않은 경우, 입력 동영상에서 장치를 추론합니다. - return_tensors (
Annotated[str | ~utils.generic.TensorType | None, None], kwargs) —'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택 사항) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다. - Returns
'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. —
Tipsv2DptImageProcessor 이미지 프로세서를 생성합니다.
disable_grouping (bool, kwargs, 선택):
이미지를 크기로 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부.
None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. image_seq_length (int, kwargs, 선택):
입력에서 각 이미지에 사용할 이미지 토큰의 수.
하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.
preprocess
< source >( images: typing.Union[ForwardRef('PIL.Image.Image'), numpy.ndarray, ForwardRef('torch.Tensor'), list['PIL.Image.Image'], list[numpy.ndarray], list['torch.Tensor']]*argsimage_like_kwargs: dict[str, typing.Any] | None = None**kwargs: *<class 'transformers.processing_utils.ImagesKwargs'> ) → ~image_processing_base.BatchFeature
매개변수
- images (
Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]) — 전처리할 이미지. 픽셀 값이 0에서 255 범위로 이루어진 단일 이미지 또는 배치 이미지를 기대합니다. 픽셀 값이 0에서 1 사이인 이미지를 전달하는 경우do_rescale=False로 설정하세요. - image_like_kwargs (
dict[str, Any], 선택) — 추가 이미지 유사 입력을 전처리할 때 사용하는 개발자용 플래그입니다. 입력을 kwarg로 전달하는 것이 작동하지 않는 경우에만 사용하세요. 예를 들어,preprocess(images, masks=masks)가 권장되는 옵션이지만 일부 모델에서는 인자 우선순위 문제가 발생할 수 있습니다. 이러한 경우 대신preprocess(images, image_like_inputs={"masks": masks})를 사용할 수 있습니다. - do_convert_rgb (
bool, kwargs, 선택 사항) — 이미지를 RGB로 변환할지 여부입니다. - do_resize (
bool, kwargs, 선택) — 이미지를 리사이즈할지 여부. - size (
Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — 모델의 최대 입력 차원을 설명합니다. - default_to_square (
bool, kwargs, 선택 사항) — size가 int인 경우 리사이즈 시 정사각형 이미지로 기본 설정할지 여부. - crop_size (
Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) —center_crop을 적용한 후 출력 이미지의 크기. - resample (
Annotated[Union[int, PILImageResampling, NoneType], None], kwargs) — 이미지를 리사이즈할 경우 사용할 리샘플링 필터입니다. 이는PILImageResamplingenum 중 하나일 수 있습니다.do_resize가True로 설정된 경우에만 효과가 있습니다. - do_rescale (
bool, kwargs, 선택 사항) — 이미지를 다시 스케일링할지 여부입니다. - rescale_factor (
float, kwargs, optional) —do_rescale이True로 설정된 경우 이미지를 리스케일하기 위한 리스케일 팩터입니다. - do_normalize (
bool, kwargs, optional) — 이미지를 정규화할지 여부. - image_mean (
Union[float, list[float], tuple[float, ...]], kwargs, 선택) — 정규화에 사용할 이미지 평균입니다.do_normalize가True로 설정된 경우에만 효과가 있습니다. - image_std (
Union[float, list[float], tuple[float, ...]], kwargs, 선택) — 정규화에 사용할 이미지 표준 편차.do_normalize가True로 설정된 경우에만 효과가 있습니다. - do_pad (
bool, kwargs, optional) — 이미지를 패딩할지 여부입니다. 패딩은 배치 내 가장 큰 크기로 수행하거나, 이미지마다 고정된 정사각형 크기로 수행합니다. 정확한 패딩 전략은 모델에 따라 달라집니다. - pad_size (
Annotated[int | list[int] | tuple[int, ...] | dict[str, int] | None, None], kwargs) — 이미지를 패딩할{"height": int, "width" int}크기를 지정합니다. 전처리용으로 제공된 모든 이미지 크기보다 커야 합니다.pad_size가 제공되지 않으면, 배치 내 가장 큰 높이와 너비로 패딩됩니다.do_pad=True.일 때만 적용됩니다. - do_center_crop (
bool, kwargs, 선택) — 이미지를 중앙으로 크롭할지 여부. - data_format (
Union[str, ~image_utils.ChannelDimension], kwargs, 선택 사항) —ChannelDimension.FIRST만 지원됩니다. 느린 프로세서와의 호환성을 위해 추가되었습니다. - input_data_format (
Union[str, ~image_utils.ChannelDimension], kwargs, 선택 사항) — 입력 이미지의 채널 차원 형식입니다. 설정되지 않으면 입력 이미지에서 채널 차원 형식을 추론합니다. 다음 중 하나일 수 있습니다:"channels_first"또는ChannelDimension.FIRST: (num_channels, height, width) 형식의 이미지."channels_last"또는ChannelDimension.LAST: (height, width, num_channels) 형식의 이미지."none"또는ChannelDimension.NONE: (height, width) 형식의 이미지.
- device (
Annotated[Union[str, torch.device, NoneType], None], kwargs) — 동영상을 처리할 장치입니다. 설정되지 않은 경우, 입력 동영상에서 장치를 추론합니다. - return_tensors (
Annotated[str | ~utils.generic.TensorType | None, None], kwargs) —'pt'로 설정된 경우 스택된 텐서를 반환하고, 그렇지 않으면 텐서 목록을 반환합니다. - disable_grouping (
bool, kwargs, 선택 사항) — 이미지를 크기에 따라 그룹화하는 것을 비활성화하여 배치 대신 개별적으로 처리할지 여부입니다. None인 경우, 이미지가 CPU에 있으면 True, 그렇지 않으면 False로 설정됩니다. 이 선택은 https://github.com/huggingface/transformers/pull/38157에 자세히 설명된 경험적 관찰에 기반합니다. - image_seq_length (
int, kwargs, 선택 사항) — 입력에서 각 이미지에 사용할 이미지 토큰의 수입니다. 하위 호환성을 위해 추가되었지만, 향후 모델에서는 프로세서 속성으로 설정해야 합니다.
반환값
~image_processing_base.BatchFeature
- data (
dict) — call 메서드가 반환하는 리스트/배열/텐서 딕셔너리(‘pixel_values’ 등). - tensor_type (
Union[None, str, TensorType], 선택 사항) — 초기화 시 PyTorch/Numpy 텐서에서 정수 목록을 변환하려면 여기에 tensor_type를 지정할 수 있습니다.
이미지 또는 이미지 배치(batch)를 전처리합니다.
post_process_depth_estimation
< source >( outputstarget_sizes: transformers.utils.generic.TensorType | list[tuple[int, int]] | None = None ) → list[dict[str, torch.Tensor]]
매개변수
- outputs (
DepthEstimatorOutput또는Tipsv2DptDensePredictorOutput) — 모델의 원시 출력입니다. - target_sizes (TensorType 또는
list[tuple[int, int]], 선택 사항) — 배치 내 각 이미지의 목표 크기(높이, 너비)를 포함하는(batch_size, 2)모양의 Tensor 또는 튜플(tuple[int, int]) 목록입니다. None으로 두면 예측 결과가 리사이즈되지 않습니다.
반환값
list[dict[str, torch.Tensor]]
처리된 깊이 예측을 나타내는 텐서 딕셔너리의 목록입니다.
Tipsv2DptForDepthEstimation 또는 Tipsv2DptForDensePrediction의 출력을 최종 깊이 예측으로 변환합니다.
post_process_normal_estimation
< source >( outputstarget_sizes: transformers.utils.generic.TensorType | list[tuple[int, int]] | None = None )
매개변수
- outputs (
Tipsv2DptNormalEstimatorOutput또는Tipsv2DptDensePredictorOutput) — 모델의 원시 출력입니다. - target_sizes (TensorType 또는
list[tuple[int, int]], 선택 사항) — 배치 내 각 이미지의 목표 크기(높이, 너비)를 포함하는(batch_size, 2)모양의 Tensor 또는 튜플(tuple[int, int]) 목록입니다. None으로 두면 예측 결과가 리사이즈되지 않습니다.
Tipsv2DptForNormalEstimation 또는 Tipsv2DptForDensePrediction의 출력을 L2 정규화된 표면 법선 맵으로 변환합니다.
post_process_semantic_segmentation
< source >( outputstarget_sizes: transformers.utils.generic.TensorType | list[tuple[int, int]] | None = Nonereturn_segmentation_scores: bool = False ) → list[torch.Tensor] or list[SemanticSegmentationPostProcessorOutput]
매개변수
- outputs (
SemanticSegmenterOutput또는Tipsv2DptDensePredictorOutput) — 모델의 원시 출력입니다. - target_sizes [(TensorType 또는
list[tuple[int, int]], optional) —(batch_size, 2)형태의 Tensor 또는 배치 내 각 이미지의 목표 크기(높이, 너비)를 포함하는 튜플(tuple[int, int])의 리스트입니다. None으로 두면 예측 결과가 리사이즈되지 않습니다. - return_segmentation_scores (
bool, 선택 사항, 기본값False) — 분할 맵과 함께 분할 점수를 반환할지 여부입니다.True인 경우, 반환된 리스트의 각 요소는SemanticSegmentationPostProcessorOutput이며,segmentation필드(클래스 ID, shape(height, width))와segmentation_scores필드(shape(num_classes, height, width))를 포함합니다.
반환값
list[torch.Tensor] 또는 list[SemanticSegmentationPostProcessorOutput]
return_segmentation_scores=False(기본값)인 경우, 각 항목이 클래스 ID를 가진 (height, width) 형태의 분할 맵인 길이 batch_size의 리스트를 반환합니다. return_segmentation_scores=True인 경우, segmentation(클래스 ID, 형태 (height, width))와 segmentation_scores(형태 (num_classes, height, width)) 필드를 가진 SemanticSegmentationPostProcessorOutput의 리스트를 반환합니다. 두 경우 모두 (height, width)는 대상 크기(target_sizes가 지정된 경우)에 해당합니다.
Tipsv2DptForSemanticSegmentation 또는 Tipsv2DptForDensePrediction의 출력을 의미 분할 맵으로 변환합니다.
Tipsv2DptForDensePrediction
class transformers.Tipsv2DptForDensePrediction
< source >( config: Tipsv2DptConfig )
매개변수
- config (Tipsv2DptConfig) — 모델의 모든 매개변수를 포함하는 모델 구성 클래스입니다. 구성 파일로 초기화하는 것은 모델과 관련된 가중치를 로드하지 않으며, 구성만 로드합니다. 모델 가중치를 로드하려면 from_pretrained() 메서드를 확인하세요.
깊이 추정, 표면 법선 추정, 의미 분할을 위한 세 개의 독립된 헤드를 갖춘 TIPSv2-DPT 모델 — 단일 공유 백본의 전방 전파를 실행합니다.
이 모델은 PreTrainedModel에서 상속됩니다. 라이브러리가 모든 모델에 대해 구현하는 일반적 메서드(다운로드 또는 저장, 입력 임베딩 크기 조정, 헤드 프루닝 등)에 대한 세부 사항은 상위 클래스 문서를 확인하세요.
이 모델은 또한 PyTorch torch.nn.Module의 하위 클래스입니다. 일반적인 PyTorch Module처럼 사용하며, 일반적인 사용법 및 동작과 관련된 모든 사항은 PyTorch 문서를 참조하세요.
forward
< source >( pixel_values: Tensor**kwargs: Unpack ) → Tipsv2DptDensePredictorOutput or tuple(torch.Tensor)
매개변수
- pixel_values (
torch.Tensor, shape(batch_size, num_channels, image_size, image_size)) — 입력 이미지에 해당하는 텐서입니다. 픽셀 값은 Tipsv2DptImageProcessor를 사용하여 얻을 수 있습니다. 자세한 내용은 Tipsv2DptImageProcessor.call()를 참조하세요 (processor_class는 이미지 처리에 Tipsv2DptImageProcessor를 사용합니다).
반환값
Tipsv2DptDensePredictorOutput 또는 tuple(torch.Tensor)
Tipsv2DptDensePredictorOutput 또는 torch.Tensor의 튜플(return_dict=False가 전달되었거나 config.return_dict=False인 경우)로, 구성(Tipsv2DptConfig)과 입력에 따라 다양한 요소를 포함합니다.
Tipsv2DptForDensePrediction의 forward 메서드는 __call__ 특수 메서드를 오버라이드합니다.
이 함수 내에서 forward pass의 레시피를 정의해야 하지만, 이후에는 이 함수 대신
Module인스턴스를 호출해야 합니다. 전자는 전처리 및 후처리 단계를 실행하는 것을 처리하는 반면, 후자는 이를 조용히 무시하기 때문입니다.
predicted_depth (
torch.Tensor, shape(batch_size, height, width), 선택 사항) — 각 픽셀에 대한 예측된 깊이.normals (
torch.Tensor, shape(batch_size, 3, height, width)) — 정규화되지 않은 원시 normal map 예측 값.segmentation_logits (
torch.Tensor, shape(batch_size, config.num_labels, height, width)) — 각 픽셀에 대한 분류 점수.반환되는 logits는 입력으로 전달된 `pixel_values`와 반드시 동일한 크기를 가질 필요는 없습니다. 이는 사용자가 후처리 단계에서 logits를 원본 이미지 크기로 리사이즈할 때 두 번의 보간을 수행하여 품질이 저하되는 것을 방지하기 위한 것입니다. 항상 logits의 shape을 확인하고 필요에 따라 리사이즈해야 합니다.
hidden_states (
tuple[torch.Tensor, ...], 선택 사항,output_hidden_states=True가 전달되거나config.output_hidden_states=True인 경우 반환됨) —torch.Tensor의 튜플(모델에 임베딩 레이어가 있는 경우 임베딩의 출력에 대한 것 1개 + 각 레이어의 출력에 대한 것 1개)로, 모양은(batch_size, sequence_length, hidden_size)입니다.각 레이어의 출력에서 모델의 Hidden-states와 선택적 초기 임베딩 출력을 포함합니다.
attentions (
tuple[torch.Tensor, ...], 선택 사항,output_attentions=True가 전달되었거나config.output_attentions=True인 경우 반환됨) — 각 레이어마다 하나씩 포함된torch.Tensor의 튜플로, 모양은(batch_size, num_heads, sequence_length, sequence_length)입니다.self-attention 헤드에서 가중 평균을 계산하는 데 사용되는 attention softmax 이후의 attention 가중치.
예:
>>> import torch
>>> from transformers import Tipsv2DptForDensePrediction, AutoImageProcessor
>>> from transformers.image_utils import load_image
>>> model_id = "google/tipsv2-b14-dpt"
>>> model = Tipsv2DptForDensePrediction.from_pretrained(model_id, device_map="auto")
>>> image_processor = AutoImageProcessor.from_pretrained(model_id)
>>> image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
>>> inputs = image_processor(images=image, return_tensors="pt").to(model.device)
>>> with torch.no_grad():
... outputs = model(**inputs)
>>> # outputs.predicted_depth: (batch_size, height, width) tensor with predicted depth in meters
>>> # outputs.normals: (batch_size, 3, height, width) tensor with normals in XYZ format (unnormalized)
>>> # outputs.segmentation_logits: (batch_size, config.num_labels, height, width) tensor with segmentation logits
>>> depth_results = image_processor.post_process_depth_estimation(outputs, target_sizes=[(image.height, image.width)])
>>> normal_results = image_processor.post_process_normal_estimation(outputs, target_sizes=[(image.height, image.width)])
>>> segmentation_results = image_processor.post_process_semantic_segmentation(outputs, target_sizes=[(image.height, image.width)])
>>> predicted_depth = depth_results[0]["predicted_depth"] # (height, width) tensor with predicted depth in meters
>>> normals = normal_results[0]["normals"] # (3, height, width) tensor with normals in XYZ format (L2-normalized)
>>> segmentation = segmentation_results[0] # (height, width) tensor with class idsTipsv2DptForDepthEstimation
class transformers.Tipsv2DptForDepthEstimation
< source >( config: Tipsv2DptConfig )
매개변수
- config (Tipsv2DptConfig) — 모델의 모든 매개변수를 포함하는 모델 구성 클래스입니다. 구성 파일로 초기화하는 것은 모델과 관련된 가중치를 로드하지 않으며, 구성만 로드합니다. 모델 가중치를 로드하려면 from_pretrained() 메서드를 확인하세요.
monocular depth estimation 헤드를 갖춘 TIPSv2-DPT 모델.
이 모델은 PreTrainedModel에서 상속됩니다. 라이브러리가 모든 모델에 대해 구현하는 일반적 메서드(다운로드 또는 저장, 입력 임베딩 크기 조정, 헤드 프루닝 등)에 대한 세부 사항은 상위 클래스 문서를 확인하세요.
이 모델은 또한 PyTorch torch.nn.Module의 하위 클래스입니다. 일반적인 PyTorch Module처럼 사용하며, 일반적인 사용법 및 동작과 관련된 모든 사항은 PyTorch 문서를 참조하세요.
forward
< source >( pixel_values: Tensorlabels: typing.Optional[torch.Tensor] = None**kwargs: Unpack ) → DepthEstimatorOutput or tuple(torch.Tensor)
매개변수
- pixel_values (
torch.Tensor, shape(batch_size, num_channels, image_size, image_size)) — 입력 이미지에 해당하는 텐서입니다. 픽셀 값은 Tipsv2DptImageProcessor를 사용하여 얻을 수 있습니다. 자세한 내용은 Tipsv2DptImageProcessor.call()를 참조하세요 (processor_class는 이미지 처리에 Tipsv2DptImageProcessor를 사용합니다). - labels (
torch.LongTensor, shape(batch_size, height, width), 선택 사항) — 손실을 계산하기 위한 ground truth depth estimation map입니다.
반환값
DepthEstimatorOutput 또는 tuple(torch.Tensor)
torch.Tensor의 튜플 또는 DepthEstimatorOutput입니다. return_dict=False가 전달되었거나 config.return_dict=False인 경우, 구성(Tipsv2DptConfig)과 입력에 따라 다양한 요소를 포함합니다.
Tipsv2DptForDepthEstimation의 forward 메서드는 __call__ 특수 메서드를 오버라이드합니다.
이 함수 내에서 forward pass의 레시피를 정의해야 하지만, 이후에는 이 함수 대신
Module인스턴스를 호출해야 합니다. 전자는 전처리 및 후처리 단계를 실행하는 것을 처리하는 반면, 후자는 이를 조용히 무시하기 때문입니다.
loss (
torch.Tensor, shape(1,), 선택 사항,labels이 제공될 때 반환됨) — 분류 (또는 config.num_labels==1인 경우 회귀) 손실.predicted_depth (
torch.Tensor, shape(batch_size, height, width)) — 각 픽셀에 대한 예측된 깊이.hidden_states (
tuple(torch.Tensor), 선택 사항,output_hidden_states=True가 전달되거나config.output_hidden_states=True인 경우 반환됨) —torch.Tensor의 튜플(모델에 임베딩 레이어가 있는 경우 임베딩의 출력에 대한 것 1개 + 각 레이어의 출력에 대한 것 1개)로, 모양은(batch_size, num_channels, height, width)입니다.각 레이어의 출력에서 모델의 Hidden-states와 선택적 초기 임베딩 출력을 포함합니다.
attentions (
tuple(torch.Tensor), 선택 사항,output_attentions=True가 전달되었거나config.output_attentions=True인 경우 반환됨) — 각 레이어마다 하나씩 포함된torch.Tensor의 튜플로, 모양은(batch_size, num_heads, patch_size, sequence_length)입니다.self-attention 헤드에서 가중 평균을 계산하는 데 사용되는 attention softmax 이후의 attention 가중치.
예:
>>> import torch
>>> from transformers import AutoModelForDepthEstimation, AutoImageProcessor
>>> from transformers.image_utils import load_image
>>> model_id = "google/tipsv2-b14-dpt"
>>> model = AutoModelForDepthEstimation.from_pretrained(model_id, device_map="auto")
>>> image_processor = AutoImageProcessor.from_pretrained(model_id)
>>> image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
>>> inputs = image_processor(images=image, return_tensors="pt").to(model.device)
>>> with torch.no_grad():
... outputs = model(**inputs)
>>> results = image_processor.post_process_depth_estimation(outputs, target_sizes=[(image.height, image.width)])
>>> predicted_depth = results[0]["predicted_depth"] # (height, width) tensor with predicted depth in metersTipsv2DptForNormalEstimation
class transformers.Tipsv2DptForNormalEstimation
< source >( config: Tipsv2DptConfig )
매개변수
- config (Tipsv2DptConfig) — 모델의 모든 매개변수를 포함하는 모델 구성 클래스입니다. 구성 파일로 초기화하는 것은 모델과 관련된 가중치를 로드하지 않으며, 구성만 로드합니다. 모델 가중치를 로드하려면 from_pretrained() 메서드를 확인하세요.
표면 법선 추정 헤드가 포함된 TIPSv2-DPT 모델.
이 모델은 PreTrainedModel에서 상속됩니다. 라이브러리가 모든 모델에 대해 구현하는 일반적 메서드(다운로드 또는 저장, 입력 임베딩 크기 조정, 헤드 프루닝 등)에 대한 세부 사항은 상위 클래스 문서를 확인하세요.
이 모델은 또한 PyTorch torch.nn.Module의 하위 클래스입니다. 일반적인 PyTorch Module처럼 사용하며, 일반적인 사용법 및 동작과 관련된 모든 사항은 PyTorch 문서를 참조하세요.
forward
< source >( pixel_values: Tensorlabels: typing.Optional[torch.Tensor] = None**kwargs: Unpack ) → Tipsv2DptNormalEstimatorOutput or tuple(torch.Tensor)
매개변수
- pixel_values (
torch.Tensor, shape(batch_size, num_channels, image_size, image_size)) — 입력 이미지에 해당하는 텐서입니다. 픽셀 값은 Tipsv2DptImageProcessor를 사용하여 얻을 수 있습니다. 자세한 내용은 Tipsv2DptImageProcessor.call()를 참조하세요 (processor_class는 이미지 처리에 Tipsv2DptImageProcessor를 사용합니다). - labels (
torch.Tensor, shape(batch_size, sequence_length), 선택 사항) — 마스크 언어 모델링 손실을 계산하는 데 사용되는 라벨입니다. 인덱스는[0, ..., config.vocab_size]범위 내의 값이거나 -100이어야 합니다(input_idsdocstring 참조). 인덱스가-100으로 설정된 토큰은 무시(마스크)되며, 손실은[0, ..., config.vocab_size]범위의 라벨을 가진 토큰에 대해서만 계산됩니다.
반환값
Tipsv2DptNormalEstimatorOutput 또는 tuple(torch.Tensor)
Tipsv2DptNormalEstimatorOutput 또는 torch.Tensor의 튜플(return_dict=False가 전달되었거나 config.return_dict=False인 경우)로, 구성(Tipsv2DptConfig)과 입력에 따라 다양한 요소를 포함합니다.
Tipsv2DptForNormalEstimation의 forward 메서드는 __call__ 특수 메서드를 오버라이드합니다.
이 함수 내에서 forward pass의 레시피를 정의해야 하지만, 이후에는 이 함수 대신
Module인스턴스를 호출해야 합니다. 전자는 전처리 및 후처리 단계를 실행하는 것을 처리하는 반면, 후자는 이를 조용히 무시하기 때문입니다.
- loss (
torch.Tensor, shape(1,), 선택 사항,labels가 제공될 때 반환됨) — 정규 추정 손실. - normals (
torch.Tensor, shape(batch_size, num_labels, height, width)) — 모델이 출력한 원본 노멀 맵 예측값(정규화되지 않음). - hidden_states (
tuple(torch.Tensor), 선택 사항,output_hidden_states=True가 전달되었거나config.output_hidden_states=True인 경우 반환됨) —torch.Tensor의 튜플(임베딩 출력 1개 + 각 단계의 출력 1개) 형상은(batch_size, sequence_length, hidden_size)입니다. 각 레이어 출력 시점의 모델 hidden-states와 초기 임베딩 출력을 포함합니다. - attentions (
tuple(torch.Tensor), 선택 사항,output_attentions=True가 전달되었거나config.output_attentions=True인 경우 반환됨) —torch.Tensor의 튜플(레이어당 하나)로, 모양은(batch_size, num_heads, sequence_length, sequence_length)입니다. attention softmax 이후의 attention 가중치입니다.
예:
>>> import torch
>>> from transformers import Tipsv2DptForNormalEstimation, AutoImageProcessor
>>> from transformers.image_utils import load_image
>>> model_id = "google/tipsv2-b14-dpt"
>>> model = Tipsv2DptForNormalEstimation.from_pretrained(model_id, device_map="auto")
>>> image_processor = AutoImageProcessor.from_pretrained(model_id)
>>> image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
>>> inputs = image_processor(images=image, return_tensors="pt").to(model.device)
>>> with torch.no_grad():
... outputs = model(**inputs)
>>> results = image_processor.post_process_normal_estimation(outputs, target_sizes=[(image.height, image.width)])
>>> normals = results[0]["normals"] # (3, height, width) tensor with normals in XYZ format (L2-normalized)Tipsv2DptForSemanticSegmentation
class transformers.Tipsv2DptForSemanticSegmentation
< source >( config: Tipsv2DptConfig )
매개변수
- config (Tipsv2DptConfig) — 모델의 모든 매개변수를 포함하는 모델 구성 클래스입니다. 구성 파일로 초기화하는 것은 모델과 관련된 가중치를 로드하지 않으며, 구성만 로드합니다. 모델 가중치를 로드하려면 from_pretrained() 메서드를 확인하세요.
의미 분할 헤드를 갖춘 TIPSv2-DPT 모델.
이 모델은 PreTrainedModel에서 상속됩니다. 라이브러리가 모든 모델에 대해 구현하는 일반적 메서드(다운로드 또는 저장, 입력 임베딩 크기 조정, 헤드 프루닝 등)에 대한 세부 사항은 상위 클래스 문서를 확인하세요.
이 모델은 또한 PyTorch torch.nn.Module의 하위 클래스입니다. 일반적인 PyTorch Module처럼 사용하며, 일반적인 사용법 및 동작과 관련된 모든 사항은 PyTorch 문서를 참조하세요.
forward
< source >( pixel_values: Tensorlabels: typing.Optional[torch.LongTensor] = None**kwargs: Unpack ) → SemanticSegmenterOutput or tuple(torch.Tensor)
매개변수
- pixel_values (
torch.Tensor, shape(batch_size, num_channels, image_size, image_size)) — 입력 이미지에 해당하는 텐서입니다. 픽셀 값은 Tipsv2DptImageProcessor를 사용하여 얻을 수 있습니다. 자세한 내용은 Tipsv2DptImageProcessor.call()를 참조하세요 (processor_class는 이미지 처리에 Tipsv2DptImageProcessor를 사용합니다). - labels (
torch.LongTensor, shape(batch_size, height, width), 선택 사항) — 손실 계산에 사용되는 ground truth semantic segmentation map입니다. 인덱스는[0, ..., config.num_labels - 1]범위에 있어야 합니다.config.num_labels > 1인 경우, 분류 손실(Cross-Entropy)이 계산됩니다.
반환값
SemanticSegmenterOutput 또는 tuple(torch.Tensor)
torch.Tensor의 튜플 또는 SemanticSegmenterOutput입니다. return_dict=False가 전달되거나 config.return_dict=False인 경우, 구성(Tipsv2DptConfig)과 입력에 따라 다양한 요소를 포함합니다.
Tipsv2DptForSemanticSegmentation의 forward 메서드는 __call__ 특수 메서드를 오버라이드합니다.
이 함수 내에서 forward pass의 레시피를 정의해야 하지만, 이후에는 이 함수 대신
Module인스턴스를 호출해야 합니다. 전자는 전처리 및 후처리 단계를 실행하는 것을 처리하는 반면, 후자는 이를 조용히 무시하기 때문입니다.
loss (
torch.Tensor, shape(1,), 선택 사항,labels이 제공될 때 반환됨) — 분류 (또는 config.num_labels==1인 경우 회귀) 손실.logits (
torch.Tensor, shape(batch_size, config.num_labels, logits_height, logits_width)) — 각 픽셀에 대한 분류 점수.pixel_values로 전달된 입력과 반환되는 logits의 크기가 항상 동일하지는 않습니다. 이는 사용자가 후처리 단계에서 logits를 원본 이미지 크기로 리사이즈할 때 두 번의 보간을 수행하여 품질이 저하되는 것을 방지하기 위한 것입니다. 따라서 logits의 shape을 항상 확인하고 필요에 따라 리사이즈해야 합니다.hidden_states (
tuple(torch.Tensor), 선택 사항,output_hidden_states=True가 전달되거나config.output_hidden_states=True인 경우 반환됨) —torch.Tensor의 튜플(모델에 임베딩 레이어가 있는 경우 임베딩 출력 1개 + 각 레이어의 출력 1개)로, 모양은(batch_size, patch_size, hidden_size)입니다.각 레이어의 출력에서 모델의 Hidden-states와 선택적 초기 임베딩 출력을 포함합니다.
attentions (
tuple(torch.Tensor), 선택 사항,output_attentions=True가 전달되었거나config.output_attentions=True인 경우 반환됨) — 각 레이어마다 하나씩 포함된torch.Tensor의 튜플로, 모양은(batch_size, num_heads, patch_size, sequence_length)입니다.self-attention 헤드에서 가중 평균을 계산하는 데 사용되는 attention softmax 이후의 attention 가중치.
예:
>>> import torch
>>> from transformers import AutoModelForSemanticSegmentation, AutoImageProcessor
>>> from transformers.image_utils import load_image
>>> model_id = "google/tipsv2-b14-dpt"
>>> model = AutoModelForSemanticSegmentation.from_pretrained(model_id, device_map="auto")
>>> image_processor = AutoImageProcessor.from_pretrained(model_id)
>>> image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/room.jpg")
>>> inputs = image_processor(images=image, return_tensors="pt").to(model.device)
>>> with torch.no_grad():
... outputs = model(**inputs)
>>> results = image_processor.post_process_semantic_segmentation(outputs, target_sizes=[(image.height, image.width)])
>>> segmentation_map = results[0] # (height, width) tensor with class ids