| CosineAnnealingLR_Restart |
Ran ran on a synthesized input |
mdyao/CSNorm/models/CSNorm_model.py code served (permissive licence) · get_code("cdf9cbfb1245b1ef") 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 list, ndim 1, 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 math
from torch.optim.lr_scheduler import _LRScheduler
class CosineAnnealingLR_Restart(_LRScheduler):
def __init__(self, optimizer, T_period, restarts=None, weights=None, eta_min=0, last_epoch=-1):
self.T_period = T_period
self.T_max = self.T_period[0]
self.eta_min = eta_min
self.restarts = restarts if restarts else [0]
self.restart_weights = weights if weights else [1]
self.last_restart = 0
assert len(self.restarts) == len(self.restart_weights), 'restarts and their weights do not match.'
super(CosineAnnealingLR_Restart, self).__init__(optimizer, last_epoch)
def get_lr(self):
if self.last_epoch == 0:
return self.base_lrs
elif self.last_epoch in self.restarts:
self.last_restart = self.last_epoch
self.T_max = self.T_period[self.restarts.index(self.last_epoch) + 1]
weight = self.restart_weights[self.restarts.index(self.last_epoch)]
return [group['initial_lr'] * weight for group in self.optimizer.param_groups]
elif (self.last_epoch - self.last_restart - 1 - self.T_max) % (2 * self.T_max) == 0:
return [group['lr'] + (base_lr - self.eta_min) * (1 - math.cos(math.pi / self.T_max)) / 2 for base_lr, group in zip(self.base_lrs, self.optimizer.param_groups)]
return [(1 + math.cos(math.pi * (self.last_epoch - self.last_restart) / self.T_max)) / (1 + math.cos(math.pi * (self.last_epoch - self.last_restart - 1) / self.T_max)) * (group['lr'] - self.eta_min) + self.eta_min for group in self.optimizer.param_groups]
# Create a simple model and optimizer for testing
model = torch.nn.Linear(4, 2)
optimizer = torch.optim.SGD(model.parameters(), lr=0.1)
INIT_ARGS = {
'optimizer': optimizer,
'T_period': [10, 20],
'restarts': [10],
'weights': [1.0],
'eta_min': 0.0,
'last_epoch': -1
}
ARGS = {}
METHOD = 'get_lr'
# Construct and call
scheduler = CosineAnnealingLR_Restart(**INIT_ARGS)
result = scheduler.get_lr()
- 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 list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
- 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)
|
| FFT_Loss |
Ran ran on a synthesized input |
mdyao/CSNorm/models/CSNorm_model.py code served (permissive licence) · get_code("32b1b52ff3f87906") 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, ndim 1, 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
class FFT_Loss(nn.Module):
def __init__(self, losstype='l2', eps=0.001):
super(FFT_Loss, self).__init__()
def forward(self, x, gt):
x = x + 1e-08
gt = gt + 1e-08
x_freq = torch.fft.rfft2(x, norm='backward')
x_amp = torch.abs(x_freq)
x_phase = torch.angle(x_freq)
gt_freq = torch.fft.rfft2(gt, norm='backward')
gt_amp = torch.abs(gt_freq)
gt_phase = torch.angle(gt_freq)
loss_amp = torch.mean(torch.sum((x_amp - gt_amp) ** 2))
loss_phase = torch.mean(torch.sum((x_phase - gt_phase) ** 2))
return (loss_amp, loss_phase)
INIT_ARGS = {
'losstype': 'l2',
'eps': 0.001
}
ARGS = {
'x': torch.randn(2, 1, 4, 3),
'gt': torch.randn(2, 1, 4, 3)
}
if __name__ == '__main__':
model = FFT_Loss(**INIT_ARGS)
loss_amp, loss_phase = model(**ARGS)
print(f"Loss amplitude: {loss_amp}")
print(f"Loss phase: {loss_phase}")
- 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, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
- 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)
|
| Generate_gate |
Ran ran on a synthesized input |
mdyao/CSNorm/models/CSNorm_model.py code served (permissive licence) · get_code("68eb3cb9baefa822") 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, 512, 1, 1) 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
INIT_ARGS = {}
ARGS = {
'x': torch.randn(2, 512, 4, 3)
}
if __name__ == '__main__':
model = nn.Module()
class Generate_gate(nn.Module):
def __init__(self):
super(Generate_gate, self).__init__()
self.proj = nn.Sequential(nn.AdaptiveAvgPool2d(1), nn.Conv2d(512, 256, 1), nn.ReLU(), nn.Conv2d(256, 512, 1), nn.ReLU())
self.epsilon = 1e-08
def forward(self, x):
alpha = self.proj(x)
gate = alpha ** 2 / (alpha ** 2 + self.epsilon)
return gate
model = Generate_gate(**INIT_ARGS)
output = model(**ARGS)
print(f"Output shape: {output.shape}")
print(f"Output: {output}")
- 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, 512, 1, 1) — shape (2, 512, 1, 1) 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)
|
| MultiStepLR_Restart |
Ran ran on a synthesized input |
mdyao/CSNorm/models/CSNorm_model.py code served (permissive licence) · get_code("046fd7a21286d589") 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 list, ndim 1, 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
from torch.optim import SGD
from collections import Counter, defaultdict
from torch.optim.lr_scheduler import _LRScheduler
class MultiStepLR_Restart(_LRScheduler):
def __init__(self, optimizer, milestones, restarts=None, weights=None, gamma=0.1, clear_state=False, last_epoch=-1):
self.milestones = Counter(milestones)
self.gamma = gamma
self.clear_state = clear_state
self.restarts = restarts if restarts else [0]
self.restart_weights = weights if weights else [1]
assert len(self.restarts) == len(self.restart_weights), 'restarts and their weights do not match.'
super(MultiStepLR_Restart, self).__init__(optimizer, last_epoch)
def get_lr(self):
if self.last_epoch in self.restarts:
if self.clear_state:
self.optimizer.state = defaultdict(dict)
weight = self.restart_weights[self.restarts.index(self.last_epoch)]
return [group['initial_lr'] * weight for group in self.optimizer.param_groups]
if self.last_epoch not in self.milestones:
return [group['lr'] for group in self.optimizer.param_groups]
return [group['lr'] * self.gamma ** self.milestones[self.last_epoch] for group in self.optimizer.param_groups]
# Create a simple model for the optimizer
model = torch.nn.Linear(4, 3)
optimizer = SGD(model.parameters(), lr=0.1)
INIT_ARGS = {
'optimizer': optimizer,
'milestones': [2, 4, 6],
'restarts': [0, 3, 5],
'weights': [1.0, 0.5, 0.25],
'gamma': 0.1,
'clear_state': False,
'last_epoch': -1
}
ARGS = {}
METHOD = 'get_lr'
# Construct and call
scheduler = MultiStepLR_Restart(**INIT_ARGS)
result = scheduler.get_lr()
- 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 list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
- 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)
|
| NAFNet |
Ran ran on a synthesized input |
mdyao/CSNorm/models/CSNorm_model.py code served (permissive licence) · get_code("21782d8f27153a1a") 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
# INIT_ARGS for NAFNet.__init__
INIT_ARGS = {
'img_channel': 3,
'width': 8,
'middle_blk_num': 1,
'enc_blk_nums': [1, 1],
'dec_blk_nums': [1, 1]
}
# ARGS for NAFNet.forward
# The input should be a 4D tensor: (batch, channels, height, width)
# channels must match img_channel, and spatial dims should be divisible by 2^len(enc_blk_nums)
ARGS = {
'inp': torch.randn(2, 3, 16, 16)
}
- 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)
|
| SSIMLoss |
Ran ran on a synthesized input |
mdyao/CSNorm/models/CSNorm_model.py code served (permissive licence) · get_code("b5d17b4ab3aea4df") 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 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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
from math import exp
def gaussian(window_size, sigma):
gauss = torch.Tensor([exp(-(x - window_size // 2) ** 2 / float(2 * sigma ** 2)) for x in range(window_size)])
return gauss / gauss.sum()
def create_window(window_size, channel):
_1D_window = gaussian(window_size, 1.5).unsqueeze(1)
_2D_window = _1D_window.mm(_1D_window.t()).float().unsqueeze(0).unsqueeze(0)
window = _2D_window.expand(channel, 1, window_size, window_size).contiguous()
return window
def _ssim(img1, img2, window, window_size, channel, size_average=True):
import torch.nn.functional as F
mu1 = F.conv2d(img1, window, padding=window_size // 2, groups=channel)
mu2 = F.conv2d(img2, window, padding=window_size // 2, groups=channel)
mu1_sq = mu1.pow(2)
mu2_sq = mu2.pow(2)
mu1_mu2 = mu1 * mu2
sigma1_sq = F.conv2d(img1 * img1, window, padding=window_size // 2, groups=channel) - mu1_sq
sigma2_sq = F.conv2d(img2 * img2, window, padding=window_size // 2, groups=channel) - mu2_sq
sigma12 = F.conv2d(img1 * img2, window, padding=window_size // 2, groups=channel) - mu1_mu2
C1 = 0.01 ** 2
C2 = 0.03 ** 2
ssim_map = (2 * mu1_mu2 + C1) * (2 * sigma12 + C2) / ((mu1_sq + mu2_sq + C1) * (sigma1_sq + sigma2_sq + C2))
if size_average:
return -1 * ssim_map.mean()
else:
return -1 * ssim_map.mean(1).mean(1).mean(1)
class SSIMLoss(torch.nn.Module):
def __init__(self, window_size=11, size_average=True):
super(SSIMLoss, self).__init__()
self.window_size = window_size
self.size_average = size_average
self.channel = 1
self.window = create_window(window_size, self.channel)
def forward(self, img1, img2):
import torch.nn.functional as F
_, channel, _, _ = img1.size()
if channel == self.channel and self.window.data.type() == img1.data.type():
window = self.window
else:
window = create_window(self.window_size, channel)
if img1.is_cuda:
window = window.cuda(img1.get_device())
window = window.type_as(img1)
self.window = window
self.channel = channel
return _ssim(img1, img2, window, self.window_size, channel, self.size_average)
INIT_ARGS = {
'window_size': 11,
'size_average': True,
}
ARGS = {
'img1': torch.randn(2, 1, 32, 32),
'img2': torch.randn(2, 1, 32, 32),
}
if __name__ == '__main__':
model = SSIMLoss(**INIT_ARGS)
output = model(**ARGS)
print(f"Output shape: {output.shape}")
print(f"Output value: {output.item()}")
- 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 0, dtype family float, shape () — shape () 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)
|
| _ssim |
Ran ran; our contract draft was wrong, not the code |
mdyao/CSNorm/models/CSNorm_model.py code served (permissive licence) · get_code("f4be0291174eaba1") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 0, dtype family float, shape () 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
torch.manual_seed(0)
# Create small image tensors (batch_size=2, channels=3, height=4, width=4)
img1 = torch.randn(2, 3, 4, 4)
img2 = torch.randn(2, 3, 4, 4)
# Create a Gaussian window for SSIM calculation
# window_size = 11, channels = 3
window_size = 11
channel = 3
# Create a simple Gaussian window
sigma = 1.5
x = torch.arange(window_size).float() - (window_size - 1) / 2.0
gaussian_1d = torch.exp(-x.pow(2) / (2 * sigma ** 2))
gaussian_1d = gaussian_1d / gaussian_1d.sum()
# Create 2D window and expand for channels
window = gaussian_1d.unsqueeze(1) * gaussian_1d.unsqueeze(0)
window = window.unsqueeze(0).unsqueeze(0) # shape: (1, 1, 11, 11)
window = window.expand(channel, 1, window_size, window_size) # shape: (3, 1, 11, 11)
ARGS = {
"img1": img1,
"img2": img2,
"window": window,
"window_size": window_size,
"channel": channel,
"size_average": True
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- 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 0, dtype family float, shape () — shape () 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: none by the harness; any seed is in the setup block
|
| BaseModel |
Not yet run unverified (harvested, no recorded run) |
mdyao/CSNorm/models/CSNorm_model.py code served (permissive licence) · get_code("911948c0e6e6d01c") How it ran |
| CSNorm_Model |
Not yet run unverified (harvested, no recorded run) |
mdyao/CSNorm/models/CSNorm_model.py code served (permissive licence) · get_code("4f6a8930f4d094cf") How it ran |
| define_G |
Not yet run unverified (harvested, no recorded run) |
mdyao/CSNorm/models/CSNorm_model.py code served (permissive licence) · get_code("8a9cf80181d95bfa") How it ran |
| freeze_direct |
Not yet run unverified (harvested, no recorded run) |
mdyao/CSNorm/models/CSNorm_model.py code served (permissive licence) · get_code("271899e6c882ad1e") How it ran |