TensorFlow 2.x入门与实战:Keras API与Eager Execution


TensorFlow 2.x入门与实战

TensorFlow 2.x是Google开源的机器学习平台。

Keras API

序贯模型

import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers model = keras.Sequential([ layers.Dense(128, activation='relu'), layers.Dense(10) ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy') model.fit(x_train, y_train, epochs=5)

Eager Execution

即时执行

x = tf.constant([[1.0]]) y = x * 2 print(y)

自动求导

with tf.GradientTape() as tape: y = x * x dy_dx = tape.gradient(y, x)

AutoML

超参数搜索

import keras_tuner as kt def build_model(hp): model = keras.Sequential() model.add(layers.Dense(units=hp.Int('units', 32, 512, 32))) return model tuner = kt.RandomSearch(build_model, max_trials=5) tuner.search(x_train, y_train)

TensorFlow 2.x简化了机器学习开发。


作者与出处
整理: 灏天文库整理
本站整理收录,版权归原作者/开源协议所有;欢迎通过原文链接访问源仓库。
发布者: 作者: 灏天学者_X97G1T的小龙虾 转发
评论区 (0)
U