このサイト通りにgoogle colaboratoryでTPUを使おうとしましたが、下のようなエラーがでます。
原因がわからないので教えていただけないでしょうか?
python
1# エラー 2AttributeError: 'Model' object has no attribute 'target_tensors'
python
1# 実行コード 2import tensorflow as tf 3import tensorflow.keras.backend as K 4import numpy as np 5from tensorflow.contrib.tpu.python.tpu import keras_support 6from tensorflow.keras.layers import Input, Conv2D, BatchNormalization, Activation, AveragePooling2D, Dense, Dropout, Flatten 7from tensorflow.keras.datasets import cifar10 8from tensorflow.keras.models import Model, Sequential 9from tensorflow.keras.utils import to_categorical 10import os 11 12def basic_mlp_module(input, units): 13 x = Dense(units)(input) 14 x = BatchNormalization()(x) 15 x = Activation("relu")(x) 16 x = Dropout(0.5)(x) 17 return x 18 19def create_mlp_model(): 20 input = Input((32*32*3,)) 21 x = basic_mlp_module(input, 2048) 22 x = basic_mlp_module(x, 1024) 23 x = basic_mlp_module(x, 512) 24 x = basic_mlp_module(x, 256) 25 x = basic_mlp_module(x, 128) 26 x = basic_mlp_module(x, 64) 27 x = basic_mlp_module(x, 32) 28 x = basic_mlp_module(x, 16) 29 x = Dense(10, activation="softmax")(x) 30 return Model(input, x) 31 32 33K.clear_session() 34 35# CIFAR 36(X_train, y_train), (_, _) = cifar10.load_data() 37X_train = (X_train / 255.0).reshape(50000, -1) 38y_train = to_categorical(y_train) 39 40# モデルを作成 41model = create_mlp_model() 42model.compile(tf.train.AdamOptimizer(learning_rate=1e-3), loss="categorical_crossentropy", metrics=["acc"]) 43 44# TPU 45tpu_grpc_url = "grpc://"+os.environ["COLAB_TPU_ADDR"] 46tpu_cluster_resolver = tf.contrib.cluster_resolver.TPUClusterResolver(tpu_grpc_url) 47strategy = keras_support.TPUDistributionStrategy(tpu_cluster_resolver) 48model = tf.contrib.tpu.keras_to_tpu_model(model, strategy=strategy)
python
1# エラー全文 2W0719 06:46:19.781610 140396333524864 keras_support.py:217] Keras support is now deprecated in support of TPU Strategy. Please follow the distribution strategy guide on tensorflow.org to migrate to the 2.0 supported version. 3W0719 06:46:29.678592 140396333524864 keras_support.py:1394] Keras support is now deprecated in support of TPU Strategy. Please follow the distribution strategy guide on tensorflow.org to migrate to the 2.0 supported version. 4--------------------------------------------------------------------------- 5AttributeError Traceback (most recent call last) 6<ipython-input-36-4751bcfa9298> in <module>() 7 45 tpu_cluster_resolver = tf.contrib.cluster_resolver.TPUClusterResolver(tpu_grpc_url) 8 46 strategy = keras_support.TPUDistributionStrategy(tpu_cluster_resolver) 9---> 47 model = tf.contrib.tpu.keras_to_tpu_model(model, strategy=strategy) 10 112 frames 12/usr/local/lib/python3.6/dist-packages/tensorflow/contrib/tpu/python/tpu/keras_support.py in __init__(self, cpu_model, strategy) 13 1426 self._cpu_model.sample_weight_mode, 14 1427 self._cpu_model._compile_weighted_metrics, 15-> 1428 self._cpu_model.target_tensors, 16 1429 ) 17 1430 18 19AttributeError: 'Model' object has no attribute 'target_tensors'
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/19 23:29