执行完就可以得到存储class的txt文件。打开char_std_5990.txt,看到有21个类。
===============================================================
crnn的卷积部分类似VGG,我对模型的改进主要有一下几个方面:
1、加入激活函数Swish。
2、加入BatchNorm。
3、加入SE注意力机制。
4、适当加深模型。
代码如下:
self.cnn = nn.Sequential(
nn.Conv2d(nc, 64, 3, 1, 1), Swish(), nn.BatchNorm2d(64),
nn.MaxPool2d(2, 2), # 64x16x50
nn.Conv2d(64, 128, 3, 1, 1), Swish(), nn.BatchNorm2d(128),
nn.MaxPool2d(2, 2), # 128x8x25
nn.Conv2d(128, 256, 3, 1, 1), nn.BatchNorm2d(256), Swish(), # 256x8x25
nn.Conv2d(256, 256, 3, 1, 1), nn.BatchNorm2d(256), Swish(), # 256x8x25
SELayer(256, 16),
nn.MaxPool2d((2, 2), (2, 1), (0, 1)), # 256x4x25
nn.Conv2d(256, 512, 3, 1, 1), nn.BatchNorm2d(512), Swish(), # 512x4x25
nn.Conv2d(512, 512, 1), nn.BatchNorm2d(512), Swish(),
nn.Conv2d(512, 512, 3, 1, 1), nn.BatchNorm2d(512), Swish(), # 512x4x25
SELayer(512, 16),
nn.MaxPool2d((2, 2), (2, 1), (0, 1)), # 512x2x25
nn.Conv2d(512, 512, 2, 1, 0), nn.BatchNorm2d(512), Swish()) # 512x1x25
SE和Swish
class SELayer(nn.Module):
def init(self, channel, reduction=16):
super(SELayer, self).init()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.fc = nn.Sequential(
nn.Linear(channel, channel // reduction, bias=True),
nn.LeakyReLU(inplace=True),
nn.Linear(channel // reduction, channel, bias=True),
nn.Sigmoid()
)
def forward(self, x):
b, c, _, _ = x.size()
y = self.avg_pool(x).view(b, c)
y = self.fc(y).view(b, c, 1, 1)
return x * y.expand_as(x)
class Swish(nn.Module):
def forward(self, x):
return x * torch.sigmoid(x)
打开train.py ,在训练之前,我们还要调节一下参数。
parser = argparse.ArgumentParser()
parser.add_argument(‘–trainlist’, default=‘train.txt’)
parser.add_argument(‘–vallist’, default=‘val.txt’)
parser.add_argument(‘–workers’, type=int, help=‘number of data loading workers’, default=0)
parser.add_argument(‘–batchSize’, type=int, default=4, help=‘input batch size’)
parser.add_argument(‘–imgH’, type=int, default=32, help=‘the height of the input image to network’)