tensorflow - 凯拉斯 TPU。编译失败 : Detected unsupported operations

标签 tensorflow keras google-colaboratory google-cloud-tpu

我尝试使用 Google Colab TPU 运行我的 keras UNet 模型,但我遇到了这个问题 UpSampling2D .任何解决方案或解决方法?

要运行的代码:

import os
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import UpSampling2D

model = Sequential()
model.add(UpSampling2D((2, 2), input_shape=(16, 16, 1)))
model.compile(optimizer=tf.train.RMSPropOptimizer(learning_rate=0.01), 
              loss='binary_crossentropy', metrics=['acc'])

TPU_WORKER = 'grpc://' + os.environ['COLAB_TPU_ADDR']
tf.logging.set_verbosity(tf.logging.INFO)


model = tf.contrib.tpu.keras_to_tpu_model(
    model,strategy=tf.contrib.tpu.TPUDistributionStrategy(
        tf.contrib.cluster_resolver.TPUClusterResolver(TPU_WORKER)))

X = np.zeros((1024, 16, 16, 1))
Y = np.zeros((1024, 32, 32, 1))

model.fit(X, Y, batch_size=1024)

错误:

RuntimeError: Compilation failed: Compilation failure: Detected unsupported operations when trying to compile graph cluster_3_5095732716396540171[] on XLA_TPU_JIT: ResizeNearestNeighbor (No registered 'ResizeNearestNeighbor' OpKernel for XLA_TPU_JIT devices compatible with node {{node tpu_140211339657168/up_sampling2d_1/ResizeNearestNeighbor}} = ResizeNearestNeighbor[T=DT_FLOAT, align_corners=false, _device="/device:TPU_REPLICATED_CORE"](infeed-train_1:1, tpu_140211339657168/up_sampling2d_1/mul) . Registered: device='CPU'; T in [DT_DOUBLE] device='CPU'; T in [DT_FLOAT] device='CPU'; T in [DT_BFLOAT16] device='CPU'; T in [DT_HALF] device='CPU'; T in [DT_INT8] device='CPU'; T in [DT_UINT8] device='CPU'; T in [DT_INT16] device='CPU'; T in [DT_UINT16] device='CPU'; T in [DT_INT32] device='CPU'; T in [DT_INT64] ){{node tpu_140211339657168/up_sampling2d_1/ResizeNearestNeighbor}}

最佳答案

从错误来看,Keras 的 Tensorflow 后端 ( ResizeNearestNeighbor ) 图中的一项操作目前与 TPU 不兼容。目前有少量 Tensorflow 操作不适用于 TPU ( Cloud TPU FAQs )。

您可以查看与 TPU 兼容的 Tensorflow ops 的当前列表 here .你也可以使用 Tensorboard 查看 TPU Compatibility Graphs .

作为一种解决方法,您可以尝试结合 TPU 兼容的 Tensorflow 操作来复制 ResizeNearestNeighbor 的行为。 .特别是,您可能对 ResizeBilinear 感兴趣Op,它与 TPU 兼容。

关于tensorflow - 凯拉斯 TPU。编译失败 : Detected unsupported operations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52906186/

相关文章:

python - 我已经在我的 google colab 中下载了一个已解压的手套文件,但我仍然无法访问它

tensorflow - 如何使用已安装的 Google 驱动器中的 Tensorflow 在 Google Colab 笔记本中加载图像

python - 如何在Tensorflow中正确设置Adadelta算法的参数?

android - 在手机硬件上运行机器学习模型的可行性?

python - Keras:多类不平衡数据分类过拟合

python - 为什么 fit_generator 的精度与 Keras 中的 evaluate_generator 的精度不同?

tensorflow - 如何使用 Tensorflow 的 Dataset API 将数据移动到多个 GPU 塔

tensorflow - 如何确保使用 sagemaker 安装库?

machine-learning - 使用 ImageDataGenerator 训练的 Keras 模型进行预测的正确方法

python - ModuleNotFoundError : No module named 'libtorrent'