你画我猜
最后更新 2020/03/25 22:34
阅读 856
PyTorch ResNet SENet
前排板凳瓜子
5
获得赞0
发布的文章1
答辩的项目Batch大小为1,循环次数为1次,通过在线上环境完成训练,模型最优精度评分为91.54。
最后更新 2020/03/25 22:34
阅读 856
PyTorch ResNet SENet
为了增强人工智能的趣味性,我们开展了你画我猜这一竞赛。你画我猜数据集中包括了40种生活中常见的类别如飞机、苹果、篮球等。图片信息以json格式存储,在每个json中记录了用户每一笔简笔画对应的横坐标集合和纵坐标集合。其中训练集、验证集和测试集划分比例为6:2:2.
以下为给的json示例:
{"drawing": [[[18, 21, 15, 17, 23], [255, 185, 106, 97, 89]], [[17, 7, 3, 0, 9, 19, 29, 40, 41, 30, 28], [70, 60, 50, 26, 4, 0, 12, 39, 49, 75, 88]], [[28, 25, 22, 13, 11, 14, 15, 7, 11], [63, 10, 67, 53, 30, 17, 28, 63, 58]]]}
可以看到数据给的格式是用户绘画是的点的顺序。由于本人对nlp不是很熟悉,因此将此问题转化为图像分类问题。具体就是将这些点在(256, 256, 3)大小的图像上面显示。可视化结果如下:
数据预处理
数据增强
实现mixup数据增强很简单,其实我个人认为这就是一种抑制过拟合的策略,增加了一些扰动,从而提升了模型的泛化能力。
def get_batch(x, y, step, batch_size, alpha=0.2):
candidates_data, candidates_label = x, y
offset = (step * batch_size) % (candidates_data.shape[0] - batch_size)
train_features_batch = candidates_data[offset:(offset + batch_size)]
train_labels_batch = candidates_label[offset:(offset + batch_size)]
if alpha == 0:
return train_features_batch, train_labels_batch
if alpha > 0:
weight = np.random.beta(alpha, alpha, batch_size)
x_weight = weight.reshape(batch_size, 1, 1, 1)
y_weight = weight.reshape(batch_size, 1)
index = np.random.permutation(batch_size)
x1, x2 = train_features_batch, train_features_batch[index]
x = x1 * x_weight + x2 * (1 - x_weight)
y1, y2 = train_labels_batch, train_labels_batch[index]
y = y1 * y_weight + y2 * (1 - y_weight)
return x, y
而模型增前后的效果如下:
模型选择
模型优化
optimizer = torch.optim.SGD(filter(lambda p: p.requires_grad, model.parameters()), lr=lr, momentum=0.9, weight_decay=0.0001, nesterov=True)
最后的总结
首先要使用一个简单的基础模型将流程跑通,得到一个baseline。之后在baseline的基础上添加测试训练技巧,这样可以快速涨分!!
PyTorch ResNet SENet
请先绑定您的微信账号 点击立即绑定
敬请谅解,如有疑问请联系FlyAI客服