LoginSignup
1
0

More than 3 years have passed since last update.

kerasを学ぶ( model = Model(inputs=inputs, outputs=predictions) )

Last updated at Posted at 2019-08-03

目的

kerasのサイトの以下のコードで、

 Model(inputs=inputs, outputs=predictions)

のような、inとoutの定義で、なぜ、複数のレイヤをもつmodelが構成できるのかがわからなかったので調べた。

from keras.layers import Input, Dense
from keras.models import Model

# This returns a tensor
inputs = Input(shape=(784,))

# a layer instance is callable on a tensor, and returns a tensor
x = Dense(64, activation='relu')(inputs)
x = Dense(64, activation='relu')(x)
predictions = Dense(10, activation='softmax')(x)

# This creates a model that includes
# the Input layer and three Dense layers
model = Model(inputs=inputs, outputs=predictions)コード

調べた結果

以下あたりで、コツコツ接続しているよう。
\site-packages\keras\engine\network.py

def _map_graph_network(inputs, outputs):
    """Validates a network's topology and gather its layers and nodes.

    # Arguments
        inputs: List of input tensors.
        outputs: List of outputs tensors.

まとめ

ネットワーク構造をなんとかするようなコードに慣れていないので、
どうなっているか、まったく、わからなかった。
個々のTensorの属性と関係は、いまだに、厳密には全くわかっていないが、
コツコツつないでいるという想像です。
それらしい動きはしていました。

今後

この程度の調査が、今後の役にたつかは不明。
このあたりのコードは、あまり、バシバシ読めませぬ。
コメントなどあれば、お願いします。:candy:

関連

Grad-CAMで、湖畔と谷とマッシュドポテト、構成と質感認識、VGG16の。

1
0
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
1
0