data_juicer.ops.common.hawor_func_vit module#

data_juicer.ops.common.hawor_func_vit.vit(cfg)[源代码]#
data_juicer.ops.common.hawor_func_vit.get_abs_pos(abs_pos, h, w, ori_h, ori_w, has_cls_token=True)[源代码]#
Calculate absolute positional embeddings. If needed, resize embeddings and remove cls_token

dimension for the original embeddings.

参数:
  • abs_pos (Tensor) -- absolute positional embeddings with (1, num_position, C).

  • has_cls_token (bool) -- If true, has 1 embedding in abs_pos for cls token.

  • hw (Tuple) -- size of input image tokens.

返回:

Absolute positional embeddings after processing with shape (1, H, W, C)

class data_juicer.ops.common.hawor_func_vit.DropPath(drop_prob=None)[源代码]#

基类:Module

Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).

__init__(drop_prob=None)[源代码]#

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[源代码]#

Define the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

extra_repr()[源代码]#

Return the extra representation of the module.

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

class data_juicer.ops.common.hawor_func_vit.Mlp(in_features, hidden_features=None, out_features=None, act_layer=<class 'torch.nn.modules.activation.GELU'>, drop=0.0)[源代码]#

基类:Module

__init__(in_features, hidden_features=None, out_features=None, act_layer=<class 'torch.nn.modules.activation.GELU'>, drop=0.0)[源代码]#

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[源代码]#

Define the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class data_juicer.ops.common.hawor_func_vit.Attention(dim, num_heads=8, qkv_bias=False, qk_scale=None, attn_drop=0.0, proj_drop=0.0, attn_head_dim=None)[源代码]#

基类:Module

__init__(dim, num_heads=8, qkv_bias=False, qk_scale=None, attn_drop=0.0, proj_drop=0.0, attn_head_dim=None)[源代码]#

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[源代码]#

Define the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class data_juicer.ops.common.hawor_func_vit.Block(dim, num_heads, mlp_ratio=4.0, qkv_bias=False, qk_scale=None, drop=0.0, attn_drop=0.0, drop_path=0.0, act_layer=<class 'torch.nn.modules.activation.GELU'>, norm_layer=<class 'torch.nn.modules.normalization.LayerNorm'>, attn_head_dim=None)[源代码]#

基类:Module

__init__(dim, num_heads, mlp_ratio=4.0, qkv_bias=False, qk_scale=None, drop=0.0, attn_drop=0.0, drop_path=0.0, act_layer=<class 'torch.nn.modules.activation.GELU'>, norm_layer=<class 'torch.nn.modules.normalization.LayerNorm'>, attn_head_dim=None)[源代码]#

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[源代码]#

Define the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class data_juicer.ops.common.hawor_func_vit.PatchEmbed(img_size=224, patch_size=16, in_chans=3, embed_dim=768, ratio=1)[源代码]#

基类:Module

Image to Patch Embedding

__init__(img_size=224, patch_size=16, in_chans=3, embed_dim=768, ratio=1)[源代码]#

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x, **kwargs)[源代码]#

Define the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class data_juicer.ops.common.hawor_func_vit.HybridEmbed(backbone, img_size=224, feature_size=None, in_chans=3, embed_dim=768)[源代码]#

基类:Module

CNN Feature Map Embedding Extract feature map from CNN, flatten, project to embedding dim.

__init__(backbone, img_size=224, feature_size=None, in_chans=3, embed_dim=768)[源代码]#

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[源代码]#

Define the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class data_juicer.ops.common.hawor_func_vit.ViT(img_size=224, patch_size=16, in_chans=3, num_classes=80, embed_dim=768, depth=12, num_heads=12, mlp_ratio=4.0, qkv_bias=False, qk_scale=None, drop_rate=0.0, attn_drop_rate=0.0, drop_path_rate=0.0, hybrid_backbone=None, norm_layer=None, use_checkpoint=False, frozen_stages=-1, ratio=1, last_norm=True, patch_padding='pad', freeze_attn=False, freeze_ffn=False)[源代码]#

基类:Module

__init__(img_size=224, patch_size=16, in_chans=3, num_classes=80, embed_dim=768, depth=12, num_heads=12, mlp_ratio=4.0, qkv_bias=False, qk_scale=None, drop_rate=0.0, attn_drop_rate=0.0, drop_path_rate=0.0, hybrid_backbone=None, norm_layer=None, use_checkpoint=False, frozen_stages=-1, ratio=1, last_norm=True, patch_padding='pad', freeze_attn=False, freeze_ffn=False)[源代码]#

Initialize internal Module state, shared by both nn.Module and ScriptModule.

init_weights()[源代码]#

Initialize the weights in backbone. :param pretrained: Path to pre-trained weights.

Defaults to None.

get_num_layers()[源代码]#
no_weight_decay()[源代码]#
forward_features(x)[源代码]#
forward(x)[源代码]#

Define the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

train(mode=True)[源代码]#

Convert the model into training mode.