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

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

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

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

6259閲覧

pythonコードのエラーの原因を教えて下さい

trafalbad

総合スコア303

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

1グッド

1クリップ

投稿2017/03/09 06:41

編集2017/03/09 06:42

Tensorflowで以下のコードを実行しましたが、下のようなエラーが出ました。原因を教えて下さい。

scalar_summaryはtensorflowで使われいるはずなのですがなぜこのようなエラーが出てしまうのでしょうか?

import tensorflow as tf import numpy as np import matplotlib.pyplot as plt from tensorflow.examples.tutorials.mnist import input_data #モジュールをインポートして、乱数のシードを設定 np.random.seed(20160612) tf.set_random_seed(20160612) mnist = input_data.read_data_sets("/tmp/data/", one_hot=True) #MNISTのデータセットを用意 class SingleLayerNetwork: def __init__(self, num_units): with tf.Graph().as_default(): self.prepare_model(num_units) self.prepare_session() def prepare_model(self, num_units): with tf.name_scope('input'): x = tf.placeholder(tf.float32, [None, 784], name='input') with tf.name_scope('hidden'): w1 = tf.Variable(tf.truncated_normal([784, num_units]), name='weights') b1 = tf.Variable(tf.zeros([num_units]), name='biases') hidden1 = tf.nn.relu(tf.matmul(x, w1) + b1, name='hidden1') with tf.name_scope('output'): w0 = tf.Variable(tf.zeros([num_units, 10]), name='weights') b0 = tf.Variable(tf.zeros([10]), name='biases') p = tf.nn.softmax(tf.matmul(hidden1, w0) + b0, name='softmax') with tf.name_scope('optimizer'): t = tf.placeholder(tf.float32, [None, 10], name='labels') loss = -tf.reduce_sum(t * tf.log(p), name='loss') train_step = tf.train.AdamOptimizer().minimize(loss) with tf.name_scope('evaluator'): correct_prediction = tf.equal(tf.argmax(p, 1), tf.argmax(t, 1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32), name='accuracy') tf.scalar_summary("loss", loss) tf.scalar_summary("accuracy", accuracy) tf.histogram_summary("weights_hidden", w1) tf.histogram_summary("biases_hidden", b1) tf.histogram_summary("weights_output", w0) tf.histogram_summary("biases_output", b0) self.x, self.t, self.p = x, t, p self.train_step = train_step self.loss = loss self.accuracy = accuracy def prepare_session(self): sess = tf.InteractiveSession() sess.run(tf.initialize_all_variables()) summary = tf.merge_all_summaries() writer = tf.train.SummaryWriter("/tmp/mnist_sl_logs", sess.graph) self.sess = sess self.summary = summary self.writer = writer #単層ニューラルネットワークを表現するクラスの定義 !rm -rf /tmp/mnist_sl_logs #ensorBoard用のデータ出力ディレクトリーを削除して初期化 nn = SingleLayerNetwork(1024) i = 0 for _ in range(2000): i += 1 batch_xs, batch_ts = mnist.train.next_batch(100) nn.sess.run(nn.train_step, feed_dict={nn.x: batch_xs, nn.t: batch_ts}) if i % 100 == 0: summary, loss_val, acc_val = nn.sess.run( [nn.summary, nn.loss, nn.accuracy], feed_dict={nn.x:mnist.test.images, nn.t: mnist.test.labels}) print ('Step: %d, Loss: %f, Accuracy: %f' % (i, loss_val, acc_val)) nn.writer.add_summary(summary, i) #パラメーターの最適化を2000回繰り返します。

【エラー】
AttributeError Traceback (most recent call last)
<ipython-input-22-c77c4e4a5ccf> in <module>()
----> 1 nn = SingleLayerNetwork(1024)
2
3 i = 0
4 for _ in range(2000):
5 i += 1

<ipython-input-19-1d1a82266501> in init(self, num_units)
2 def init(self, num_units):
3 with tf.Graph().as_default():
----> 4 self.prepare_model(num_units)
5 self.prepare_session()
6

<ipython-input-19-1d1a82266501> in prepare_model(self, num_units)
30 tf.float32), name='accuracy')
31
---> 32 tf.scalar_summary("loss", loss)
33 tf.scalar_summary("accuracy", accuracy)
34 tf.histogram_summary("weights_hidden", w1)

AttributeError: module 'tensorflow' has no attribute 'scalar_summary'

nagaetty👍を押しています

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

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

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

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

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

guest

回答1

0

ベストアンサー

Tensorflow: 'module' object has no attribute 'scalar_summary'

The tf.scalar_summary() function was moved in the master branch, after the 0.12 release. You can now find it as tf.summary.scalar().

質問者の動作バージョン不明ですが、0.12からはtf.summary.scalar()を使うように動作が変わったようです。

投稿2017/03/09 06:47

can110

総合スコア38262

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

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

trafalbad

2017/03/09 07:54

ありがとうございます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問