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

Method __init__

openrec/modeling/decoders/abinet_decoder.py:157–203  ·  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

155class ABINetDecoder(nn.Module):
156
157 def __init__(self,
158 in_channels,
159 out_channels,
160 nhead=8,
161 num_layers=3,
162 dim_feedforward=2048,
163 dropout=0.1,
164 max_length=25,
165 iter_size=3,
166 **kwargs):
167 super().__init__()
168 self.max_length = max_length + 1
169 d_model = in_channels
170 self.pos_encoder = PositionalEncoding(dropout=0.1, dim=d_model)
171 self.encoder = nn.ModuleList([
172 TransformerBlock(
173 d_model=d_model,
174 nhead=nhead,
175 dim_feedforward=dim_feedforward,
176 attention_dropout_rate=dropout,
177 residual_dropout_rate=dropout,
178 with_self_attn=True,
179 with_cross_attn=False,
180 ) for _ in range(num_layers)
181 ])
182 self.decoder = PositionAttention(
183 max_length=self.max_length, # additional stop token
184 in_channels=d_model,
185 num_channels=d_model // 8,
186 mode='nearest',
187 )
188 self.out_channels = out_channels
189 self.cls = nn.Linear(d_model, self.out_channels)
190 self.iter_size = iter_size
191 if iter_size > 0:
192 self.language = BCNLanguage(
193 d_model=d_model,
194 nhead=nhead,
195 num_layers=4,
196 dim_feedforward=dim_feedforward,
197 dropout=dropout,
198 max_length=max_length,
199 num_classes=self.out_channels,
200 )
201 # alignment
202 self.w_att_align = nn.Linear(2 * d_model, d_model)
203 self.cls_align = nn.Linear(d_model, self.out_channels)
204
205 def forward(self, x, data=None):
206 # bs, c, h, w

Callers

nothing calls this directly

Calls 5

PositionalEncodingClass · 0.90
TransformerBlockClass · 0.90
PositionAttentionClass · 0.85
BCNLanguageClass · 0.85
__init__Method · 0.45

Tested by

no test coverage detected