MCPcopy Create free account
hub / github.com/aigc3d/LHM / __init__

Method __init__

engine/BiRefNet/models/modules/prompt_encoder.py:9–58  ·  view source on GitHub ↗
(
        self,
        embed_dim=256,
        image_embedding_size=1024,
        input_image_size=(1024, 1024),
        mask_in_chans=16,
        activation=nn.GELU,
    )

Source from the content-addressed store, hash-verified

7
8class PromptEncoder(nn.Module):
9 def __init__(
10 self,
11 embed_dim=256,
12 image_embedding_size=1024,
13 input_image_size=(1024, 1024),
14 mask_in_chans=16,
15 activation=nn.GELU,
16 ) -> None:
17 super().__init__()
18 """
19 Codes are partially from SAM: https://github.com/facebookresearch/segment-anything/blob/6fdee8f2727f4506cfbbe553e23b895e27956588/segment_anything/modeling/prompt_encoder.py.
20
21 Arguments:
22 embed_dim (int): The prompts' embedding dimension
23 image_embedding_size (tuple(int, int)): The spatial size of the
24 image embedding, as (H, W).
25 input_image_size (int): The padded size of the image as input
26 to the image encoder, as (H, W).
27 mask_in_chans (int): The number of hidden channels used for
28 encoding input masks.
29 activation (nn.Module): The activation to use when encoding
30 input masks.
31 """
32 super().__init__()
33 self.embed_dim = embed_dim
34 self.input_image_size = input_image_size
35 self.image_embedding_size = image_embedding_size
36 self.pe_layer = PositionEmbeddingRandom(embed_dim // 2)
37
38 self.num_point_embeddings: int = 4 # pos/neg point + 2 box corners
39 point_embeddings = [
40 nn.Embedding(1, embed_dim) for i in range(self.num_point_embeddings)
41 ]
42 self.point_embeddings = nn.ModuleList(point_embeddings)
43 self.not_a_point_embed = nn.Embedding(1, embed_dim)
44
45 self.mask_input_size = (
46 4 * image_embedding_size[0],
47 4 * image_embedding_size[1],
48 )
49 self.mask_downscaling = nn.Sequential(
50 nn.Conv2d(1, mask_in_chans // 4, kernel_size=2, stride=2),
51 LayerNorm2d(mask_in_chans // 4),
52 activation(),
53 nn.Conv2d(mask_in_chans // 4, mask_in_chans, kernel_size=2, stride=2),
54 LayerNorm2d(mask_in_chans),
55 activation(),
56 nn.Conv2d(mask_in_chans, embed_dim, kernel_size=1),
57 )
58 self.no_mask_embed = nn.Embedding(1, embed_dim)
59
60 def get_dense_pe(self) -> torch.Tensor:
61 """

Callers

nothing calls this directly

Calls 3

LayerNorm2dClass · 0.85
__init__Method · 0.45

Tested by

no test coverage detected