GPUCodeForces/S1/uucoco_#76/AdversarialLoss_torch.py

26 lines
633 B
Python

import torch
import torch.nn as nn
import torch.nn.functional as F
class Model(nn.Module):
def __init__(self, reduction='mean'):
super().__init__()
self.reduction = reduction
def forward(self, input: torch.Tensor, target: torch.Tensor) -> torch.Tensor:
return F.binary_cross_entropy_with_logits(input, target, reduction=self.reduction)
batch_size = 128
feature_dim = 1
def get_inputs():
pred = torch.randn(batch_size, feature_dim, dtype=torch.float32)
target = torch.randint(0, 2, (batch_size, feature_dim)).float()
return [pred, target]
def get_init_inputs():
return ['mean']