资源简介
莫烦深度学习 Python + Keras视频课程的源代码 kerasTUT
代码片段和文件信息
“““
To know more or get code samples please visit my website:
https://morvanzhou.github.io/tutorials/
Or search: 莫烦Python
Thank you for supporting!
“““
# please note all tutorial code are running under python3.5.
# If you use the version like python2.7 please modify the code accordingly
# 10 - save
import numpy as np
np.random.seed(1337) # for reproducibility
from keras.models import Sequential
from keras.layers import Dense
from keras.models import load_model
# create some data
X = np.linspace(-1 1 200)
np.random.shuffle(X) # randomize the data
Y = 0.5 * X + 2 + np.random.normal(0 0.05 (200 ))
X_train Y_train = X[:160] Y[:160] # first 160 data points
X_test Y_test = X[160:] Y[160:] # last 40 data points
model = Sequential()
model.add(Dense(output_dim=1 input_dim=1))
model.compile(loss=‘mse‘ optimizer=‘sgd‘)
for step in range(301):
cost = model.train_on_batch(X_train Y_train)
# save
print(‘test before save: ‘ model.predict(X_test[0:2]))
model.save(‘my_model.h5‘) # HDF5 file you have to pip3 install h5py if don‘t have it
del model # deletes the existing model
# load
model = load_model(‘my_model.h5‘)
print(‘test after load: ‘ model.predict(X_test[0:2]))
“““
# save and load weights
model.save_weights(‘my_model_weights.h5‘)
model.load_weights(‘my_model_weights.h5‘)
# save and load fresh network without trained weights
from keras.models import model_from_json
json_string = model.to_json()
model = model_from_json(json_string)
“““
相关资源
- Python-Keras实现的DeepSpeech端到端语音识
- Machine Learning with Python Cookbook
- Keras-2.3.1-py2.py3-none-any.whl
- keras实现cifar-10图片分类
- keras+tensorflow CNN
- mnist_mlp.py
- Python-PythonTensorflowKeras实现参数tSNE算法
- Python-图像分割Keras在Keras中实现Segne
- keras_contrib[离线安装].zip
- 非常简易的keras函数式Functional模型学
- python+tensorflow+keras 基于Inception-v3模型
评论
共有 条评论