Transformers documentation

Backbone

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Backbone

Backbone은 객체 감지 및 이미지 분류와 같은 고급 컴퓨터 비전 작업을 위한 특징 추출에 사용되는 모델입니다. Transformers는 사전 학습된 모델 가중치로부터 Transformers backbone을 초기화하기 위한 AutoBackbone 클래스와 두 가지 유틸리티 클래스를 제공합니다:

  • BackboneMixin은 Transformers 또는 timm에서 백본을 초기화할 수 있게 하며, 출력 특징과 인덱스를 반환하는 함수를 포함합니다.
  • BackboneConfigMixin은 백본 구성의 출력 특징 및 인덱스를 설정합니다.

timm 모델은 TimmBackbone 및 TimmBackboneConfig 클래스를 통해 로드됩니다.

다음 모델에 대해 Backbones이 지원됩니다:

AutoBackbone

클래스 transformers.AutoBackbone

< >

( *args**kwargs )

BackboneMixin

class transformers.BackboneMixin

< >

( *args**kwargs )

post_init

< >

( )

post_init를 오버라이드하여 캡처 훅을 항상 설치합니다. 백본은 항상 출력을 캡처하기 때문입니다. 모듈이 이미 인스턴스화되어 있어야 하므로 post_init에서 수행해야 합니다. 이는 torch.compile과의 혼동을 방지합니다. 첫 번째 훅 설치 시 그래프 브레이크가 필요하거나 생성되며, 이는 model = torch.compile(model...)와 같은 외부 사용자 호출과 충돌할 수 있기 때문입니다.

BackboneConfigMixin

class transformers.BackboneConfigMixin

< >

( )

backbone 구성에서 out_features 및 out_indices 속성을 처리하도록 지원하는 Mixin입니다.

set_output_features_output_indices

< >

( out_features: list | Noneout_indices: list | None )

매개변수

  • out_features (list[str], 선택 사항) — backbone이 출력할 feature의 이름입니다. 제공되지 않으면 기본값으로 config._out_features를 사용합니다.
  • out_indices (list[int] 또는 tuple[int], 선택 사항) — backbone이 출력할 feature의 인덱스입니다. 제공되지 않으면 기본값으로 config._out_indices를 사용합니다.

출력 인덱스와 특징을 새로운 값으로 설정하고, 주어진 stage_names와 정렬합니다. 입력 중 하나가 제공되지 않은 경우, 주어진 stage_names에 해당하는 out_features 또는 out_indices를 찾습니다.

to_dict

< >

( )

이 인스턴스를 Python 딕셔너리로 직렬화합니다. out_features 및 out_indices 속성을 포함하도록 PreTrainedConfig의 기본 to_dict()를 오버라이드합니다.

verify_out_features_out_indices

< >

( )

stage_names에 대해 out_indices와 out_features가 유효한지 확인합니다.

TimmBackbone

class transformers.TimmBackbone

< >

( config: TimmBackboneConfig**kwargs )

timm 모델을 백본으로 사용하도록 래핑하는 클래스입니다. 이를 통해 라이브러리 내의 다른 모델과 동일한 API를 유지하면서 timm 모델을 상호 교환적으로 사용할 수 있습니다.

TimmBackboneConfig

클래스 transformers.TimmBackboneConfig

< >

( 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: str | None = Nonenum_channels: int = 3features_only: bool = True_out_indices: list[int] | None = Nonefreeze_batch_norm_2d: bool = Falseoutput_stride: int | None = None )

매개변수

  • backbone (str, 선택 사항) — 로드할 timm 체크포인트입니다.
  • num_channels (int, 선택 사항, 기본값 3) — 입력 채널의 수입니다.
  • features_only (bool, 선택 사항, 기본값 True) — logits를 포함하여 출력할지, features만 출력할지를 결정합니다.
  • freeze_batch_norm_2d (bool, 선택 사항, 기본값 False) — 제공된 모듈의 모든 BatchNorm2d 및 SyncBatchNorm 레이어를 FrozenBatchNorm2d로 변환합니다.
  • output_stride (int, 선택 사항) — 입력 및 출력 특징 맵의 공간 해상도 비율입니다.

이것은 TimmBackbone의 구성을 저장하기 위한 구성 클래스입니다. 지정된 인자에 따라 Timm Backbone 모델을 인스턴스화하여 모델 아키텍처를 정의하는 데 사용됩니다. 기본값으로 구성을 인스턴스화하면 와 유사한 구성이 생성됩니다.

Configuration 객체는 PreTrainedConfig를 상속하며 모델 출력을 제어하는 데 사용할 수 있습니다. 자세한 내용은 PreTrainedConfig의 문서를 참고하세요.

예:

>>> from transformers import TimmBackboneConfig, TimmBackbone

>>> # Initializing a timm backbone
>>> configuration = TimmBackboneConfig("resnet50")

>>> # Initializing a model from the configuration
>>> model = TimmBackbone(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config
Update on GitHub