Git Product home page Git Product logo

hneg_src's Introduction

Official Pytorch implementation of "Exploring Patch-wise Semantic Relation for Contrastive Learning in Image-to-Image Translation Tasks" (CVPR 2022)

Chanyong Jung*, Gihyun Kwon*, Jong Chul Ye (* co-first author)

Link: https://arxiv.org/abs/2203.01532

Supplementary Material: https://openaccess.thecvf.com/content/CVPR2022/supplemental/Jung_Exploring_Patch-Wise_Semantic_CVPR_2022_supplemental.pdf

Result_sincut

Cite

@inproceedings{jung2022exploring,
  title={Exploring patch-wise semantic relation for contrastive learning in image-to-image translation tasks},
  author={Jung, Chanyong and Kwon, Gihyun and Ye, Jong Chul},
  booktitle={Proceedings of the IEEE/CVF conference on computer vision and pattern recognition},
  pages={18260--18269},
  year={2022}
}

Environment

$ conda create -n SRC python=3.6
$ pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
$ conda install -c conda-forge packaging 
$ conda install -c conda-forge visdom 
$ conda install -c conda-forge gputil 
$ conda install -c conda-forge dominate 

hneg_src's People

Contributors

cyclomon avatar jcy132 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

Watchers

 avatar  avatar  avatar  avatar  avatar

hneg_src's Issues

questions abou acc

Sorry to bother, I used your pretrained seg models and cut models to test, but I found the acc pixAcc of cityscapes was 83.2, much larger than that of in the paper.
Did I do thing s wrong?

The implementation of PatchHDCELoss

class PatchHDCELoss(nn.Module):
   ...
   ...
        diagonal = torch.eye(npatches, device=feat_q.device, dtype=self.mask_dtype)[None, :, :]
        l_neg_curbatch.masked_fill_(diagonal, -10.0) 
        l_neg = l_neg_curbatch.view(-1, npatches) # [npatches, npatches]

        logits = (l_neg-l_pos)/self.opt.nce_T # [npatches, npatches]
        v = torch.logsumexp(logits, dim=1)    # [npatches]
        loss_vec = torch.exp(v-v.detach())    # [npatches] all elements are 1.0

        # for monitoring
        out_dummy = torch.cat((l_pos, l_neg), dim=1) / self.opt.nce_T # [npatches, npatches+1]
        CELoss_dummy = self.cross_entropy_loss(out_dummy, torch.zeros(out_dummy.size(0), dtype=torch.long, device=feat_q.device))

        loss = loss_vec.mean()-1+CELoss_dummy.detach()

        return loss

Hi, I don't understand 'loss = loss_vec.mean()-1+CELoss_dummy.detach()', which seems to output the same results of 'CELoss_dummy.detach()'. Because 'loss_vec = torch.exp(v-v.detach())' is a tensor with all values of 1, I think ‘loss_vec.mean()-1’ is a tensor with all values of 0. I don't know if this loss is same with infoNCE?

batch size

Hello, the research work in this article is particularly meaningful. The batch size in the code is set to 1 by default, but the following problems occur when I set the batch size to 2 or 3. Can you help me solve this problem.
Looking forward to your reply.

File "train.py", line 44, in
model.data_dependent_initialize(data)
File "/home/cvers/Joe/SM/models/cut_model.py", line 176, in data_dependent_initialize
self.compute_G_loss().backward() # calculate graidents for G
File "/home/cvers/Joe/SM/models/cut_model.py", line 289, in compute_G_loss
self.loss_SRC, weight = self.calculate_R_loss(real_A_pool, fake_B_pool, epoch=self.train_epoch)
File "/home/cvers/Joe/SM/models/cut_model.py", line 335, in calculate_R_loss
loss_SRC, weight = crit(f_q, f_k, only_weight, epoch)
File "/home/cvers/anaconda3/envs/airnet/lib/python3.8/site-packages/torch/nn/modules/module.py", line 722, in call_impl
result = self.forward(*input, **kwargs)
File "/home/cvers/Joe/SM/models/SRC.py", line 55, in forward
weight_seed.masked_fill
(diagonal, -10.0)
RuntimeError: The expanded size of the tensor (768) must match the existing size (256) at non-singleton dimension 2. Target sizes: [1, 768, 768]. Tensor sizes: [1, 256, 256]

Implementation of PatchHDCELoss

Hi, thanks for your great work!

I have a question about the PatchHDCELoss implementation in the Single-modal setting.

In models/hDCE.py,

class PatchHDCELoss(nn.Module):
   ...
   ...
        diagonal = torch.eye(npatches, device=feat_q.device, dtype=self.mask_dtype)[None, :, :]
        l_neg_curbatch.masked_fill_(diagonal, -10.0) 
        l_neg = l_neg_curbatch.view(-1, npatches) # [npatches, npatches]

        logits = (l_neg-l_pos)/self.opt.nce_T # [npatches, npatches]
        v = torch.logsumexp(logits, dim=1)    # [npatches]
        loss_vec = torch.exp(v-v.detach())    # [npatches] all elements are 1.0

        # for monitoring
        out_dummy = torch.cat((l_pos, l_neg), dim=1) / self.opt.nce_T # [npatches, npatches+1]
        CELoss_dummy = self.cross_entropy_loss(out_dummy, torch.zeros(out_dummy.size(0), dtype=torch.long, device=feat_q.device))

        loss = loss_vec.mean()-1+CELoss_dummy.detach()

        return loss

I can't understand your intentions in this implementation.
Which equation in your paper did you implement?
I cannot match this loss to a equation in the paper.
I think I missed something. Please give me some explanation.
Thank you!

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.