Coder Social home page Coder Social logo

easezyc / deep-transfer-learning Goto Github PK

View Code? Open in Web Editor NEW
861.0 9.0 203.0 7.16 MB

A collection of implementations of deep domain adaptation algorithms

License: MIT License

Python 100.00%
pytorch deep-transfer-learning domain-adaptation transfer-learning

deep-transfer-learning's People

Contributors

easezyc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deep-transfer-learning's Issues

关于DAN和DDC

您好!在阅读论文时,我发现DAN相比于DDC,除了使用多核MMD外,还增加了多层适配。您认为多层适配是否重要?

TSNE visualization

Hello,
I was going through the paper DSAN and codebase. I was wondering could you make the TSNE visualization available as well. It will be helpful for me. I will cite your paper

Questions about RevGrad

Hi @easezyc ,
thanks for your great implementations.
When I'm trying RevGrad in pytorch1.0, I have some questions.
Would you help me?

  1. In the original paper, it said the optimizer was set as momentum=0.9. However, in line62, the optimizer will be created every iteration, which means momentum will be reset every time.

    ], lr=LEARNING_RATE / 10, momentum=momentum, weight_decay=l2_decay)

  2. The optimizer_critic seems do not optimizer_critic.step().

    optimizer_critic = torch.optim.SGD([

  3. I tried to solve the questions, but I cannot reproduce the reported results. My modifications are below.

# defined optimizer_fea before the training loop
    optimizer_fea = torch.optim.SGD([
        {'params': model.sharedNet.parameters(), 'base_lr': lr/10},
        {'params': model.cls_fn.parameters(), 'base_lr': lr},
        {'params': model.domain_fn.parameters(), 'base_lr': lr}
        ], lr=lr, momentum=momentum, weight_decay=l2_decay)

. . .

for i in range(1, iteration+1):
         # update learning rate during training
        for param_group in optimizer_fea.param_groups:
            param_group['lr'] = param_group['base_lr'] / math.pow((1 + 10 * (i - 1) / iteration), 0.75)

Did I miss anything? Thanks for your help!

A question about cmmd.py

Maybe in cmmd function, threre should be "s_label = torch.zeros(32, args.nc).scatter_(1, s_label.data, 1)" rather than "s_label = torch.zeros(32, 31).scatter_(1, s_label.data, 1)"? Cause when I reviewed the code using "args.nc = 32", I got error like "RuntimeError: Invalid index in scatter". And when I change it and other relevant parts to "args.nc", it works.

关于SRC和TAR类别无法匹配的训练策略

您好,感谢您的工作。
想请教一下目前使用的数据集源类别和目标类别是一致对应的,如果两者类别无法对应的情况(比如SRC中有ABC三类,而TAR中有ABD三类),有什么好的训练策略可以改善效果吗?

Domain-specific Classifier Alignment Loss

In your paper, you have mentioned the discrepancy loss for aligning the classifiers. In your code I did not find the discrepancy loss for classifiers. Did I miss that? Can you please explain it?

Thank you in advanced.

Question about the model selection

Your have done a great job.
But I have a question about the training process.
In the domain adapation scenario, you tune the parameters of the model according to the validation set of source domain or the target domain?
That means, how do you select the best model? According to the evaluation metrics of source domain validation set or the target domain validation set.
Thank you.

How to train hyperspectral images with MRAN

Uploading image.png…
我想使用 MRAN 训练Hyperspectral Image
但是resnet 输入的是244*244的图像。高光谱图像输入是一个像素就是一个类别,需要在哪里修改网络结构

期待您的反馈!

How to understand the MMD Loss?

You have done a great job, but I have a question about the MMD Loss.

You use the guassian kernel for computing, what are the kernel_mul and kernel_num mean in your code?
image
Thank you very much.

Loss and Accuracy are always the same

I tried to run DDC.py,
while testing the average loss and accuracy aren't changed at all.
amazon set: Average loss: 0.0000, Accuracy: 2817/2817 (100.00%)

I tried with different source and target.

MFSAN tSNE

Dear Authors

Thank you very much for your excellent work and for making the code publicly available. As you sent the code for the tSNE visualization to others, I am also requesting the code for MFSAN tSNE. I would really appreciate it. My email: is [email protected]

Thanks in advance

Question about the evaluation or the test with MFSAN

大佬您好,抱歉打扰了。我试了office-31的DW2A,发现结果很好,但是在AD2W跟AW2D上感觉达不到paper的结果。另外office-home的ACP2R也是。我想是不是有什么test上面的tricks?因为像AD2W,D的部分结果是明显好于A的部分,按照代码里头算平均,结果就会弱一些。请问是不是要做一些加权之类的?

关于DFSAN训练过程中数据使用的问题

您好前辈,非常感谢您的代码。

我有几个问题:

  1. 在训练过程中,按理来说想使用全部数据的话一般是外面一层epoch循环,内里一层dataloader的循环。但是我看MFSAN里input只用了iterator的单次next(),所以每次epoch的源域和目标域的大小都只是一个batch_size吗?为什么不每次epoch将源域和目标域的所有图片都做迁移,是考虑到时间成本之类的问题吗?或者是采样的技巧吗?

  2. 跟上个问题性质差不多,举个例子在MFSAN2中,按照您的代码的话,在第一个epoch中,是source1的第一个batch跟target的第一个batch去计算,然后source2的第一个batch是跟target的第二个batch去计算了。target不是同一个batch的话,会不会有些影响?

非常感谢您的回答,祝前辈中好多顶会 :>

A supplement to dataset of DAN

if you are in a situation where soft-loss is equal to 0 and accuracy is 100%, you probably meet the same problem as me. You might need to check your dataset and ensure that sub-classes are under the category folder such as bike and back_pack instead of images. The correct data set layout is shown in the figure. I hope this works and can help you.
示例图片

DAN error report

Hi, thx for ur code.

There's an error when I run the DAN code.

The log can be seen here:
image

The only thing I edited in the code is changing the root_path from /data/zhuyc/OFFICE31/ to ./dataset/Original_images/(except for the print log with "tt" and "ttt"). I checked the size of source data and target data but nothing wrong, both are [32, 3, 224, 224]. Is there any mistake in the code or did I run the wrong way?

Thank you in advance and have a good day :>

关于迁移中测试集和训练集的问题

前辈您好!

再一次来提问,在训练模型过程中要避免测试集和训练集有交集。但是迁移学习中的话也要避免吗?毕竟迁移的训练过程中,目标域是作为无标签的数据来进行迁移的,迁移完后再在目标域上测试,我不知道这样算不算是模型得到了测试集的信息。我之前看您的代码data_loader中是使用了两种transform,但是也很难保证完全没有交集吧?

最近在写别的课题的时候又碰到了这个问题所以想来请教一下。非常感谢!

t-sne

您好,不知您是否还保留DSAN的t-sne可视化的代码,我自己尝试的结果很差,如果您还有存留,可不可以麻烦您发我一份。我的邮箱是[email protected]。麻烦您了!

About DSAN

作者您好,请问您现在还有DSAN中关于t-sne部分的代码吗,自己尝试了很多次,感觉都不太对,如果您还有的话,麻烦您可以发给我吗,我的邮箱是[email protected]。如果打扰到您很抱歉。

Question about RevGrad

In RevGrad, u used confusion_loss. My question why u used this loss as u already used critic loss (domain loss) and classification loss. Can u please explain a little bit on this?

question about dsan

您好,我在运行您提供代码的过程中,由于机器本身的限制(1060 6GB),所以我将batch_size从32改到了16
batch_size = 16 epochs = 200 lr = 0.01 momentum = 0.9 no_cuda =False cuda_id = '0' seed = 1 log_interval = 10 l2_decay = 5e-4 class_num = 31 param = 0.3 bottle_neck = True root_path = "G:/数据集/datasets/" source_name = "amazon" target_name = "dslr"

除了batch_size之外所有的参数没有进行更改,但是模型的准确率一直是100%,请问这是哪里出现了问题。

以及当我试图将backbone模型从resnet50改成resnet18或者34的时候一直会出现问题,RuntimeError: Error(s) in loading state_dict for ResNet: Missing key(s) in state_dict: "layer1.0.conv3.weight", "layer1.0.bn3.weight", "layer1.0.bn3.bias", "layer1.0.bn3.running_mean", "layer1.0.bn3.running_var", "layer1.0.downsample.0.weight", "layer1.0.downsample.1.weight", "layer1.0.downsample.1.bias", "layer1.0.downsample.1.running_mean",这里是报错信息的部份,请问我要如何进行修改。

How to compute the proxy A-distance?

In the work of MRAN, you report the A-distance.

Can you give more explanation on how to compute the A-distance? Or, how about sharing the code?

Thank you very much!

Question about RevGrad

Hi @easezyc ,

You provided both version of the implementation of RevGrad using Pytorch 0.3 and Pytorch 1.0.

In Pytorch 0.3 the code is like that
`class RevGrad(nn.Module):

def __init__(self, num_classes=31):
    super(RevGrad, self).__init__()
    self.sharedNet = resnet50(False)
    self.cls_fc = nn.Linear(2048, num_classes)
    self.domain_fc = nn.Linear(2048, 2)

def forward(self, data):
    data = self.sharedNet(data)
    clabel_pred = self.cls_fc(data)
    dlabel_pred = self.domain_fc(data)

    return clabel_pred, dlabel_pred`

and in Pytorch 1.0 the code is like that:

class RevGrad(nn.Module):

    def __init__(self, num_classes=31):
        super(RevGrad, self).__init__()
        self.sharedNet = resnet50(True)
        self.cls_fn = nn.Linear(2048, num_classes)
        self.domain_fn = AdversarialNetwork(in_feature=2048)
             
    def forward(self, data):
        data = self.sharedNet(data)
        clabel_pred = self.cls_fn(data)
        dlabel_pred = self.domain_fn(AdversarialLayer(high_value=1.0)(data))
        #print(dlabel_pred)
        return clabel_pred, dlabel_pred



class AdversarialNetwork(nn.Module):
    def __init__(self, in_feature):
        super(AdversarialNetwork, self).__init__()
        self.ad_layer1 = nn.Linear(in_feature,1024)
        self.ad_layer2 = nn.Linear(1024,1024)
        self.ad_layer3 = nn.Linear(1024, 1)
        self.ad_layer1.weight.data.normal_(0, 0.01)
        self.ad_layer2.weight.data.normal_(0, 0.01)
        self.ad_layer3.weight.data.normal_(0, 0.3)
        self.ad_layer1.bias.data.fill_(0.0)
        self.ad_layer2.bias.data.fill_(0.0)
        self.ad_layer3.bias.data.fill_(0.0)
        self.relu1 = nn.ReLU()
        self.relu2 = nn.ReLU()
        self.dropout1 = nn.Dropout(0.5)
        self.dropout2 = nn.Dropout(0.5)
        self.sigmoid = nn.Sigmoid()

    def forward(self, x):
        x = self.ad_layer1(x)
        x = self.relu1(x)
        x = self.dropout1(x)
        x = self.ad_layer2(x)
        x = self.relu2(x)
        x = self.dropout2(x)
        x = self.ad_layer3(x)
        x = self.sigmoid(x)
        return x

    def output_num(self):
        return 1
class AdversarialLayer(torch.autograd.Function):
  def __init__(self, high_value=1.0):
    self.iter_num = 0
    self.alpha = 10
    self.low = 0.0
    self.high = high_value
    self.max_iter = 2000.0
    
  def forward(self, input):
    self.iter_num += 1
    output = input * 1.0
    return output

  def backward(self, gradOutput):
    self.coeff = np.float(2.0 * (self.high - self.low) / (1.0 + np.exp(-self.alpha*self.iter_num / self.max_iter)) - (self.high - self.low) + self.low)
    return -self.coeff * gradOutput

My question is which method is correct? If both methods are correct, can you please explain a bit. Thanks in advance.

Reproducing t-SNE results

Hi,

First of all, thanks for the great work!

For DSAN, I am wondering if you can also release the source code of reproducing the T-SNE results. I tried the T-SNE pytorch version but the generated result is different from the one reported in the paper.

UPDATE: I saw there is a closed post that asking for t-SNE implementation and you want them to provide the email address. Would you please also send me a copy of code? My email address is: [email protected]

Thanks for your valuable time and I am looking forward to hearing from you soon!

DSAN

为什么我运行DSAN时达不到论文里的准确率

question about the result of the DAN

I have run the codes in the DAN but the result shows that acc is always 100% no matter what is the source and what is the target. Do you know the reason? Or did I made any mistakes? I run the codes according to your readme. Thanks a lot!

Question about the dataset and ImageFolder in MFSAN

大佬您好,想请问一下MFSAN中关于dataset和ImageFolder的问题。

  1. 我一开始下载您提供的office31,目录的结构是dataset/domain_name/images/class_name/具体图像,直接运行发现准确率100%。想问一下这里默认的结构是不是dataset/domain_name/class_name/具体图像?
  2. 我按照dataset/domain_name/class_name/具体图像设置,但是发现target out of bounds。查看dataloader发现虽然生成了31个label,但是是从1到31而非0-30。想请教把class_number设成32是否可行?以及有没有办法把label弄到0-30?

Problem about the t-SNE

您好,非常棒的工作,谢谢您的开源分享!
我在尝试复现您的工作DSAN,但是t-SNE出来的效果不太理想。
请问在A-->W这个任务上,您t-SNE可视化时选取的源域和目标域的样本分别是多少呢?
我两个域都选取的是480个样本,但出来的图效果不好。
如果可以的话能否分享一下t-SNE的代码呢? email: [email protected]

期待您的回复!谢谢!

Question about the work

Thanks for your work. I wonder if these networks are all based on ResNet? And can you add some additional experiments without adaptation and show the results for comparison? By the way, I am glad to help you because I am also learning these algorithms of domain adaptation and try to reproduce them.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.