自学内容网 自学内容网

李宏毅机器学习2023-HW11-Domain Adaptation

Task

Domain Adaptation
通过训练真实图片得到分类模型,并将其应用到涂鸦图片上进行分类,来获得更高的精准度。
在这里插入图片描述

Link

kaggle
colab

Baseline

Simple Baseline

acc≥0.44280, < 1hour
Just run the code and submit answer.

Medium Baseline

acc≥0.65994, 2~4 hours
方法:增加epoch+ 改变 λ 值

  • Set proper λ in DaNN algorithm.
  • Training more epochs.
    epoch从200增加到800,λ 从0.1变为0.7,提升lambλ 意味着更注重domain classifier的表现,让source domain和target domain的表现更一致,不过也不能一直提升,太大会影响label predictor的能力

Strong Baseline

acc≥0.75342, 5~6 hours
增加epoch+ 动态调整 λ 值。将epoch调整到1000。根据DANN论文,可使用动态调整的 λ 值,从0.02动态的调整为1,这样前期可让label predictor更准确,后期更注重domain classifier的表现

代码中输出了0, 199, 399, 599, 799, 999 epoch的训练效果图。在这些epoch,将5000张source和target图片,输入到feature_extractor模型,每张图片的输出是一个512维度的图片,然后利用t-SNE方法降维到2维,最后画出source图片的不同类别分布图和source target分布对比度。随着epoch增加,target和source的分布基本一致了,达到了DANN模型的目的。 这里不展示,具体可见代码

for epoch in range(epochs):
    lamb = np.log(1.02 + 1.7*epoch/epochs)
    train_D_loss, train_F_loss, train_acc = train_epoch(source_dataloader, target_dataloader, lamb=lamb)
def visualization(features):
    for i, feature in enumerate(features):
        data = np.concatenate([feature.X, feature.TX])
        num_source = len(feature.labels)
        X_tsne = manifold.TSNE(n_components=2, init='random', random_state=5, verbose=1).fit_transform(data)
        # Normalization the processed features 
        x_min, x_max = X_tsne.min(0), X_tsne.max(0)
        X_norm = (X_tsne - x_min) / (x_max - x_min)
    
        plt.figure(figsize=(16, 8))
        plt.subplot(121)
        plt.title(f'epoch {marked_epoch[i]}:distribution of features accross different class')
        plt.scatter(X_norm[:num_source, 0], X_norm[:num_source, 1], c=feature.labels, label='source domain')
        plt.subplot(122)
        plt.title(f'epoch {marked_epoch[i]}:distribution of features accross different domain')
        plt.scatter(X_norm[:num_source, 0], X_norm[:num_source, 1], c='b', label='source domain')
        plt.scatter(X_norm[num_source:, 0], X_norm[num_source:, 1], c='r', label='target domain', alpha=0.5)
        plt.legend()
    plt.show()

Boss Baseline

acc ≥0.81072

  • 调整参数:optimizer, learning rate, set lr_scheduler, etc…
  • Ensemble: Ensemble the model or output you tried.
  • 其他advanced adversarial training,比如DALN
  • Semi-supervised learning
  • Universal Domain Adaptation

借鉴DIRT的两步训练法
这里利用DANN模型生成伪标签(pseudo-label)。第一步用adversarial的方法训练一个模型,这里我们使用strong baseline得到的模型;第二步是利用第一步产生的模型,对target图片生成伪标签,有了标签,就可以对target做有监督学习,该方法能充分利用模型的潜在价值。
在具体的实现环节,为了保证伪标签的可靠性,设计了一个超参数赋值0.95,所产生的伪标签概率高于该值才被使用,另外为保证训练的稳定性,使用了teacher网络,利用teacher网络生成伪标签,teacher网络的初始值也来自strong base模型,在训练过程中,teacher网络更新比较慢,做法是设计了一个超参数赋值0.9,teacher网络的更新中0.9的权重来自于自己,0.1的权重来自于主干网络


原文地址:https://blog.csdn.net/qq_42875127/article/details/142415019

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!