遇见 YOLO26: 下一代视觉 AI。
Ultralytics
返回 Ultralytics 词汇表

Gradient Descent

探索梯度下降如何优化像 Ultralytics YOLO26 这样的机器学习模型。了解损失函数、反向传播和权重,以提高 AI 准确性。

Gradient Descent is a fundamental iterative optimization algorithm used to train machine learning models and neural networks. Its primary function is to minimize a loss function by systematically adjusting the model's internal parameters, specifically the model weights and biases. You can visualize this process as a hiker attempting to descend a mountain in dense fog; unable to see the bottom, the hiker feels the slope of the ground and takes a step in the steepest downward direction. In the context of machine learning (ML), the "mountain" represents the error landscape, and the "bottom" represents the state where the model's predictions are most accurate. This optimization technique is the engine behind modern artificial intelligence (AI) breakthroughs, powering everything from simple linear regression to complex deep learning architectures like Ultralytics YOLO26.

Link to this section梯度下降的工作原理#

梯度下降的有效性依赖于梯度的计算——即指向损失函数最陡峭增长方向的向量。此计算通常使用反向传播算法执行。一旦确定了方向,算法就会向相反方向更新权重以减少误差。所采取的步长由一个称为学习率的超参数决定。找到最优学习率至关重要;步长过大会导致模型越过最小值,而步长过小则会使训练过程异常缓慢,需要过多的轮次 (epochs) 才能收敛。如需深入了解数学原理,可汗学院提供了关于此主题的多元微积分课程

该过程迭代重复,直到模型到达误差最小化的点,这通常被称为收敛。虽然标准算法会在整个训练数据集上计算梯度,但诸如随机梯度下降 (SGD)等变体则使用较小的子集或单个样本来加速计算并跳出局部最小值。这种适应性使其非常适合在Ultralytics Platform上训练大规模模型,在那里效率和速度至关重要。

Link to this section实际应用#

梯度下降在几乎所有成功的 AI 解决方案背后默默运行,将原始数据转化为跨不同行业的可操作智能。

  • Autonomous Driving: In the development of autonomous vehicles, models must process visual data to identify pedestrians, traffic signs, and other cars. Using object detection architectures like the state-of-the-art YOLO26, Gradient Descent minimizes the difference between the predicted location of an object and its actual position. This ensures that AI in automotive systems can make split-second, life-saving decisions by continuously refining their internal maps of the road.
  • 医学诊断: 在医疗领域,医学图像分析依赖深度学习来检测 MRI 扫描中的肿瘤等异常情况。通过使用梯度下降来优化卷积神经网络 (CNNs),这些系统学会了以高精度区分恶性和良性组织。这通过减少关键诊断中的漏诊,极大地帮助了医疗 AI 专业人员,从而实现更早、更准确的治疗方案。

Link to this section区分相关概念#

在模型开发过程中,区分梯度下降与深度学习 (DL) 词汇表中密切相关的术语非常重要,以避免混淆。

  • 与反向传播的对比: 虽然它们经常被一起提及,但它们在训练循环中执行不同的角色。反向传播是用于计算梯度(确定坡度方向)的方法,而梯度下降是使用这些梯度来更新权重(迈出步伐)的优化算法。反向传播是地图;梯度下降是徒步者。
  • 与 Adam 优化器的对比: Adam 优化器是梯度下降的一种高级演变,它为每个参数使用自适应学习率。这通常比标准 SGD 产生更快的收敛速度。它被广泛用于现代框架中,并且由于其鲁棒性,是训练YOLO11和 YOLO26 等模型的默认选择。
  • 与损失函数的对比: 损失函数(如均方误差或交叉熵)用于衡量模型的表现有多差。梯度下降是改善该表现的过程。损失函数提供评分,而梯度下降提供改善该评分的策略。

Link to this sectionPython 代码示例#

虽然高级库(如 ultralytics)在训练期间抽象化了此过程,但你可以直接使用 PyTorch 查看该机制。以下示例展示了一个简单的优化步骤,我们手动更新一个张量以最小化一个值。

import torch

# Create a tensor representing a weight, tracking gradients
w = torch.tensor([5.0], requires_grad=True)

# Define a simple loss function: (w - 2)^2. Minimum is at w=2.
loss = (w - 2) ** 2

# Backward pass: Calculate the gradient (slope) of the loss with respect to w
loss.backward()

# Perform a single Gradient Descent step
learning_rate = 0.1
with torch.no_grad():
    w -= learning_rate * w.grad  # Update weight: w_new = w_old - (lr * gradient)

print(f"Gradient: {w.grad.item()}")
print(f"Updated Weight: {w.item()}")  # Weight moves closer to 2.0

理解这些基础知识可以让开发者排查收敛问题、有效地调整超参数,并利用诸如Ultralytics Explorer等强大工具来可视化数据集如何与模型训练动态交互。对于那些希望高效部署这些优化后模型的人来说,探索量化感知训练 (QAT)可以进一步提升边缘设备的性能。

Explore solutions

Real-time AI that works with your team

机器人技术中的 AI

使用 Ultralytics YOLO 模型为智能机器赋能。机器人技术中的视觉 AI 可推动自主导航、感知、物体跟踪和实时控制。
了解更多
Real-time AI that works with your team

物流中的 AI

使用 Ultralytics YOLO 模型简化物流。视觉 AI 可实现包裹检查、分拣、车辆跟踪和实时仓库安全监控。
了解更多
Real-time AI that works with your team

零售业 AI

使用 Ultralytics YOLO 模型重塑零售业。视觉 AI 推动库存跟踪、货架监控、队列管理和更智能的客户洞察。
了解更多
Real-time AI that works with your team

医疗保健中的 AI

利用 Ultralytics YOLO 模型构建医疗保健解决方案。医疗保健中的视觉 AI 可助力更快速的医学影像分析、更智能的诊断和患者监测。
了解更多
Real-time AI that works with your team

制造业中的 AI

使用 Ultralytics YOLO 模型优化制造业。视觉 AI 推动质量控制、缺陷检测、PPE 合规性和装配线自动化。
了解更多
Real-time AI that works with your operation

汽车中的 AI

将计算机视觉应用于汽车行业,并配合 Ultralytics YOLO 模型。汽车视觉 AI 可提升道路安全、辅助驾驶和车辆自动化,打造更智能的道路。
了解更多
Real-time AI tailored to your operation

农业中的 AI

借助 Ultralytics YOLO 模型,将视觉 AI 引入智慧农业。赋能作物监测、牲畜追踪和精准农业,实现更高、更智能的产量。
了解更多
Real-time AI that works with your team

机器人技术中的 AI

使用 Ultralytics YOLO 模型为智能机器赋能。机器人技术中的视觉 AI 可推动自主导航、感知、物体跟踪和实时控制。
了解更多
Real-time AI that works with your team

物流中的 AI

使用 Ultralytics YOLO 模型简化物流。视觉 AI 可实现包裹检查、分拣、车辆跟踪和实时仓库安全监控。
了解更多
Real-time AI that works with your team

零售业 AI

使用 Ultralytics YOLO 模型重塑零售业。视觉 AI 推动库存跟踪、货架监控、队列管理和更智能的客户洞察。
了解更多
Real-time AI that works with your team

医疗保健中的 AI

利用 Ultralytics YOLO 模型构建医疗保健解决方案。医疗保健中的视觉 AI 可助力更快速的医学影像分析、更智能的诊断和患者监测。
了解更多
Real-time AI that works with your team

制造业中的 AI

使用 Ultralytics YOLO 模型优化制造业。视觉 AI 推动质量控制、缺陷检测、PPE 合规性和装配线自动化。
了解更多
Real-time AI that works with your operation

汽车中的 AI

将计算机视觉应用于汽车行业,并配合 Ultralytics YOLO 模型。汽车视觉 AI 可提升道路安全、辅助驾驶和车辆自动化,打造更智能的道路。
了解更多
Real-time AI tailored to your operation

农业中的 AI

借助 Ultralytics YOLO 模型,将视觉 AI 引入智慧农业。赋能作物监测、牲畜追踪和精准农业,实现更高、更智能的产量。
了解更多
Real-time AI that works with your team

机器人技术中的 AI

使用 Ultralytics YOLO 模型为智能机器赋能。机器人技术中的视觉 AI 可推动自主导航、感知、物体跟踪和实时控制。
了解更多
Real-time AI that works with your team

物流中的 AI

使用 Ultralytics YOLO 模型简化物流。视觉 AI 可实现包裹检查、分拣、车辆跟踪和实时仓库安全监控。
了解更多
Real-time AI that works with your team

零售业 AI

使用 Ultralytics YOLO 模型重塑零售业。视觉 AI 推动库存跟踪、货架监控、队列管理和更智能的客户洞察。
了解更多
Real-time AI that works with your team

医疗保健中的 AI

利用 Ultralytics YOLO 模型构建医疗保健解决方案。医疗保健中的视觉 AI 可助力更快速的医学影像分析、更智能的诊断和患者监测。
了解更多
Real-time AI that works with your team

制造业中的 AI

使用 Ultralytics YOLO 模型优化制造业。视觉 AI 推动质量控制、缺陷检测、PPE 合规性和装配线自动化。
了解更多
Real-time AI that works with your operation

汽车中的 AI

将计算机视觉应用于汽车行业,并配合 Ultralytics YOLO 模型。汽车视觉 AI 可提升道路安全、辅助驾驶和车辆自动化,打造更智能的道路。
了解更多
Real-time AI tailored to your operation

农业中的 AI

借助 Ultralytics YOLO 模型,将视觉 AI 引入智慧农业。赋能作物监测、牲畜追踪和精准农业,实现更高、更智能的产量。
了解更多

让我们一起构建 AI 的未来!

开启你的机器学习未来之旅