class
MyModel(nn.Module):
def
__init__(
self
):
super
(MyModel,
self
).__init__()
self
.layer1
=
nn.Sequential(
nn.Conv2d(in_channels
=
3
, out_channels
=
64
, kernel_size
=
3
, padding
=
1
),
nn.BatchNorm2d(
64
),
nn.ReLU(),
nn.MaxPool2d(kernel_size
=
2
)
)
self
.layer2
=
nn.Sequential(
nn.Conv2d(in_channels
=
64
, out_channels
=
128
, kernel_size
=
3
, padding
=
1
),
nn.BatchNorm2d(
128
),
nn.ReLU(),
nn.MaxPool2d(
2
)
)
self
.layer3
=
nn.Sequential(
nn.Conv2d(in_channels
=
128
, out_channels
=
256
, kernel_size
=
3
, padding
=
1
),
nn.BatchNorm2d(
256
),
nn.ReLU(),
nn.MaxPool2d(
2
)
)
self
.layer4
=
nn.Sequential(
nn.Conv2d(in_channels
=
256
, out_channels
=
512
, kernel_size
=
3
, padding
=
1
),
nn.BatchNorm2d(
512
),
nn.ReLU(),
nn.MaxPool2d(
2
)
)
self
.global_avg_pool
=
nn.AdaptiveAvgPool2d(
1
)
self
.fc
=
nn.Sequential(
nn.Linear(
512
,
4096
),
nn.Dropout(
0.2
),
nn.ReLU(),
nn.Linear(
4096
, gen_ImageCaptcha.captcha_size
*
len
(gen_ImageCaptcha.captcha_array))
)
def
forward(
self
, x):
x
=
self
.layer1(x)
x
=
self
.layer2(x)
x
=
self
.layer3(x)
x
=
self
.layer4(x)
x
=
self
.global_avg_pool(x)
x
=
x.view(x.size(
0
),
-
1
)
x
=
self
.fc(x)
return
x