MCPcopy Create free account
hub / github.com/Topdu/OpenOCR / __init__

Method __init__

openrec/modeling/decoders/matrn_decoder.py:132–183  ·  view source on GitHub ↗
(self,
                 in_channels,
                 out_channels,
                 nhead=8,
                 num_layers=3,
                 dim_feedforward=2048,
                 dropout=0.1,
                 max_length=25,
                 iter_size=3,
                 **kwargs)

Source from the content-addressed store, hash-verified

130class MATRNDecoder(nn.Module):
131
132 def __init__(self,
133 in_channels,
134 out_channels,
135 nhead=8,
136 num_layers=3,
137 dim_feedforward=2048,
138 dropout=0.1,
139 max_length=25,
140 iter_size=3,
141 **kwargs):
142 super().__init__()
143 self.max_length = max_length + 1
144 d_model = in_channels
145 self.pos_encoder = PositionalEncoding(dropout=0.1, dim=d_model)
146 self.encoder = nn.ModuleList([
147 TransformerBlock(
148 d_model=d_model,
149 nhead=nhead,
150 dim_feedforward=dim_feedforward,
151 attention_dropout_rate=dropout,
152 residual_dropout_rate=dropout,
153 with_self_attn=True,
154 with_cross_attn=False,
155 ) for _ in range(num_layers)
156 ])
157 self.decoder = PositionAttention(
158 max_length=self.max_length, # additional stop token
159 in_channels=d_model,
160 num_channels=d_model // 8,
161 mode='nearest',
162 )
163 self.out_channels = out_channels
164 self.cls = nn.Linear(d_model, self.out_channels)
165 self.iter_size = iter_size
166 if iter_size > 0:
167 self.language = BCNLanguage(
168 d_model=d_model,
169 nhead=nhead,
170 num_layers=4,
171 dim_feedforward=dim_feedforward,
172 dropout=dropout,
173 max_length=max_length,
174 num_classes=self.out_channels,
175 )
176 # alignment
177 self.semantic_visual = BaseSemanticVisual_backbone_feature(
178 d_model=d_model,
179 nhead=nhead,
180 num_layers=2,
181 dim_feedforward=dim_feedforward,
182 max_length=max_length,
183 num_classes=self.out_channels)
184
185 def forward(self, x, data=None):
186 # bs, c, h, w

Callers 1

__init__Method · 0.45

Calls 5

PositionalEncodingClass · 0.90
TransformerBlockClass · 0.90
PositionAttentionClass · 0.90
BCNLanguageClass · 0.90

Tested by

no test coverage detected