你好!我在使用TPU.Some部分代码编译模型时遇到了一些问题,如下所示:
resolver = tf.contrib.cluster_resolver.TPUClusterResolver(TF_MASTER)
tf.contrib.distribute.initialize_tpu_system(resolver)
strategy = tf.contrib.distribute.TPUStrategy(resolver)
with strategy.scope():
model = create_model()
model.compile(optimizer=tf.keras.optimizers.Adadelta(),loss='categorical_crossentropy',metrics='accuracy'])我得到了RuntimeError:enter image description here
你能帮帮我吗?
发布于 2019-10-11 20:45:00
我解决了我的问题,通过各种混沌trying.You可以重新启动你的程序或注释代码:
resolver = tf.contrib.cluster_resolver.TPUClusterResolver
tf.contrib.distribute.initialize_tpu_system(resolver)
strategy = tf.contrib.distribute.TPUStrategy(resolver)
with strategy.scope():
model = create_model()
model.compile()为了避免这个问题
发布于 2020-02-13 02:10:03
同样的问题。看起来默认的TensorFlow版本是1.x。我将代码更改为:(注释3行并添加其他行)
try:
# %tensorflow_version only exists in Colab.
%tensorflow_version 2.x
except Exception:
pass
# resolver = tf.contrib.cluster_resolver.TPUClusterResolver('grpc://' + os.environ['COLAB_TPU_ADDR'])
# tf.contrib.distribute.initialize_tpu_system(resolver)
# strategy = tf.contrib.distribute.TPUStrategy(resolver)
resolver = tf.distribute.cluster_resolver.TPUClusterResolver(tpu='grpc://' + os.environ['COLAB_TPU_ADDR'])
tf.config.experimental_connect_to_cluster(resolver)
tf.tpu.experimental.initialize_tpu_system(resolver)
strategy = tf.distribute.experimental.TPUStrategy(resolver)问题解决了。
https://stackoverflow.com/questions/58144309
复制相似问题