BIT-DA / SePiCo

[TPAMI 2023 ESI Highly Cited Paper] SePiCo: Semantic-Guided Pixel Contrast for Domain Adaptive Semantic Segmentation https://arxiv.org/abs/2204.08808
https://arxiv.org/abs/2204.08808
Other
112 stars 7 forks source link

如果打算像你们那样,给自定义的损失函数传入mask和feat,该如何在mmseg框架下更改? #17

Closed QChhh123 closed 1 year ago

BinhuiXie commented 1 year ago

Hi @QChhh123

Thank you for being so interested.

First, you can follow the tutorial on MMSegmentation to define a new loss function. https://mmsegmentation.readthedocs.io/zh_CN/latest/advanced_guides/add_models.html#loss

In our repo, you can refer to this file contrastive_loss.py. And if you expect feat and mask in the loss function, the following lines might be helpful. https://github.com/BIT-DA/SePiCo/blob/0774b56e2c566e315a25997b915dd68076606149/mmseg/models/losses/contrastive_loss.py#L349-L355

QChhh123 commented 1 year ago

Thank you for your reply. I may not have described my problem clearly. If I expect feat and mask, how to modify the config file? And, in which part, the feat and mask are passed into the contrastive_loss.

---原始邮件--- 发件人: "Binhui Xie @.> 发送时间: 2023年4月8日(周六) 中午11:36 收件人: @.>; 抄送: @.**@.>; 主题: Re: [BIT-DA/SePiCo] 如果打算像你们那样,给自定义的损失函数传入mask和feat,该如何在mmseg框架下更改? (Issue #17)

Hi @QChhh123

Thank you for being so interested.

First, you can follow the tutorial on MMSegmentation to define a new loss function. https://mmsegmentation.readthedocs.io/zh_CN/latest/advanced_guides/add_models.html#loss

In our repo, you can refer to this file contrastive_loss.py. And if you expect feat and mask in the loss function, the following lines might be helpful. https://github.com/BIT-DA/SePiCo/blob/0774b56e2c566e315a25997b915dd68076606149/mmseg/models/losses/contrastive_loss.py#L349-L355

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

BinhuiXie commented 1 year ago
  1. config file

https://github.com/BIT-DA/SePiCo/blob/0774b56e2c566e315a25997b915dd68076606149/configs/_base_/models/daformer_sepaspp_proj_mitb5.py#L11

we define a new SEGMENTORS EncoderDecoderProjector to include the auxiliary head for contrastive loss.

https://github.com/BIT-DA/SePiCo/blob/0774b56e2c566e315a25997b915dd68076606149/configs/_base_/models/daformer_sepaspp_proj_mitb5.py#L36-L50

  1. the path, take the target contrastive loss as an example.

https://github.com/BIT-DA/SePiCo/blob/0774b56e2c566e315a25997b915dd68076606149/mmseg/models/uda/sepico.py#L337-L338

https://github.com/BIT-DA/SePiCo/blob/0774b56e2c566e315a25997b915dd68076606149/mmseg/models/segmentors/encoder_decoder_projector.py#L195-L196

https://github.com/BIT-DA/SePiCo/blob/0774b56e2c566e315a25997b915dd68076606149/mmseg/models/segmentors/encoder_decoder_projector.py#L134-L135

https://github.com/BIT-DA/SePiCo/blob/0774b56e2c566e315a25997b915dd68076606149/mmseg/models/decode_heads/decode_head_decorator.py#L194

https://github.com/BIT-DA/SePiCo/blob/0774b56e2c566e315a25997b915dd68076606149/mmseg/models/losses/contrastive_loss.py#L349-L355

Hope it helps.

QChhh123 commented 1 year ago

Thank you very much for your answer. I have benefited a lot from it

BinhuiXie commented 1 year ago

I believe the issue at hand was addressed, as such I'm closing this. Feel free to ask if you have further questions.