我正在尝试将 Google 云控制台中的 Keras 模型转换为 TPU 模型。不幸的是,我收到如下所示的错误。我的最小示例如下:
import keras
from keras.models import Sequential
from keras.layers import Dense, Activation
import tensorflow as tf
import os
model = Sequential()
model.add(Dense(32, input_dim=784))
model.add(Dense(32))
model.add(Activation('relu'))
model.compile(optimizer='rmsprop', loss='mse')
tpu_model = tf.contrib.tpu.keras_to_tpu_model(
model,
strategy=tf.contrib.tpu.TPUDistributionStrategy(
tf.contrib.cluster_resolver.TPUClusterResolver(TPU_WORKER)))
我的输出是:
Using TensorFlow backend.
Traceback (most recent call last):
File "cloud_python4.py", line 11, in <module>
tpu_model = tf.contrib.tpu.keras_to_tpu_model(AttributeError: module 'tensorflow.contrib.tpu' has no attribute 'keras_to_tpu_model'
keras_to_tpu_model 方法似乎是实验性的,如 tensorflow 网站所示。它最近被删除了吗?如果是这样,我该如何继续使用 TPU 来估计我的 Keras 模型?如果 keras_to_tpu_model 方法仍然可用,为什么我不能调用它?