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)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。