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

a = Input(shape=(640, 480, 3))
b = Input(shape=(23,))
c = Input(shape=(54,))
d = Dense(32)(b)
multi = Lambda(lambda x: x**3)
e = multi(c)

model_mine = Model(inputs=[a, b, c], outputs=[d, e])
model_mine.summary()

multi是个layer类

abcde都是tensor

model_mine是model类。

最后一句是打印。

没有数据,代码调试:

看一下每个变量的类型:

超简单的keras函数模型教程

代码输出:

Using TensorFlow backend.
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_2 (InputLayer)            (None, 23)           0                                            
__________________________________________________________________________________________________
input_3 (InputLayer)            (None, 54)           0                                            
__________________________________________________________________________________________________
dense_1 (Dense)                 (None, 32)           768         input_2[0][0]                    
__________________________________________________________________________________________________
lambda_1 (Lambda)               (None, 54)           0           input_3[0][0]                    
==================================================================================================
Total params: 768
Trainable params: 768
Non-trainable params: 0
________________________________________________

之前打了很多字都没了。先这样吧。就是model建立需要指定输入输出的tensor.输入输出之间要用layer建立联系。

Dense是全连接

Lambda是自己建立layer对象。这里建立的是立方函数。x=[2,3]讲过multi这个layer会变成[8,27].

 

相关文章:

  • 2021-10-01
  • 2021-12-17
  • 2022-12-23
  • 2021-11-07
  • 2021-12-14
  • 2021-07-17
  • 2021-09-02
  • 2021-08-13
猜你喜欢
  • 2021-04-28
  • 2021-09-02
  • 2021-12-29
  • 2022-12-23
  • 2021-12-29
  • 2021-09-06
  • 2022-01-26
相关资源
相似解决方案