Tensorflow Google Colab:TPU:double的不受支持的数据类型,由输出条件8/合并导致:0

Tensorflow Google Colab:TPU:double的不受支持的数据类型,由输出条件8/合并导致:0,tensorflow,keras,google-colaboratory,google-cloud-tpu,talos,Tensorflow,Keras,Google Colaboratory,Google Cloud Tpu,Talos,我正在使用Talos和Google colabTPU来运行Keras模型的超参数调优。请注意,我使用的是Tensorflow1.15.0和Keras2.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.opt

我正在使用Talos和Google colabTPU来运行Keras模型的超参数调优。请注意,我使用的是Tensorflow1.15.0和Keras2.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

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, name = "relu"))
      model.add(Dense(3, activation=tf.nn.softmax, name = "softmax"))
      model.compile(optimizer=Adam(learning_rate=0.1), loss=params['losses'])

    # Fit the Keras model on the dataset
    out = model.fit(x_train, y_train,
                    batch_size=params['batch_size'], 
                    epochs=params['epochs'],
                    validation_data=[x_val, y_val],
                    verbose=0,
                    steps_per_epoch=2)

    return out, model


x, y = ta.templates.datasets.iris()

# Create a hyperparameter distributions 
p = {'losses': ['logcosh'],
     'batch_size': (20, 50, 5),
     'epochs': [10, 20]}

# Use Talos to scan the best hyperparameters of the Keras model
scan_object = ta.Scan(x, y, model=iris_model, params=p, fraction_limit=0.1, experiment_name='first_test')
使用out=model.fit拟合模型时,我得到以下错误:

InvalidArgumentError                      Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/client/session.py in _do_call(self, fn, *args)
   1382                     '\nsession_config.graph_options.rewrite_options.'
   1383                     'disable_meta_optimizer = True')
-> 1384       raise type(e)(node_def, op, message)
   1385 
   1386   def _extend_graph(self):

InvalidArgumentError: Unsupported data type for TPU: double, caused by output cond_8/Merge:0

TPU最近增加了对double的支持。您现在可以参考所有支持的类型。

尝试将您的x\u-train、y\u-train、x\u-val、y\u-val转换为tf.float32。谢谢,我已经解决了这个问题。我现在面临另一个问题:谢谢你的回复