Skip to Content
PyTorch によるコーダーのための AI および ML
book

PyTorch によるコーダーのための AI および ML

by Laurence Moroney
July 2025
Intermediate to advanced
444 pages
7h 8m
Japanese
O'Reilly Media, Inc.
Content preview from PyTorch によるコーダーのための AI および ML

第4章 PyTorchでデータを使う PyTorchでデータを使う

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

本書の最初の3章では、 、API経由でバンドルされているFashion MNISTデータセットから、APIをダウンロードして前処理する必要があるZIPファイルとして提供されている画像ベースの "Horses or Humans "や "Dogs vs. Cats "データセットまで、様々なデータを使ってモデルを学習した。というわけで、モデルを訓練するためのデータを入手するには、さまざまな方法があることがお分かりいただけただろう。

しかし、多くの公開データセットでは、モデルのアーキテクチャを検討する前に、さまざまなドメイン固有のスキルを学ぶ必要がある。PyTorchドメインとtorch.utils.data.Datasets ネームスペースで利用可能なツールの背後にあるゴールは、データセットを利用しやすい方法で公開することで、データを取得してPyTorchフレンドリーなAPIに取り込むまでのすべての前処理ステップをあなたに代わって行うことだ。

PyTorchがFashion MNISTをどのように扱ったかは、第2章ですでに少し紹介した 。おさらいすると、データを取得するために必要なことはこれだけだ:

train_dataset = datasets.FashionMNIST(root='./data', train=True,
                             download=True, transform=transform)
 

このデータセットの場合、 、Fashion MNISTへの参照を含むデータセットオブジェクトを取得するために、torchvisionライブラリからのインポートも行った:

from torchvision import datasets

このデータセットがコンピュータ・ビジョン指向のデータセットであることを考えると、torchvisionライブラリにあるのは理にかなっている。

PyTorchには、同じ方法で読み込むことができる異なるデータタイプのデータセットが他にもたくさんある。以下のようなものがある:

構想

ファッションMNISTは前述の torchvisionライブラリにある。これは「画像分類」組み込みデータセットのひとつだが、画像検出、セグメンテーション、オプティカルフロー、ステレオマッチング、画像ペアリング、画像キャプション、ビデオ分類、ビデオ予測など、他のシナリオ用のデータセットもたくさんある。

テキスト

一般的なテキストデータセットはtorchtextライブラリで利用できる。ここでは紹介しきれないほどたくさんあるが、テキスト分類、言語モデリング、マシン翻訳、シーケンスタギング、質問と回答、教師なし学習などのリストがある。これらの詳細はPyTorchのドキュメントで発見できる。このライブラリはデータセットだけでなく、テキストを処理するときに使うヘルパー関数もたくさん持っている。

オーディオ

torchaudioライブラリには、 、音や音声のマシンラーニングシナリオで使えるデータセットが多数含まれている。詳細はPyTorchのドキュメントで発見できる。

すべてのデータセットはtorch.utils.data.Dataset, のサブクラスなので、このライブラリを見てよく理解することが重要だ。そうすることで、既存のデータセットを利用するだけでなく、自分で作成して他の人と共有することもできる。 ...

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

生成 Deep Learning ―絵を描き、物語や音楽を作り、ゲームをプレイする

生成 Deep Learning ―絵を描き、物語や音楽を作り、ゲームをプレイする

David Foster, 松田 晃一, 小沼 千絵
ダイナミックリチーミング 第2版 ―5つのパターンによる効果的なチーム編成

ダイナミックリチーミング 第2版 ―5つのパターンによる効果的なチーム編成

Heidi Helfand, 永瀬 美穂, 吉羽 龍太郎, 原田 騎郎, 細澤 あゆみ

Publisher Resources

ISBN: 9798341662636