【问题标题】:Keras TPU. Compilation failure: Detected unsupported operationsKeras TPU。编译失败:检测到不支持的操作
【发布时间】:2023-03-05 22:59:02
【问题描述】:

我尝试使用 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:编译失败:编译失败:检测到 尝试编译图形时不支持的操作 XLA_TPU_JIT 上的 cluster_3_5095732716396540171[]:ResizeNearestNeighbor (没有为 XLA_TPU_JIT 注册的“ResizeNearestNeighbor”OpKernel 与节点 {{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) .注册:设备='CPU'; [DT_DOUBLE] 中的 T 设备='CPU'; [DT_FLOAT] 中的 T 设备='CPU'; [DT_BFLOAT16] 中的 T 设备='CPU'; [DT_HALF] 中的 T 设备='CPU'; [DT_INT8] 中的 T 设备='CPU'; [DT_UINT8] 中的 T 设备='CPU'; [DT_INT16] 中的 T 设备='CPU'; [DT_UINT16] 中的 T 设备='CPU'; [DT_INT32] 中的 T 设备='CPU'; [DT_INT64] 中的 T ){{node tpu_140211339657168/up_sampling2d_1/ResizeNearestNeighbor}}

【问题讨论】:

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


    【解决方案1】:

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

    您可以查看与 TPU 兼容的 Tensorflow 操作here 的当前列表。也可以使用 Tensorboard 查看TPU Compatibility Graphs

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-12
      • 1970-01-01
      • 2016-03-27
      相关资源
      最近更新 更多