LoginSignup
7
8

More than 3 years have passed since last update.

テンソル(Tensor)の理解(3) : Real World Data

Last updated at Posted at 2020-03-12

1.はじめに

Tensorの理解に必要な情報を、自分用メモとして整理します。
今日は、ディープランニングの実世界で使われるデータの例を挙げ、
そのデータがテンソルとしてどう表現されているかについてご紹介します。

そして、各データがテンソルのShapeとしてどう表現されるか、注意をしながら読んでいただければと思います。

前回のポストは、こちらになります。
1. テンソル(Tensor)の理解 (1) : Dimension
2. テンソル(Tensor)の理解 (2) : Shape

2.テンソルとは?

  1. Tensor is a just a container for data.
  2. The data are almost numerical data
  3. Therefore, Tensor is a container for number.

テンソルは、数字を入れるコンテナです。シンプルですね。

3.テンソルの実例(Real World Data)

下記のテーブルに、ディープランニングの実世界でよく使われるデータとそのテンソル情報を示します。

データの例 名称 Tensor Shape
Vector Data* Matrix 2D Tensor (sample, feature)
Time Series Data 3D Tensor 3D Tensor (sample, timestep, feature)
Images 4D Tensor 4D Tensor (sample, height, width, channel)
Video 5D Tensor 5D Tensor (sample, frame, height, width, channel)
  • Vector data is different with Vector. Vector is 1D tensor.
  • ベクトルデータは、機械学習でよく使われるテーブル型のデータを意味します。ベクトルではなく、ベクトルデータだることに注意しましょう。

3.1. Vector Data(2D Tensor)

人のリストのデータの例を挙げます。何等かの選挙名簿だと考えてください。
リスト中の各公人を説明する特徴量(Features)として、年齢(Age),郵便番号(ZIP Code),収入(Income)を選び、10000人(Samples)のデータを集めたとします。
データがマトリックス状になりますので、2Dテンソルとなります。この2DテンソルのShapeは、(Sample, Feature)=(10000,3)です。
image.png

3.2.Time Series Data(3D Tensor)

ある会社の1年間の株価を時系列データを考えます。

このデータの構成を考えます。
株価は、1年中250営業日のデータが集まります。
株価は1分単位で集計します。株式市場は390分のデータが集まります。
株買の特徴量として、Current Price, the Highest Price, the Lowest Priceの三つを選びます。

従って、この時系列のShapeは、(Sample, Timestep, Feature) = (250, 390, 3)となります。

image.png

3.3. Images(4D Tensor)

画像のデータです。
まず、128枚の画像データがあるとします。
次に、解像度が256X256 pixelsとします。
カラー画像とし、三つのチャンネル(R,G,B)で構成されています。

従って、この画像データのShapeは、(Sample, height, width, channel) = (128, 256, 256, 3)となります。
image.png

3.4. Video(5D Tensor)

動画のデータです。
例えば、解像度144X156の60秒のカラー動画データが4本あるとします。
この動画のFrame rateを4fpsと仮定しますと、約240フレーム(240 frame = 60 sec * 4 frame/sec)で構成されることになります。

従って、この動画データのShapeは、(Sample, Frames, Height, Width, Channel) = (4, 240, 144, 156, 3) となります。

image.png

4.まとめ

データの例 詳細 Tensor Shape
Vector Data* Personal Data image.png 2D Tensor (sample, feature)=(10000, 3)
Time Series Data Annual Stock Data image.png 3D Tensor (sample, timestep, feature) = (250, 260, 3)
Images Batch of Color Images image.png 4D Tensor (sample, height, width, channel)=(128,256,256,3)
Video Batch of Video Frames image.png 5D Tensor (sample, frame, height, width, channel)=(4,240,144,156,3)
  • Vector data is different with Vector. Vector is 1D tensor.

5. 参考資料

  1. テンソル(Tensor)の理解 (1) : Dimension
  2. テンソル(Tensor)の理解 (2) : Shape
7
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
8