Keras是一个高层神经网络API,Keras由纯Python编写而成并基于Tensorflow、Theano以及CNTK后端。Keras为支持快速实验而生,能够把你的idea迅速转换为结果,如果你有如下需求,请选择Keras:
有串联式和函数式两种建模方式,串联式建模方式
model = Sequential()
model.add(Dense(32, input_dim=784))
model.add(Activation('relu'))
def model_name(input_shape, output_shape):
inputs = Input(shape = input_shape, dtype = , name = '')
x = Dense(64 , activation='relu')(inputs)
x = Dense(64,activation='relu')(x)
predictions = Dense(output_shape,activation='softmax')(x)
model = Model(inputs=inputs, outputs=predictions)
return model
from keras import Model ……
model = Model(inputs = input, outputs = output)
model.fit(X_train, Y_train, (X_dev, Y_dev),metric = [])
model.predict(X_test, Y_test)
fit和predict函数有返回值的,最好用一个变量来接住,方便查看预测过程中的变量信息history。model.summary()
使用方法:
Keras.utils.plot_model plot_model(model,to_file='a.png')
结果如下,还可以保存为pdf等格式
例图:
使用方法:
/usr/local/lib/python3.7/site-packages/pycore/
pdflatex filename.tex
,此步骤需要提前拷贝源文件layers中sty文件至tex文件目录,用pdflaetx编译需要texlive环境,请提前安装。这个方法最为硬核,其中mandb还可以横纵向对比多个模型的各个参数,并方便debug和optimize 使用方法:
from rl.callbacks import WandbLogger
import tensorboard
model.fig(巴拉巴拉, callbacks = [函数])
``,在网页localhost可视化
下载安装,导入keras模型.h5即可食用,也支持tf、pytorch等多种模型,界面如下
# model is a Keras model
lr_finder = LRFinder(model)
# Train a model with batch size 512 for 5 epochs
# with learning rate growing exponentially from 0.0001 to 1
lr_finder.find(x_train, y_train, start_lr=0.0001, end_lr=1, batch_size=512, epochs=5)
# Plot the loss, ignore 20 batches in the beginning and 5 in the end
lr_finder.plot_loss(n_skip_beginning=20, n_skip_end=5)
# Plot rate of change of the loss
# Ignore 20 batches in the beginning and 5 in the end
# Smooth the curve using simple moving average of 20 batches
# Limit the range for y axis to (-0.02, 0.01)
lr_finder.plot_loss_change(sma=20, n_skip_beginning=20, n_skip_end=5, y_lim=(-0.01, 0.01))
root\\.keras\models