Issues with the published code (and fixes)
Hi, thanks for your research.
I took the liberty to fix some issues I've found in the code. I published it here.
In particular, on Block the mlp_ratio is being passed as float. Usually the MLP uses hidden_dim = int(dim * mlp_ratio) but in the official CFSR released code it uses those variables directly, causing the dtype issue. Another issue I've found was using FloatTensor for sobel and laplacian tensors. Instead, the correct solution would be to ~~use .clone() instead~~ (no need, just pass it directly). I've also added a bool for mean normalization, as the default uses values from ImageNet, which tends to cause issues on other datasets.
Again, thank you for releasing the code for this research, the paper is very interesting :+1:
how about this part?
class Layer(nn.Module):
def __init__(self, dim, depth, dw_size, mlp_ratio=4.0):
super().__init__()
self.blocks = nn.ModuleList([
Block(dim, dw_size, mlp_ratio) for i in range(depth)
])
self.conv = nn.Conv2d(dim, dim, 1)
def forward(self, x):
for blk in self.blocks:
x = blk(x)
return self.conv(x) + x
modify:
class Layer(nn.Module):
def __init__(self, dim, depth, dw_size, mlp_ratio=4.):
super().__init__()
self.blocks = nn.ModuleList([
Block(dim, dw_size, mlp_ratio) for i in range(depth)
])
self.conv = nn.Conv2d(dim, dim, 1)
def forward(self, x):
identity = x
for blk in self.blocks:
x = blk(x)
return self.conv(identity) + x
I wanted to add that I'm not a professional in this field, so I'm not entirely certain about the changes I've suggested. However, based on my understanding, it seems to me that the modification might be beneficial.
@NowLoadY yes, already fixed on the code posted above, if you have interest