def _run_eval(self):
"""Run model evaluation and generate summaries."""
coord = tf.train.Coordinator(clean_stop_exception_types=(
tf.errors.CancelledError, tf.errors.OutOfRangeError))
with tf.Session(graph=self._graph) as session:
# Restores previously saved variables from latest checkpoint
self._saver.restore(session, self._latest_checkpoint)
session.run([tf.tables_initializer(), tf.local_variables_initializer()])
tf.train.start_queue_runners(coord=coord, sess=session)
train_step = session.run(self._gs)
tf.logging.info('Starting evaluation')
d = {key: [] for key in ['loss', 'accuracy', 'dice_coefficient', 'hausdorff_distance',
'average_symmetric_surface_distance']}
with coord.stop_on_exception():
while not coord.should_stop():
metric_dict = session.run(self._metric_dict)
prediction = metric_dict.pop('prediction')
ground_truth = metric_dict.pop('ground_truth')
d['loss'].append(metric_dict.pop('loss'))
d['accuracy'].append(metric_dict.pop('accuracy'))
d['dice_coefficient'].append(metric_dict.pop('dice_coefficient'))
d['hausdorff_distance'].append(hd(prediction, ground_truth))
d['average_symmetric_surface_distance'].append(assd(prediction, ground_truth))
# Save histogram, mean and std for each variable
for key, value in d.iteritems():
self.logger.log_histogram(tag=key, values=value, step=train_step, bins=15)
self.logger.log_random_variable(tag='eval_'+key, var=value, step=train_step)
tf.logging.info('Finished evaluation')
评论列表
文章目录