def Construct_Accuracy_op(self):
with tf.name_scope('accuracy'):
if self.model_dict['Model_Type'] is 'Classification' :
correct_prediction = tf.equal(tf.argmax(self.model_dict['Output'], 1), tf.argmax(self.model_dict['Output_ph'], 1))
false_images = tf.boolean_mask(self.model_dict['Reshaped_input'], tf.logical_not(correct_prediction))
tf.summary.image(name='False images', tensor=false_images)
self.accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
tf.summary.scalar('accuracy', self.accuracy)
self.accuracy_op = True
elif self.model_dict['Model_Type'] is 'Segmentation' :
probs = tf.reshape((tf.sigmoid(self.model_dict['Output'])), shape=[ self.kwargs['Batch_size'], -1])
lab = tf.reshape(self.model_dict['Output_ph'], shape=[self.kwargs['Batch_size'], -1])
probs = tf.ceil(probs - 0.5 + 1e-10)
intersection = tf.reduce_sum(probs * lab, axis=1)
union = tf.reduce_sum(probs, 1) + tf.reduce_sum(lab, 1)
tf.summary.image(name='Input images',tensor = self.model_dict['Reshaped_input'])
tf.summary.image(name='Mask',tensor = tf.reshape(self.model_dict['Output_ph'], [-1, self.kwargs['Image_width'], self.kwargs['Image_height'], 1]))
tf.summary.image(name='Weight',tensor = tf.reshape(self.model_dict['Weight_ph'], [-1, self.kwargs['Image_width'], self.kwargs['Image_height'], 1]))
tf.summary.image(name='Output',tensor = (tf.sigmoid(self.model_dict['Output'])))
self.accuracy = tf.reduce_mean(2 * intersection / (union))
tf.summary.scalar('accuracy', self.accuracy)
self.accuracy_op = True
elif self.model_dict['Model_Type'] is 'Sequence' :
correct_prediction = tf.equal(tf.argmax(self.model_dict['Output'], 1), tf.reshape(tf.cast(tf.reshape(self.model_dict['Output_ph'], shape=[-1]), tf.int64), [-1]))
pre_acc = tf.to_float(correct_prediction) * tf.to_float(tf.reshape(self.model_dict['Mask'], [-1]))
pre_acc = tf.reduce_sum(pre_acc)
self.accuracy = tf.div(pre_acc, tf.maximum(1.0,tf.reduce_sum(tf.to_float(tf.reshape(self.model_dict['Mask'], [-1])))))
tf.reduce_sum(tf.to_float(tf.reshape(self.model_dict['Mask'], [-1])))
self.accuracy_op = True
tf.summary.scalar('accuracy', self.accuracy)
self.out_op = tf.argmax(self.model_dict['Output'], 1)
#tf.cond(self.accuracy > 0.92, lambda: tf.summary.image(name='False images', tensor=false_images), lambda: tf.summary.tensor_summary(name='correct_predictions', tensor=correct_prediction))
评论列表
文章目录