data_juicer.ops.common.hawor_func_vit module#

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

dimension for the original embeddings.

Parameters:
  • 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.

Returns:

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

class data_juicer.ops.common.hawor_func_vit.DropPath(drop_prob=None)[source]#

Bases: Module

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

__init__(drop_prob=None)[source]#

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

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

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()[source]#

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)[source]#

Bases: Module

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

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

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

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)[source]#

Bases: Module

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

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

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

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)[source]#

Bases: 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)[source]#

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

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

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)[source]#

Bases: Module

Image to Patch Embedding

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

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

forward(x, **kwargs)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

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)[source]#

Bases: 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)[source]#

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

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

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)[source]#

Bases: 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)[source]#

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

init_weights()[source]#

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

Defaults to None.

get_num_layers()[source]#
no_weight_decay()[source]#
forward_features(x)[source]#
forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

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)[source]#

Convert the model into training mode.