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


文档摘要

TensorFlow 2.x入门与实战 TensorFlow 2.x是Google开源的机器学习平台。 Keras API 序贯模型 Eager Execution 即时执行 自动求导 AutoML 超参数搜索 TensorFlow 2.x简化了机器学习开发。

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简化了机器学习开发。


发布者: 作者: 转发
评论区 (0)
U