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

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

新規登録して質問してみよう
ただいま回答率
85.49%
機械学習

機械学習は、データからパターンを自動的に発見し、そこから知能的な判断を下すためのコンピューターアルゴリズムを指します。人工知能における課題のひとつです。

Python

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

Q&A

解決済

1回答

4561閲覧

tensorflowのエラーコマンドの解決方法について

trafalbad

総合スコア303

機械学習

機械学習は、データからパターンを自動的に発見し、そこから知能的な判断を下すためのコンピューターアルゴリズムを指します。人工知能における課題のひとつです。

Python

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

0グッド

0クリップ

投稿2017/06/08 07:48

DCGANで#Discriminatorを定義して、学習のためのコードを定義しました。そしたら下記エラーが出てしまいました。(より詳細なエラーは「全体コード」に記載しています)

ValueError: Variable d_hidden1_weight already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally defined at:

内容によるとVariable d_hidden1_weightはすでに存在しているため、d_output_from_given_data = trainable_inference(d_given_data_placeholder)

の格納は行えないということなのでしょうか?解決策がわからないためためご教授お願いします。

全体コード

import tensorflow as tf import numpy #Discriminator INPUT_SIZE = 3072 HIDDEN_UNIT_SIZE = 64 TRAIN_DATA_SIZE = 10000 def d_inference(input, hidden1_weight, hidden1_bias, output_weight, output_bias): hidden1_output = tf.nn.relu(tf.matmul(input, hidden1_weight) + hidden1_bias) output = tf.sigmoid(tf.matmul(hidden1_output, output_weight) + output_bias) return output def trainable_inference(input): hidden1_weight = tf.get_variable("d_hidden1_weight",[INPUT_SIZE, HIDDEN_UNIT_SIZE], initializer = tf.random_normal_initializer(0, 0.1)) hidden1_bias = tf.get_variable("d_hidden1_bias",[HIDDEN_UNIT_SIZE], initializer = tf.constant_initializer(0.1)) output_weight = tf.get_variable("d_output_weight",[HIDDEN_UNIT_SIZE, 1],initializer = tf.random_normal_initializer(0, 0.1)) output_bias = tf.get_variable("d_output_bias",[1],initializer = tf.constant_initializer(0.1)) hidden1_output = tf.nn.relu(tf.matmul(input, hidden1_weight) + hidden1_bias) output = tf.sigmoid(tf.matmul(hidden1_output, output_weight) + output_bias) return output def get_train_params(): hidden1_weight = tf.get_variable("get_hidden1_weight", [INPUT_SIZE, HIDDEN_UNIT_SIZE]) hidden1_bias = tf.get_variable("get_hidden1_bias", [HIDDEN_UNIT_SIZE]) output_weight = tf.get_variable("get_output_weight", [HIDDEN_UNIT_SIZE, 1]) output_bias = tf.get_variable("get_output_bias", [1]) return [hidden1_weight, hidden1_bias, output_weight, output_bias] def loss(output_from_given_data, output_from_noise): loss_1 = tf.reduce_sum(tf.log(output_from_given_data)) loss_2 = tf.reduce_sum(tf.log(1 - output_from_noise)) return [loss_1, loss_2] def training(loss, learning_rate): train_step = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss) return train_step # placeholders d_given_data_placeholder = tf.placeholder("float", [None, INPUT_SIZE], name="g_given_data_placeholder") # inference output d_output_from_given_data = trainable_inference(d_given_data_placeholder) #エラーメッセージ --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-13-253495f74891> in <module>() 13 14 ---> 15 d_output_from_given_data = trainable_inference(d_given_data_placeholder) 16 <ipython-input-10-5d4f0de9f4e8> in trainable_inference(input) 17 18 def trainable_inference(input): ---> 19 hidden1_weight = tf.get_variable("d_hidden1_weight",[INPUT_SIZE, HIDDEN_UNIT_SIZE], initializer = tf.random_normal_initializer(0, 0.1)) 20 hidden1_bias = tf.get_variable("d_hidden1_bias",[HIDDEN_UNIT_SIZE], initializer = tf.constant_initializer(0.1)) 21 output_weight = tf.get_variable("d_output_weight",[HIDDEN_UNIT_SIZE, 1],initializer = tf.random_normal_initializer(0, 0.1)) /Users/hagiharatatsuya/anaconda/envs/TensorFlow/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py in get_variable(name, shape, dtype, initializer, regularizer, trainable, collections, caching_device, partitioner, validate_shape, use_resource, custom_getter) 1047 collections=collections, caching_device=caching_device, 1048 partitioner=partitioner, validate_shape=validate_shape, -> 1049 use_resource=use_resource, custom_getter=custom_getter) 1050 get_variable_or_local_docstring = ( 1051 """%s /Users/hagiharatatsuya/anaconda/envs/TensorFlow/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py in get_variable(self, var_store, name, shape, dtype, initializer, regularizer, trainable, collections, caching_device, partitioner, validate_shape, use_resource, custom_getter) 946 collections=collections, caching_device=caching_device, 947 partitioner=partitioner, validate_shape=validate_shape, --> 948 use_resource=use_resource, custom_getter=custom_getter) 949 950 def _get_partitioned_variable(self, /Users/hagiharatatsuya/anaconda/envs/TensorFlow/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py in get_variable(self, name, shape, dtype, initializer, regularizer, reuse, trainable, collections, caching_device, partitioner, validate_shape, use_resource, custom_getter) 354 reuse=reuse, trainable=trainable, collections=collections, 355 caching_device=caching_device, partitioner=partitioner, --> 356 validate_shape=validate_shape, use_resource=use_resource) 357 358 def _get_partitioned_variable( /Users/hagiharatatsuya/anaconda/envs/TensorFlow/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py in _true_getter(name, shape, dtype, initializer, regularizer, reuse, trainable, collections, caching_device, partitioner, validate_shape, use_resource) 339 trainable=trainable, collections=collections, 340 caching_device=caching_device, validate_shape=validate_shape, --> 341 use_resource=use_resource) 342 343 if custom_getter is not None: /Users/hagiharatatsuya/anaconda/envs/TensorFlow/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py in _get_single_variable(self, name, shape, dtype, initializer, regularizer, partition_info, reuse, trainable, collections, caching_device, validate_shape, use_resource) 651 " Did you mean to set reuse=True in VarScope? " 652 "Originally defined at:\n\n%s" % ( --> 653 name, "".join(traceback.format_list(tb)))) 654 found_var = self._vars[name] 655 if not shape.is_compatible_with(found_var.get_shape()): ValueError: Variable d_hidden1_weight already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally defined at: File "<ipython-input-3-5d4f0de9f4e8>", line 19, in trainable_inference hidden1_weight = tf.get_variable("d_hidden1_weight",[INPUT_SIZE, HIDDEN_UNIT_SIZE], initializer = tf.random_normal_initializer(0, 0.1)) File "<ipython-input-5-a8b7f043c063>", line 23, in <module> d_output_from_given_data = trainable_inference(d_given_data_placeholder) File "/Users/hagiharatatsuya/anaconda/envs/TensorFlow/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2881, in run_code exec(code_obj, self.user_global_ns, self.user_ns)

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

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

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

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

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

guest

回答1

0

ベストアンサー

解決策がわからないためためご教授お願いします。

目的によります。
すでに存在する変数(値)を使いたい場合はreuse=True
そうでない、すなわち別の変数として使いたい場合は別の名前をつけるようにします。

目的別に変数の使い方がまとめられているページがありました。参考まで。
TensorFlowの計算グラフ内の変数tf.Variableの使い方

投稿2017/06/08 09:20

編集2017/06/08 09:43
can110

総合スコア38256

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.49%

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

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

質問する

関連した質問