Buckets:

mishig's picture
|
download
raw
9.32 kB

UNet2DModel

UNet 모델은 Ronneberger et al.에 의해 바이오메디컬 이미지 분할을 위해 처음 소개되었지만, 입력과 동일한 크기의 이미지를 출력하기 때문에 🤗 Diffusers에서도 널리 사용됩니다. 실제 확산(diffusion) 과정을 담당하는 핵심 구성 요소 중 하나입니다. 🤗 Diffusers에는 차원 수와 조건부 모델 여부(conditional model)에 따라 UNet 모델의 여러 변형(variant)이 있습니다. 여기서는 2D UNet 모델입니다.

해당 논문의 초록은 다음과 같습니다:

딥 네트워크의 성공적인 학습에는 수천 개의 라벨이 붙은 학습 샘플이 필요하다는 데에 큰 합의가 있습니다. 본 논문에서는 데이터 증강을 강하게 활용하여 사용 가능한 라벨 샘플을 더 효율적으로 사용하는 네트워크와 학습 전략을 제시합니다. 아키텍처는 컨텍스트를 포착하기 위한 수축 경로와 정확한 위치 파악을 가능하게 하는 대칭적인 확장 경로로 구성됩니다. 이러한 네트워크가 매우 적은 이미지로 끝에서 끝까지(end-to-end) 학습될 수 있으며, 전자 현미경 스택의 신경 구조 분할을 위한 ISBI 챌린지에서 이전의 최선 방법(슬라이딩 윈도우 컨볼루션 네트워크)보다 우수한 성능을 보임을 보여줍니다. 동일한 네트워크를 투과광 현미경 이미지(위상 대비 및 DIC)로 학습하여, 해당 카테고리에서 ISBI 세포 추적 챌린지 2015를 큰 격차로 우승했습니다. 또한, 이 네트워크는 빠릅니다. 최신 GPU에서 512x512 이미지의 분할은 1초 미만으로 수행됩니다. 전체 구현(Caffe 기반)과 학습된 네트워크는 http://lmb.informatik.uni-freiburg.de/people/ronneber/u-net에서 사용할 수 있습니다.

UNet2DModel[[diffusers.UNet2DModel]]

diffusers.UNet2DModel[[diffusers.UNet2DModel]]

diffusers.UNet2DModel(sample_size: int | tuple[int, int] | None = None, in_channels: int = 3, out_channels: int = 3, center_input_sample: bool = False, time_embedding_type: str = 'positional', time_embedding_dim: int | None = None, freq_shift: int = 0, flip_sin_to_cos: bool = True, down_block_types: tuple = ('DownBlock2D', 'AttnDownBlock2D', 'AttnDownBlock2D', 'AttnDownBlock2D'), mid_block_type: str | None = 'UNetMidBlock2D', up_block_types: tuple = ('AttnUpBlock2D', 'AttnUpBlock2D', 'AttnUpBlock2D', 'UpBlock2D'), block_out_channels: tuple = (224, 448, 672, 896), layers_per_block: int = 2, mid_block_scale_factor: float = 1, downsample_padding: int = 1, downsample_type: str = 'conv', upsample_type: str = 'conv', dropout: float = 0.0, act_fn: str = 'silu', attention_head_dim: int | None = 8, norm_num_groups: int = 32, attn_norm_num_groups: int | None = None, norm_eps: float = 1e-05, resnet_time_scale_shift: str = 'default', add_attention: bool = True, class_embed_type: str | None = None, num_class_embeds: int | None = None, num_train_timesteps: int | None = None)

소스

매개변수:

sample_size (int 또는 tuple[int, int], 선택 사항, 기본값 None) : 입력/출력 샘플의 높이와 너비. 차원은 2 ** (len(block_out_channels) - 1)의 배수여야 합니다.

in_channels (int, 선택 사항, 기본값 3) : 입력 샘플의 채널 수.

out_channels (int, 선택 사항, 기본값 3) : 출력의 채널 수.

center_input_sample (bool, 선택 사항, 기본값 False) : 입력 샘플을 중앙에 위치시킬지 여부.

time_embedding_type (str, 선택 사항, 기본값 "positional") : 사용할 시간 임베딩의 유형.

freq_shift (int, 선택 사항, 기본값 0) : Fourier 시간 임베딩의 주파수 시프트입니다.

flip_sin_to_cos (bool, 선택 사항, 기본값 True) : Fourier 시간 임베딩에서 sin을 cos로 전환할지 여부입니다.

down_block_types (tuple[str], 선택 사항, 기본값은 ("DownBlock2D", "AttnDownBlock2D", "AttnDownBlock2D", "AttnDownBlock2D")) : 다운샘플 블록 유형 튜플.

mid_block_type (str, 선택 사항, 기본값 "UNetMidBlock2D") : UNet 중간 부분의 블록 유형으로, UNetMidBlock2D 또는 None 중 하나여야 합니다.

up_block_types (tuple[str], 선택 사항, 기본값은 ("AttnUpBlock2D", "AttnUpBlock2D", "AttnUpBlock2D", "UpBlock2D")) : 업샘플 블록 유형 튜플.

block_out_channels (tuple[int], 선택 사항, 기본값 (224, 448, 672, 896)) : 블록 출력 채널의 튜플.

layers_per_block (int, 선택 사항, 기본값 2) : 블록당 레이어 수.

mid_block_scale_factor (float, 선택 사항, 기본값 1) : mid 블록의 스케일 팩터입니다.

downsample_padding (int, 선택 사항, 기본값 1) : 다운샘플링 컨볼루션의 패딩입니다.

downsample_type (str, 선택 사항, 기본값 conv) : 다운샘플링 레이어에 사용할 다운샘플링 유형입니다. "conv" 또는 "resnet" 중 하나를 선택합니다.

upsample_type (str, 선택 사항, 기본값 conv) : 업샘플링 레이어의 업샘플링 유형입니다. "conv"와 "resnet" 중 하나를 선택합니다

dropout (float, 선택 사항, 기본값 0.0) : 사용할 dropout 확률입니다.

act_fn (str, 선택 사항, 기본값 "silu") : 사용할 활성화 함수입니다.

attention_head_dim (int, 선택 사항, 기본값 8) : 어텐션 헤드 차원입니다.

norm_num_groups (int, 선택 사항, 기본값 32) : 정규화에 사용할 그룹 수입니다.

attn_norm_num_groups (int, 선택 사항, 기본값 None) : 정수 값으로 설정하면, mid block의 Attention 레이어에 주어진 그룹 수를 가진 group norm 레이어가 생성됩니다. None으로 두면, resnet_time_scale_shift가 default로 설정된 경우에만 group norm 레이어가 생성되며, 생성될 경우 norm_num_groups개의 그룹을 가집니다.

norm_eps (float, 선택 사항, 기본값 1e-5) : 정규화에 사용되는 epsilon입니다.

resnet_time_scale_shift (str, 선택 사항, 기본값 "default") : ResNet 블록의 시간 스케일 시프트 설정(자세한 내용은 ResnetBlock2D 참조). default 또는 scale_shift 중 하나를 선택합니다.

class_embed_type (str, 선택 사항, 기본값 None) : 최종적으로 time embeddings와 합산되는 class embedding의 유형입니다. None, "timestep", 또는 "identity" 중 하나를 선택합니다.

num_class_embeds (int, 선택 사항, 기본값 None) : class_embed_type가 None인 경우 클래스 조건화를 수행할 때 time_embed_dim으로 투영되는 학습 가능한 임베딩 행렬의 입력 차원입니다.

노이즈 샘플과 타임스텝을 입력받아 샘플 모양의 출력을 반환하는 2D UNet 모델입니다.

이 모델은 ModelMixin에서 상속됩니다. 모든 모델에 대해 구현된 일반적 메서드(다운로드 또는 저장 등)에 대해서는 상위 클래스 문서를 확인하세요.

forward[[diffusers.UNet2DModel.forward]]

forward(sample: Tensor, timestep: typing.Union[torch.Tensor, float, int], class_labels: typing.Optional[torch.Tensor] = None, return_dict: bool = True)

소스

매개변수:

sample (torch.Tensor) : 다음 형태 (batch, channel, height, width)를 가진 노이즈 입력 텐서.

timestep (torch.Tensor 또는 float 또는 int) : 입력을 디노이즈할 타임스텝 수.

class_labels (torch.Tensor, 선택 사항, 기본값 None) : 조건부 생성을 위한 선택적 클래스 라벨입니다. 이 라벨의 임베딩은 타임스텝 임베딩과 합산됩니다.

return_dict (bool, 선택 사항, 기본값 True) : 일반 튜플 대신 UNet2DOutput을 반환할지 여부.

반환값: UNet2DOutput 또는 tuple

return_dict가 True이면 UNet2DOutput이 반환되고, 그렇지 않으면 첫 번째 요소가 샘플 텐서인 tuple이 반환됩니다.

UNet2DModel의 forward 메서드입니다.

UNet2DOutput[[diffusers.models.unets.unet_2d.UNet2DOutput]]

diffusers.models.unets.unet_2d.UNet2DOutput[[diffusers.models.unets.unet_2d.UNet2DOutput]]

diffusers.models.unets.unet_2d.UNet2DOutput(sample: Tensor)

소스

매개변수:

sample (torch.Tensor, shape (batch_size, num_channels, height, width)) : 모델의 마지막 레이어에서 출력된 hidden states입니다.

UNet2DModel의 출력입니다.

Xet Storage Details

Size:
9.32 kB
·
Xet hash:
8232579f2f2c2e5c27c37aa6cafb5b45a7c029662ee0ff38bf03d248233155ad

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