1、类class搭建带有跳连的非顺序神经网络
import
train, test——输入特征、标签
class.MyModel(Model) model=MyModel
model.compile——配置训练方法,优化器、损失函数、评价指标
model.fit——训练过程,epoch、batch
model.summary——结构、参数统计
2、结构
class MyModel(Model):
def __init__(self):
super(MyModel, self).__init__()
定义网络结构块
def call(self, x):
调用网络结构块,实现前向传播
return y
model = MyModel()
__init__准备好搭建网络所需要的各种积木,call调用其搭建好的积木,实现前向传播
3、举例
class IrishModel(Model):
def __init__(self):
super(IrishModel, self).__init__()
self.d1 = Dense(3) #该层名为d1,每层由self.引导
def call(self, x):
y = self.d1(x)
return y
model = IrishModel()
4、鸢尾花代码示例
与之前代码相比,增加内容为方框内。