美文网首页
操练代码之损失函数

操练代码之损失函数

作者: 万州客 | 来源:发表于2024-08-17 23:11 被阅读0次

同一系列。

一,代码

import torch
import numpy as np
import matplotlib.pyplot as plt


loss = torch.nn.L1Loss(reduction='mean')
input = torch.tensor([1., 2., 3., 4.])
target = torch.tensor([4., 5., 6., 7.])
output = loss(input, target)
print(output)

loss_fn = torch.nn.MSELoss(reduction='mean')
loss = loss_fn(input, output)
print(loss)

entroy = torch.nn.CrossEntropyLoss()
input = torch.Tensor([[-0.1181, -0.3682, -0.2209]])
target = torch.tensor([0])
output = entroy(input, target)
print(output)

a = torch.tensor([1., 2., 3., 4.])
b = torch.tensor([4.1, 51., 6.1, 7.1])
similarity = torch.cosine_similarity(a, b, dim=0)
loss = 1 - similarity
print(loss)

二,输出

2024-08-18 22_59_38-悬浮球.png

相关文章

  • 添加相似度后的 ALS 损失函数

    添加相似度后的损失函数 损失函数的推导 目前代码还未实现在 ALS 的损失函数中添加用户之间相似度的正则化 原因需...

  • Center Loss

    损失函数改进之Center Loss

  • python实现神经网络

    主要提问点 写出softmax损失函数代码(python),以及交叉熵损失函数 判断和消除过拟合的方法dropou...

  • 交叉熵损失函数原理详解

    交叉熵损失函数原理详解 之前在代码中经常看见交叉熵损失函数(CrossEntropy Loss),只知道它是分类问...

  • 机器学习:常见的损失函数

    损失函数简要介绍 0-1损失 绝对值损失 log对数损失函数 平方损失函数 指数损失函数 Hinge损失函数 损失...

  • (4)损失函数

    损失函数用来表示输出与实际值的差距。常用的损失函数为0-1损失函数、平方损失函数、绝对损失函数、对数损失函数、交叉...

  • 【深度学习】

    1, 两个重要的函数:得分函数和损失函数损失函数: hinge损失,softmax 损失。hinge损失: max...

  • 复习,总结(交叉熵,逻辑回归)

    交叉熵 逻辑回归的损失函数,即反向传播 numpy实现代码 tensorflow实现代码

  • 【AlexeyAB DarkNet框架解析】九,YOLOV3损失

    前言 前面已经讲完了YOLOV1/V2的损失函数代码解析,今天为大家带来YOLOv3的损失函数解析。YOLOV3的...

  • 损失函数概述

    常用的损失函数 1.L1损失(绝对损失函数) 和 L2 损失(平方损失函数) L1范数损失函数,也被称为 最小绝对...

网友评论

      本文标题:操练代码之损失函数

      本文链接:https://www.haomeiwen.com/subject/tttpkjtx.html