我使用的Talos和谷歌colab TPU运行的超参数调整Keras模型。请注意,我使用的是 Tensorflow 1.15.0 和 Keras 2.2.4-tf。
import os
import tensorflow as tf
import talos as ta
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.optimizers import Adam
from sklearn.model_selection import train_test_split
def iris_model(x_train, y_train, x_val, y_val, params):
# Specify a distributed strategy to use TPU
resolver = tf.contrib.cluster_resolver.TPUClusterResolver(tpu='grpc://' + os.environ['COLAB_TPU_ADDR'])
tf.contrib.distribute.initialize_tpu_system(resolver)
strategy = tf.contrib.distribute.TPUStrategy(resolver)
# Use the strategy to create and compile a Keras model
with strategy.scope():
model = Sequential()
model.add(Dense(32, input_shape=(4,), activation=tf.nn.relu, …Run Code Online (Sandbox Code Playgroud) 我发现的唯一适用于 Keras 函数式 API 的超参数优化库是 Talos。
有谁知道其他任何可行的方法?