目的
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の属性と関係は、いまだに、厳密には全くわかっていないが、
コツコツつないでいるという想像です。
それらしい動きはしていました。
今後
この程度の調査が、今後の役にたつかは不明。
このあたりのコードは、あまり、バシバシ読めませぬ。
コメントなどあれば、お願いします。