from torch import nn from torch.nn import functional import torch class Entropy_Loss(nn.Module): def __init__(self): super(Entropy_Loss, self).__init__() def forward(self, outputs, labels): # 範例: 使用均方誤差作為損失計算 # outputs = torch.argmax(outputs, 1) outputs = outputs.float() # input shape has a question # print(f"Label result: {labels}, result: {outputs}") labels = labels.float() loss = functional.binary_cross_entropy(outputs[0], labels) return loss