| FFC |
Ran ran on a synthesized input |
HeasonLee/SFIN/sfin.py code served (permissive licence) · get_code("7ad819934fe5ed23") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
# Global channel dimension used by SpectralTransform and FFC
ch = 64
class FourierUnit(nn.Module):
def __init__(self, in_channels, out_channels):
super(FourierUnit, self).__init__()
self.conv_layer = torch.nn.Conv2d(in_channels=in_channels * 2 + 2, out_channels=out_channels * 2, kernel_size=1, stride=1, padding=0, bias=False)
self.bn = torch.nn.BatchNorm2d(out_channels * 2)
self.relu = torch.nn.ReLU(inplace=True)
def forward(self, x):
batch = x.shape[0]
fft_dim = (-2, -1)
ffted = torch.fft.rfftn(x, dim=fft_dim, norm='ortho')
ffted = torch.stack((ffted.real, ffted.imag), dim=-1)
ffted = ffted.permute(0, 1, 4, 2, 3).contiguous()
ffted = ffted.view((batch, -1) + ffted.size()[3:])
height, width = ffted.shape[-2:]
coords_vert = torch.linspace(0, 1, height)[None, None, :, None].expand(batch, 1, height, width).to(ffted)
coords_hor = torch.linspace(0, 1, width)[None, None, None, :].expand(batch, 1, height, width).to(ffted)
ffted = torch.cat((coords_vert, coords_hor, ffted), dim=1)
ffted = self.conv_layer(ffted)
ffted = self.relu(self.bn(ffted))
ffted = ffted.view((batch, -1, 2) + ffted.size()[2:]).permute(0, 1, 3, 4, 2).contiguous()
ffted = torch.complex(ffted[..., 0], ffted[..., 1])
ifft_shape_slice = x.shape[-2:]
output = torch.fft.irfftn(ffted, s=ifft_shape_slice, dim=fft_dim, norm='ortho')
return output
class SpectralTransform(nn.Module):
def __init__(self):
super(SpectralTransform, self).__init__()
self.conv1 = nn.Conv2d(ch // 2, ch // 2, 3, 1, 1)
self.fu = FourierUnit(ch // 2, ch // 2)
self.conv2 = nn.Conv2d(ch, ch // 2, 3, 1, 1)
def forward(self, x):
x1 = self.conv1(x)
x2 = self.fu(x1)
x = self.conv2(torch.cat([x, x2], dim=1))
return x
class FFC(nn.Module):
def __init__(self):
super(FFC, self).__init__()
self.convl2l = nn.Conv2d(ch // 2, ch // 2, 3, 1, 1)
self.convl2g = nn.Conv2d(ch // 2, ch // 2, 3, 1, 1)
self.convg2l = nn.Conv2d(ch // 2, ch // 2, 3, 1, 1)
self.convg2g = SpectralTransform()
def forward(self, x):
x_l, x_g = x if type(x) is tuple else (x, 0)
out_xl = self.convl2l(x_l) + self.convg2l(x_g)
out_xg = self.convl2g(x_l) + self.convg2g(x_g)
return (out_xl, out_xg)
INIT_ARGS = {}
ARGS = {
'x': (torch.randn(2, ch // 2, 4, 3), torch.randn(2, ch // 2, 4, 3))
}
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type tuple — a tuple output has no array shape of its own; none is stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| FourierUnit |
Ran ran on a synthesized input |
HeasonLee/SFIN/sfin.py code served (permissive licence) · get_code("938edd283f0d1f54") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 4, dtype family float, shape (2, 8, 6, 5) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
class FourierUnit(nn.Module):
def __init__(self, in_channels, out_channels):
super(FourierUnit, self).__init__()
self.conv_layer = torch.nn.Conv2d(in_channels=in_channels * 2 + 2, out_channels=out_channels * 2, kernel_size=1, stride=1, padding=0, bias=False)
self.bn = torch.nn.BatchNorm2d(out_channels * 2)
self.relu = torch.nn.ReLU(inplace=True)
def forward(self, x):
batch = x.shape[0]
fft_dim = (-2, -1)
ffted = torch.fft.rfftn(x, dim=fft_dim, norm='ortho')
ffted = torch.stack((ffted.real, ffted.imag), dim=-1)
ffted = ffted.permute(0, 1, 4, 2, 3).contiguous()
ffted = ffted.view((batch, -1) + ffted.size()[3:])
height, width = ffted.shape[-2:]
coords_vert = torch.linspace(0, 1, height)[None, None, :, None].expand(batch, 1, height, width).to(ffted)
coords_hor = torch.linspace(0, 1, width)[None, None, None, :].expand(batch, 1, height, width).to(ffted)
ffted = torch.cat((coords_vert, coords_hor, ffted), dim=1)
ffted = self.conv_layer(ffted)
ffted = self.relu(self.bn(ffted))
ffted = ffted.view((batch, -1, 2) + ffted.size()[2:]).permute(0, 1, 3, 4, 2).contiguous()
ffted = torch.complex(ffted[..., 0], ffted[..., 1])
ifft_shape_slice = x.shape[-2:]
output = torch.fft.irfftn(ffted, s=ifft_shape_slice, dim=fft_dim, norm='ortho')
return output
INIT_ARGS = {
'in_channels': 4,
'out_channels': 8,
}
ARGS = {
'x': torch.randn(2, 4, 6, 5),
}
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Tensor, ndim 4, dtype family float, shape (2, 8, 6, 5) — shape (2, 8, 6, 5) as a later run recorded it
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| ResnetBlock |
Ran ran on a synthesized input |
HeasonLee/SFIN/sfin.py code served (permissive licence) · get_code("ad5952ee597c8808") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 4, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
import numpy as np
# Define the missing SpectralTransform class (already provided in the original class code)
class SpectralTransform(nn.Module):
def __init__(self):
super(SpectralTransform, self).__init__()
self.conv1 = nn.Conv2d(ch // 2, ch // 2, 3, 1, 1)
self.fu = FourierUnit(ch // 2, ch // 2)
self.conv2 = nn.Conv2d(ch, ch // 2, 3, 1, 1)
def forward(self, x):
x1 = self.conv1(x)
x2 = self.fu(x1)
x = self.conv2(torch.cat([x, x2], dim=1))
return x
# Define FourierUnit class (already provided in the original class code)
class FourierUnit(nn.Module):
def __init__(self, in_channels, out_channels):
super(FourierUnit, self).__init__()
self.conv_layer = torch.nn.Conv2d(in_channels=in_channels * 2 + 2, out_channels=out_channels * 2, kernel_size=1, stride=1, padding=0, bias=False)
self.bn = torch.nn.BatchNorm2d(out_channels * 2)
self.relu = torch.nn.ReLU(inplace=True)
def forward(self, x):
batch = x.shape[0]
fft_dim = (-2, -1)
ffted = torch.fft.rfftn(x, dim=fft_dim, norm='ortho')
ffted = torch.stack((ffted.real, ffted.imag), dim=-1)
ffted = ffted.permute(0, 1, 4, 2, 3).contiguous()
ffted = ffted.view((batch, -1) + ffted.size()[3:])
height, width = ffted.shape[-2:]
coords_vert = torch.linspace(0, 1, height)[None, None, :, None].expand(batch, 1, height, width).to(ffted)
coords_hor = torch.linspace(0, 1, width)[None, None, None, :].expand(batch, 1, height, width).to(ffted)
ffted = torch.cat((coords_vert, coords_hor, ffted), dim=1)
ffted = self.conv_layer(ffted)
ffted = self.relu(self.bn(ffted))
ffted = ffted.view((batch, -1, 2) + ffted.size()[2:]).permute(0, 1, 3, 4, 2).contiguous()
ffted = torch.complex(ffted[..., 0], ffted[..., 1])
ifft_shape_slice = x.shape[-2:]
output = torch.fft.irfftn(ffted, s=ifft_shape_slice, dim=fft_dim, norm='ortho')
return output
# Define FFC class (already provided in the original class code)
class FFC(nn.Module):
def __init__(self):
super(FFC, self).__init__()
self.convl2l = nn.Conv2d(ch // 2, ch // 2, 3, 1, 1)
self.convl2g = nn.Conv2d(ch // 2, ch // 2, 3, 1, 1)
self.convg2l = nn.Conv2d(ch // 2, ch // 2, 3, 1, 1)
self.convg2g = SpectralTransform()
def forward(self, x):
x_l, x_g = x if type(x) is tuple else (x, 0)
out_xl = self.convl2l(x_l) + self.convg2l(x_g)
out_xg = self.convl2g(x_l) + self.convg2g(x_g)
return (out_xl, out_xg)
# Define SFIB class (already provided in the original class code)
class SFIB(nn.Module):
def __init__(self):
super(SFIB, self).__init__()
self.ffc = FFC()
self.bn_l = nn.BatchNorm2d(ch // 2)
self.bn_g = nn.BatchNorm2d(ch // 2)
self.act_l = nn.ReLU(inplace=True)
self.act_g = nn.ReLU(inplace=True)
def forward(self, x):
x_l, x_g = self.ffc(x)
x_l = self.act_l(self.bn_l(x_l))
x_g = self.act_g(self.bn_g(x_g))
return (x_l, x_g)
ch = 64
# Setup INIT_ARGS for ResnetBlock (no parameters in __init__)
INIT_ARGS = {}
# Setup ARGS for ResnetBlock.forward
# Input tensor shape: (batch_size, channels, height, width)
batch_size = 2
height, width = 4, 3
input_tensor = torch.randn(batch_size, ch, height, width)
ARGS = {'x': input_tensor}
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Tensor, ndim 4, dtype family float — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| SFIN |
Ran ran on a synthesized input |
HeasonLee/SFIN/sfin.py code served (permissive licence) · get_code("43e3f1f536b57c8c") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 4, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
# Define the missing SpectralTransform class (already provided in the original code)
# Reproduce the full class definitions here to ensure they're available
class SpectralTransform(nn.Module):
def __init__(self):
super(SpectralTransform, self).__init__()
self.conv1 = nn.Conv2d(ch // 2, ch // 2, 3, 1, 1)
self.fu = FourierUnit(ch // 2, ch // 2)
self.conv2 = nn.Conv2d(ch, ch // 2, 3, 1, 1)
def forward(self, x):
x1 = self.conv1(x)
x2 = self.fu(x1)
x = self.conv2(torch.cat([x, x2], dim=1))
return x
class FourierUnit(nn.Module):
def __init__(self, in_channels, out_channels):
super(FourierUnit, self).__init__()
self.conv_layer = torch.nn.Conv2d(in_channels=in_channels * 2 + 2, out_channels=out_channels * 2, kernel_size=1, stride=1, padding=0, bias=False)
self.bn = torch.nn.BatchNorm2d(out_channels * 2)
self.relu = torch.nn.ReLU(inplace=True)
def forward(self, x):
batch = x.shape[0]
fft_dim = (-2, -1)
ffted = torch.fft.rfftn(x, dim=fft_dim, norm='ortho')
ffted = torch.stack((ffted.real, ffted.imag), dim=-1)
ffted = ffted.permute(0, 1, 4, 2, 3).contiguous()
ffted = ffted.view((batch, -1) + ffted.size()[3:])
height, width = ffted.shape[-2:]
coords_vert = torch.linspace(0, 1, height)[None, None, :, None].expand(batch, 1, height, width).to(ffted)
coords_hor = torch.linspace(0, 1, width)[None, None, None, :].expand(batch, 1, height, width).to(ffted)
ffted = torch.cat((coords_vert, coords_hor, ffted), dim=1)
ffted = self.conv_layer(ffted)
ffted = self.relu(self.bn(ffted))
ffted = ffted.view((batch, -1, 2) + ffted.size()[2:]).permute(0, 1, 3, 4, 2).contiguous()
ffted = torch.complex(ffted[..., 0], ffted[..., 1])
ifft_shape_slice = x.shape[-2:]
output = torch.fft.irfftn(ffted, s=ifft_shape_slice, dim=fft_dim, norm='ortho')
return output
class FFC(nn.Module):
def __init__(self):
super(FFC, self).__init__()
self.convl2l = nn.Conv2d(ch // 2, ch // 2, 3, 1, 1)
self.convl2g = nn.Conv2d(ch // 2, ch // 2, 3, 1, 1)
self.convg2l = nn.Conv2d(ch // 2, ch // 2, 3, 1, 1)
self.convg2g = SpectralTransform()
def forward(self, x):
x_l, x_g = x if type(x) is tuple else (x, 0)
out_xl = self.convl2l(x_l) + self.convg2l(x_g)
out_xg = self.convl2g(x_l) + self.convg2g(x_g)
return (out_xl, out_xg)
class SFIB(nn.Module):
def __init__(self):
super(SFIB, self).__init__()
self.ffc = FFC()
self.bn_l = nn.BatchNorm2d(ch // 2)
self.bn_g = nn.BatchNorm2d(ch // 2)
self.act_l = nn.ReLU(inplace=True)
self.act_g = nn.ReLU(inplace=True)
def forward(self, x):
x_l, x_g = self.ffc(x)
x_l = self.act_l(self.bn_l(x_l))
x_g = self.act_g(self.bn_g(x_g))
return (x_l, x_g)
class ResnetBlock(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = SFIB()
self.conv2 = SFIB()
def forward(self, x):
x_l, x_g = torch.split(x, (ch // 2, ch // 2), dim=1)
id_l, id_g = (x_l, x_g)
x_l, x_g = self.conv1((x_l, x_g))
x_l, x_g = self.conv2((x_l, x_g))
x_l, x_g = (id_l + x_l, id_g + x_g)
out = torch.cat((x_l, x_g), dim=1)
return out
ch = 4 # Reduced from 64 to 4 for small stand-in
n_blocks = 2 # Reduced from 8 to 2 for small stand-in
class SFIN(nn.Module):
def __init__(self):
super(SFIN, self).__init__()
self.blocks = []
for i in range(n_blocks):
self.blocks.append(ResnetBlock())
self.body = nn.Sequential(*self.blocks)
self.head_conv = nn.Conv2d(1, ch, 3, 1, 1)
self.tail_conv = nn.Conv2d(ch, 1, 3, 1, 1)
def forward(self, x):
x = self.head_conv(x)
shortcut = x
x = self.body(x)
x += shortcut
x = self.tail_conv(x)
return x
INIT_ARGS = {}
ARGS = {
'x': torch.randn(2, 1, 8, 6) # batch=2, channels=1, height=8, width=6
}
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Tensor, ndim 4, dtype family float — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| SpectralTransform |
Ran ran on a synthesized input |
HeasonLee/SFIN/sfin.py code served (permissive licence) · get_code("dc2f5a847b6f3267") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 4, dtype family float, shape (2, 32, 4, 3) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
class FourierUnit(nn.Module):
def __init__(self, in_channels, out_channels):
super(FourierUnit, self).__init__()
self.conv_layer = torch.nn.Conv2d(in_channels=in_channels * 2 + 2, out_channels=out_channels * 2, kernel_size=1, stride=1, padding=0, bias=False)
self.bn = torch.nn.BatchNorm2d(out_channels * 2)
self.relu = torch.nn.ReLU(inplace=True)
def forward(self, x):
batch = x.shape[0]
fft_dim = (-2, -1)
ffted = torch.fft.rfftn(x, dim=fft_dim, norm='ortho')
ffted = torch.stack((ffted.real, ffted.imag), dim=-1)
ffted = ffted.permute(0, 1, 4, 2, 3).contiguous()
ffted = ffted.view((batch, -1) + ffted.size()[3:])
height, width = ffted.shape[-2:]
coords_vert = torch.linspace(0, 1, height)[None, None, :, None].expand(batch, 1, height, width).to(ffted)
coords_hor = torch.linspace(0, 1, width)[None, None, None, :].expand(batch, 1, height, width).to(ffted)
ffted = torch.cat((coords_vert, coords_hor, ffted), dim=1)
ffted = self.conv_layer(ffted)
ffted = self.relu(self.bn(ffted))
ffted = ffted.view((batch, -1, 2) + ffted.size()[2:]).permute(0, 1, 3, 4, 2).contiguous()
ffted = torch.complex(ffted[..., 0], ffted[..., 1])
ifft_shape_slice = x.shape[-2:]
output = torch.fft.irfftn(ffted, s=ifft_shape_slice, dim=fft_dim, norm='ortho')
return output
ch = 64
class SpectralTransform(nn.Module):
def __init__(self):
super(SpectralTransform, self).__init__()
self.conv1 = nn.Conv2d(ch // 2, ch // 2, 3, 1, 1)
self.fu = FourierUnit(ch // 2, ch // 2)
self.conv2 = nn.Conv2d(ch, ch // 2, 3, 1, 1)
def forward(self, x):
x1 = self.conv1(x)
x2 = self.fu(x1)
x = self.conv2(torch.cat([x, x2], dim=1))
return x
INIT_ARGS = {}
ARGS = {
'x': torch.randn(2, ch // 2, 4, 3)
}
if __name__ == '__main__':
model = SpectralTransform(**INIT_ARGS)
model.eval()
output = model(**ARGS)
print(f"Output shape: {output.shape}")
print(f"Expected shape: (2, {ch // 2}, 4, 3)")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Tensor, ndim 4, dtype family float, shape (2, 32, 4, 3) — shape (2, 32, 4, 3) as a later run recorded it
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| SFIB |
Not yet run unverified (harvested, no recorded run) |
HeasonLee/SFIN/sfin.py code served (permissive licence) · get_code("277fdebe4130953b") How it ran |