質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Google Colaboratory

Google Colaboratoryとは、無償のJupyterノートブック環境。教育や研究機関の機械学習の普及のためのGoogleの研究プロジェクトです。PythonやNumpyといった機械学習で要する大方の環境がすでに構築されており、コードの記述・実行、解析の保存・共有などが可能です。

Q&A

解決済

1回答

1883閲覧

google colaboratoryでTPUが使えないエラーについて

trafalbad

総合スコア303

Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Google Colaboratory

Google Colaboratoryとは、無償のJupyterノートブック環境。教育や研究機関の機械学習の普及のためのGoogleの研究プロジェクトです。PythonやNumpyといった機械学習で要する大方の環境がすでに構築されており、コードの記述・実行、解析の保存・共有などが可能です。

0グッド

0クリップ

投稿2019/07/19 06:52

このサイト通りに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'

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

最新バージョンではこちらのように書き方が変更されたみたいです。

その書き方にしてみるか、!pip install tensorflow==1.13.1でバージョンを下げてみるのはどうでしょうか。

投稿2019/07/19 09:25

fiveHundred

総合スコア9774

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

trafalbad

2019/07/19 23:29

解決しました、ありがとうございます
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問