YoeTon / CTUNet

1 stars 0 forks source link

Your work is really great! I would like to ask you about your EBGM module! #1

Open WCWCWCQAQAQA opened 6 days ago

WCWCWCQAQAQA commented 6 days ago

Your improved attention module has deeply inspired my work, could you please share your EGSA code with me so that I can have a deeper understanding of your work?

YoeTon commented 2 days ago

你好,相关部分代码放在附件里了。

------------------ 原始邮件 ------------------ 发件人: "YoeTon/CTUNet" @.>; 发送时间: 2024年9月13日(星期五) 晚上6:43 @.>; @.***>; 主题: [YoeTon/CTUNet] Your work is really great! I would like to ask you about your EBGM module! (Issue #1)

Your improved attention module has deeply inspired my work, could you please share your EGSA code with me so that I can have a deeper understanding of your work?

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

WCWCWCQAQAQA commented 2 days ago

抱歉,我好像没有看到附件,您是不是不小心没点击上呀?

---- Replied Message ---- | From | @.> | | Date | 09/17/2024 17:30 | | To | YoeTon/CTUNet @.> | | Cc | Rui @.>, Author @.> | | Subject | Re: [YoeTon/CTUNet] Your work is really great! I would like to ask you about your EBGM module! (Issue #1) |

你好,相关部分代码放在附件里了。

------------------ 原始邮件 ------------------ 发件人: "YoeTon/CTUNet" @.>; 发送时间: 2024年9月13日(星期五) 晚上6:43 @.>; @.***>; 主题: [YoeTon/CTUNet] Your work is really great! I would like to ask you about your EBGM module! (Issue #1)

Your improved attention module has deeply inspired my work, could you please share your EGSA code with me so that I can have a deeper understanding of your work?

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

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

YoeTon commented 2 days ago

class EGSA(nn.Module):

    def init(self, dim, num_heads, bias):         super(EGSA, self).init()         self.num_heads = num_heads         self.temperature = nn.Parameter(torch.ones(num_heads, 1, 1))         self.conv0 = nn.Conv2d(dim, dim, kernel_size=1, bias=bias)         self.edge_body = edge(dim)         self.conv1 = nn.Conv2d(dim, dim, kernel_size=1, bias=bias)         self.project_out = nn.Conv2d(dim, dim, kernel_size=1, bias=bias)         self.relu = nn.ReLU(inplace=False)

    def forward(self, x):         b, c, h, w = x.shape         x_edge = self.edge_body(x)         x_q = x + 0.01 * x_edge         q = self.conv0(x_q)         k = q         v = self.conv1(x)

        q = rearrange(q, 'b (head c) h w -> b head c (h w)', head=self.num_heads)         k = rearrange(k, 'b (head c) h w -> b head c (h w)', head=self.num_heads)         v = rearrange(v, 'b (head c) h w -> b head c (h w)', head=self.num_heads)         q = torch.nn.functional.normalize(q, dim=-1)         k = torch.nn.functional.normalize(k, dim=-1)

        attn = (q @ k.transpose(-2, -1)) * self.temperature         attn = attn.softmax(dim=-1)

        out = (attn @ v)

        out = rearrange(out, 'b head c (h w) -> b (head c) h w', head=self.num_heads, h=h, w=w)         out = self.project_out(out)         return out

class edge(nn.Module):     def init(self, n_feats):         super(edge, self).init()         self.conv = nn.Conv2d(n_feats * 2, 2, kernel_size=(3, 3), stride=1, padding=(1, 1))

    def forward(self, out):         size = out.size()[2:]         flow = F.interpolate(out, (int(size[0] / 4.), int(size[1] / 4.)), mode='bilinear', align_corners=False)         flow = F.interpolate(flow, size, mode='bilinear', align_corners=False)         flow = self.conv(torch.cat([out, flow], 1))         flow = flow_warp(out, flow, size)

        return out - flow

def flow_warp(input, flow, size):     out_h, out_w = size

    n, c, h, w = input.size()

    norm = torch.tensor([[[[out_w, out_h]]]]).type_as(input).to(input.device)

    h_grid = torch.linspace(-1.0, 1.0, out_h).view(-1, 1).repeat(1, out_w)     w_gird = torch.linspace(-1.0, 1.0, out_w).repeat(out_h, 1)     grid = torch.cat((w_gird.unsqueeze(2), h_grid.unsqueeze(2)), 2)

    grid = grid.repeat(n, 1, 1, 1).type_as(input).to(input.device)     grid = grid + flow.permute(0, 2, 3, 1) / norm

    output = F.grid_sample(input, grid, align_corners=False)

    return output

---Original--- From: "Rui @.> Date: Tue, Sep 17, 2024 18:09 PM To: @.>; Cc: @.**@.>; Subject: Re: [YoeTon/CTUNet] Your work is really great! I would like to ask you about your EBGM module! (Issue #1)

抱歉,我好像没有看到附件,您是不是不小心没点击上呀?

---- Replied Message ---- | From | @.> | | Date | 09/17/2024 17:30 | | To | YoeTon/CTUNet @.> | | Cc | Rui @.>, Author @.> | | Subject | Re: [YoeTon/CTUNet] Your work is really great! I would like to ask you about your EBGM module! (Issue #1) |

你好,相关部分代码放在附件里了。

------------------ 原始邮件 ------------------ 发件人: "YoeTon/CTUNet" @.>; 发送时间: 2024年9月13日(星期五) 晚上6:43 @.>; @.***>; 主题: [YoeTon/CTUNet] Your work is really great! I would like to ask you about your EBGM module! (Issue #1)

Your improved attention module has deeply inspired my work, could you please share your EGSA code with me so that I can have a deeper understanding of your work?

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

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.> — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.>

WCWCWCQAQAQA commented 2 days ago

谢谢您的耐心回复!已看到!