Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: CSPLayerWitnTwoConv originally involves dynamic forwarding, whic… #1041

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions mmyolo/models/layers/yolo_bricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1504,11 +1504,27 @@ def __init__(

def forward(self, x: Tensor) -> Tensor:
"""Forward process."""

#; +---------------------------------+
#; | the original design uses `list` |
#; | which is a dynamic operation |
#; | could not traced by `torch.fx` |
#; +---------------------------------+
# x_main = self.main_conv(x)
# x_main = list(x_main.split((self.mid_channels, self.mid_channels), 1))
# x_main.extend(blocks(x_main[-1]) for blocks in self.blocks)
# return self.final_conv(torch.cat(x_main, 1))

#; the following design keeps the same calculation
#; but in a static way so that `torch.fx` could trace it
#; x = (bs, 64, h, w)
#; x_main = (bs, 64, h, w)
x_main = self.main_conv(x)
x_main = list(x_main.split((self.mid_channels, self.mid_channels), 1))
x_main.extend(blocks(x_main[-1]) for blocks in self.blocks)
return self.final_conv(torch.cat(x_main, 1))

x_main_first_32, x_main_last_32 = \
x_main.split((self.mid_channels, self.mid_channels), dim=1)
for block in self.blocks:
x_main = torch.cat([x_main, block(x_main_last_32)], dim=1)
return self.final_conv(x_main)

class BiFusion(nn.Module):
"""BiFusion Block in YOLOv6.
Expand Down