Keras_notes

Keras

https://keras.io


Keras models

There are two main models: the Sequential model and the Model class. So models are class.
They have methods and attributes in common.

  • model.layers
  • model.inputs
  • model.outputs
  • model.summary()
  • model.get_config()
  • model.get_weights()
  • model.set_weights(weights)
  • model.to_json
  • model.to_yaml()
  • model.save_weights(filepath)
  • model.load_weights(filepath, by_name=False)
    You can create model by subclassing the Model class.
import keras
class SimpleMLP(keras.Model):
    def __init__(self, use_bn=False, use_dp=False, num_classes=10):
        ...
    def call(self, inputs):
        ...
model = SimpleMLP()
model.compile(...)
model.fit(...)

Sequential model

The Sequential model is a linear stack of layers.

import keras
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D
model = Sequential()
conv1_1 = Conv2D(32, (3,3), activation='relu', input_shape=(100,100,3))
conv1_2 = Conv2D(32, (3,3), activation='relu')
pool1 = MaxPooling2D(pool_size=(2,2))
model.add(conv1_1)
model.add(conv1_2)
model.add(pool1)

layers

If a layer has a single node

  • layer.input
  • layer.output
  • layer.input_shape
  • layer.output_shape
    If a layer has multiple nodes
  • layer.get_input_at(node_index)
  • layer.get_output_at(node_index)
  • layer.get_input_shape_at(node_index)
  • layer.get_output_shape_at(node_index)

Visualization

from keras.utils import plot_model
plot_model(model, to_file='model.png')

Applications

from keras.applications.vgg16 import VGG16
vgg16_model = VGG16(weights='imagenet', include_top=True)
plot_model(vgg16_model, to_file='vgg16_model.png')
Downloading data from https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels.h5
553467904/553467096 [==============================] - 55s 0us/step
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值