Skip to Content
PyTorch 中的 AI 和 ML 编码
book

PyTorch 中的 AI 和 ML 编码

by Laurence Moroney
July 2025
Beginner to intermediate
444 pages
6h 20m
Chinese
O'Reilly Media, Inc.
Content preview from PyTorch 中的 AI 和 ML 编码

第 2 章 计算机视觉入门 计算机视觉简介

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

第 1 章介绍了机器学习工作原理的基础知识。你看到了如何入门编程,使用神经网络将数据与标签进行匹配,并从那里看到了如何推断出可用于区分物品的规则。

在本章中,我们将考虑下一个合乎逻辑的步骤,即把这些概念应用到计算机视觉中。在这个过程中,模型会学习如何识别图片中的内容,从而 "看到 "图片中的内容。您将使用一个流行的服装数据集,建立一个能够区分服装的模型,从而 "看到 "不同类型服装之间的区别。

计算机视觉如何工作

计算机视觉是 计算机识别物品的能力,而不仅仅是存储其像素。例如,考虑一下图 2-1 中的服装。它们非常复杂,同一件物品有很多不同的种类。再看看这两双鞋--虽然差别很大,但它们仍然是鞋!

图 2-1. 服装示例

这里有许多不同的可识别服装。你知道衬衫、大衣和裙子之间的区别,也基本上知道这些物品分别是什么,但你怎么向一个从未见过服装的人解释这些呢?那么鞋子呢?这幅图中有两只鞋,但考虑到它们之间的主要区别,你如何向别人解释这两只鞋的区别呢?这也是我们在第 1 章中谈到的基于规则的编程可能会失败的另一个地方。有时候,用规则来描述一件事情是不可行的。

当然,计算机视觉也不例外。但是,想想你是如何学会识别所有这些项目的--通过看到大量不同的示例,积累如何使用它们的经验。计算机也能以同样的方式学习吗?答案是肯定的,但有其局限性。在本章的其余部分,我们将举例说明如何使用一个名为时尚 MNIST 的著名数据集来教计算机识别服装。

时尚 MNIST 数据库

由 Yann LeCun、Corinna Cortes 和 Christopher Burges 创建的修改后的美国国家标准与技术研究院 (MNIST) 数据库是 用于学习和基准测试算法的基础数据集之一。该数据集由 7 万张 0 到 9 的手写数字图像组成,图像为 28 × 28 灰度。

时尚 MNIST的设计目的是替代 MNIST,其记录数、图像尺寸和类别数均与 MNIST 相同。时尚 MNIST 包含 10 种不同类型服装的图像,而不是 0 到 9 的数字图像。

您可以在图 2-2 中看到数据集内容的 示例,其中每种服装类型都有三行。

图 2-2. 探索时尚 MNIST 数据集

时尚 MNIST 的服装种类非常丰富,包括衬衫、长裤、连衣裙和多种类型的鞋子!此外,正如您可能注意到的,数据集是单色的,因此每张图片都由一定数量的像素组成,像素值介于 0 和 255 之间。这使得数据集更易于管理。

您可以从图 2-3 中看到数据集中某张图片的特写。

图 2-3. 时尚 MNIST 数据集中的图像特写

和其他图片一样,这张图片也是由像素组成的矩形网格。在本例中,网格大小为 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

在企业中实施 MLOps

在企业中实施 MLOps

Yaron Haviv, Noah Gift
图解大模型 : 生成式AI 原理与实战

图解大模型 : 生成式AI 原理与实战

Jay Alammar, Maarten Grootendorst

Publisher Resources

ISBN: 9798341662599