現在以下のTensorFlow1.xのコードをTensorFlow2.0用に書き換えを行っています。
https://github.com/ChengBinJin/V-GAN-tensorflow
その際
"TypeError: Tensors in list passed to 'inputs' of 'MergeSummary' Op have types [bool, bool, bool, bool, bool, bool, bool] that do not match expected type string."というエラーが出てしまい、解決できずにいます。
詳細は以下に示します。
ValueError: Tensor conversion requested dtype string for Tensor with dtype bool: <tf.Tensor 'auc_pr_summary/write_summary/Const:0' shape=() dtype=bool>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 48, in <module>
app.run(main)
File "/home/miura/anaconda3/lib/python3.7/site-packages/absl/app.py", line 299, in run
_run_main(main, args)
File "/home/miura/anaconda3/lib/python3.7/site-packages/absl/app.py", line 250, in _run_main
sys.exit(main(argv))
File "main.py", line 40, in main
solver = Solver(FLAGS)
File "/home/miura/200208_深層学習修正/codes/solver.py", line 31, in init
self.model = CGAN(self.sess, self.flags, self.dataset.image_size)
File "/home/miura/200208_深層学習修正/codes/model.py", line 30, in init
self._init_assign_op() # initialize assign operations
File "/home/miura/200208_深層学習修正/codes/model.py", line 116, in _init_assign_op
sensitivity_summ, specificity_summ, score_summ])
File "/home/miura/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/summary/summary.py", line 371, in merge
val = _gen_logging_ops.merge_summary(inputs=inputs, name=name)
File "/home/miura/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_logging_ops.py", line 530, in merge_summary
"MergeSummary", inputs=inputs, name=name)
File "/home/miura/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/framework/op_def_library.py", line 493, in _apply_op_helper
(prefix, dtype.name))
TypeError: Tensors in list passed to 'inputs' of 'MergeSummary' Op have types [bool, bool, bool, bool, bool, bool, bool] that do not match expected type string.
以下コード(足りない部分があれば、お伝えいだだけると追記いたします。)
Python
1#main.py 2import os 3import tensorflow as tf 4from solver import Solver 5from absl import app 6from absl import flags 7 8FLAGS = flags.FLAGS 9 10''' 11ここにコマンドライン引数をflags.DEFINE_integer, flags.DEFINE_string等で定義するが略 12''' 13 14def main(_): 15 os.environ['CUDA_VISIBLE_DEVICES'] = FLAGS.gpu_index 16 17 solver = Solver(FLAGS) 18 if FLAGS.is_test: 19 solver.test() 20 if not FLAGS.is_test: 21 solver.train() 22 23 24if __name__ == '__main__': 25 app.run(main) 26
Python
1#solver.py 2import os 3import time 4import collections 5import numpy as np 6import matplotlib.pyplot as plt 7import matplotlib.gridspec as gridspec 8import tensorflow as tf 9from PIL import Image 10 11from dataset import Dataset 12# noinspection PyPep8Naming 13import TensorFlow_utils as tf_utils 14import utils as utils 15from model import CGAN 16from tensorflow.compat.v1 import ConfigProto 17from tensorflow.compat.v1 import Session 18 19class Solver(object): 20 def __init__(self, flags): 21 run_config = ConfigProto() 22 run_config.gpu_options.allow_growth = True 23 self.sess = Session(config=run_config) 24 25 self.flags = flags 26 self.dataset = Dataset(self.flags.dataset, self.flags) 27 self.model = CGAN(self.sess, self.flags, self.dataset.image_size) 28 29 self.best_auc_sum = 0. 30 self._make_folders() 31 32 self.saver = tf.train.Saver() 33 self.sess.run(tf.global_variables_initializer()) 34 35 tf_utils.show_all_variables() 36''' 37以下メソッド略 38'''
Python
1import tensorflow as tf 2# noinspection PyPep8Naming 3import TensorFlow_utils as tf_utils 4import keras 5from tensorflow.compat.v1 import placeholder 6from tensorflow.compat.v1 import variable_scope 7from tensorflow.compat.v1 import layers 8from tensorflow.compat.v1 import trainable_variables 9from tensorflow.compat.v1.train import AdamOptimizer 10from tensorflow.compat.v1.summary import FileWriter 11from tensorflow.compat.v1.summary import merge_all 12 13class CGAN(object): 14 def __init__(self, sess, flags, image_size): 15 tf.compat.v1.disable_eager_execution() 16 self.sess = sess 17 self.flags = flags 18 self.image_size = image_size 19 20 self.alpha_recip = 1. / self.flags.ratio_gan2seg if self.flags.ratio_gan2seg > 0 else 0 21 self._gen_train_ops, self._dis_train_ops = [], [] 22 self.gen_c, self.dis_c = 32, 32 23 24 self._build_net() 25 self._init_assign_op() # initialize assign operations 26 27 print('Initialized CGAN SUCCESS!\n') 28 29def _init_assign_op(self): 30 self.best_auc_sum_placeholder = placeholder(tf.float32, name='best_auc_sum_placeholder') 31 self.auc_pr_placeholder = placeholder(tf.float32, name='auc_pr_placeholder') 32 self.auc_roc_placeholder = placeholder(tf.float32, name='auc_roc_placeholder') 33 self.dice_coeff_placeholder = placeholder(tf.float32, name='dice_coeff_placeholder') 34 self.acc_placeholder = placeholder(tf.float32, name='acc_placeholder') 35 self.sensitivity_placeholder = placeholder(tf.float32, name='sensitivity_placeholder') 36 self.specificity_placeholder = placeholder(tf.float32, name='specificity_placeholder') 37 self.score_placeholder = placeholder(tf.float32, name='score_placeholder') 38 39 self.best_auc_sum = tf.Variable(0., trainable=False, dtype=tf.float32, name='best_auc_sum') 40 auc_pr = tf.Variable(0., trainable=False, dtype=tf.float32, name='auc_pr') 41 auc_roc = tf.Variable(0., trainable=False, dtype=tf.float32, name='auc_roc') 42 dice_coeff = tf.Variable(0., trainable=False, dtype=tf.float32, name='dice_coeff') 43 acc = tf.Variable(0., trainable=False, dtype=tf.float32, name='acc') 44 sensitivity = tf.Variable(0., trainable=False, dtype=tf.float32, name='sensitivity') 45 specificity = tf.Variable(0., trainable=False, dtype=tf.float32, name='specificity') 46 score = tf.Variable(0., trainable=False, dtype=tf.float32, name='score') 47 48 self.best_auc_sum_assign_op = self.best_auc_sum.assign(self.best_auc_sum_placeholder) 49 auc_pr_assign_op = auc_pr.assign(self.auc_pr_placeholder) 50 auc_roc_assign_op = auc_roc.assign(self.auc_roc_placeholder) 51 dice_coeff_assign_op = dice_coeff.assign(self.dice_coeff_placeholder) 52 acc_assign_op = acc.assign(self.acc_placeholder) 53 sensitivity_assign_op = sensitivity.assign(self.sensitivity_placeholder) 54 specificity_assign_op = specificity.assign(self.specificity_placeholder) 55 score_assign_op = score.assign(self.score_placeholder) 56 57 self.measure_assign_op = tf.group(auc_pr_assign_op, auc_roc_assign_op, dice_coeff_assign_op, 58 acc_assign_op, sensitivity_assign_op, specificity_assign_op, 59 score_assign_op) 60 61 # for tensorboard 62 if not self.flags.is_test: 63 self.writer = FileWriter("{}/logs/{}_{}_{}".format( 64 self.flags.dataset, self.flags.discriminator, self.flags.train_interval, self.flags.batch_size)) 65 66 auc_pr_summ = tf.summary.scalar("auc_pr_summary", auc_pr) 67 auc_roc_summ = tf.summary.scalar("auc_roc_summary", auc_roc) 68 dice_coeff_summ = tf.summary.scalar("dice_coeff_summary", dice_coeff) 69 acc_summ = tf.summary.scalar("acc_summary", acc) 70 sensitivity_summ = tf.summary.scalar("sensitivity_summary", sensitivity) 71 specificity_summ = tf.summary.scalar("specificity_summary", specificity) 72 score_summ = tf.summary.scalar("score_summary", score) 73 74 self.measure_summary = merge([auc_pr_summ, auc_roc_summ, dice_coeff_summ, acc_summ, sensitivity_summ, specificity_summ, score_summ]) 75''' 76以下メソッド略 77''' 78 79
どうぞよろしくお願いいたします。
あなたの回答
tips
プレビュー