global_step=global_step) print('save a checkpoint at ' + opt.checkpoint_path + 'model-' + str(it)) print('start testing {} samples...'.format(test_samples)) for ti in range(test_samples): x_batch, y_batch = next(test_generator) # tensorflow wants a different tensor order feed_dict = {img: x_batch, label: y_batch} loss, pred_logits = sess.run([log_loss, pred], feed_dict=feed_dict) pred_map_batch = np.argmax(pred_logits, axis=3) # import pdb; pdb.set_trace() for pred_map, y in zip(pred_map_batch, y_batch): mean_iou, pixel_acc, dice = vis.add_sample( pred_map, y_batch[0]) vis.compute_scores(suffix=it) x_batch, y_batch = next(train_generator) # w_map = define_map(y_batch[0]) # exclude whole-backgroud images feed_dict = { img: x_batch, label: y_batch # weight_map: w_map } _, loss, summary, lr, pred_logits = sess.run( [train_step, log_loss, summary_merged, learning_rate, pred], feed_dict=feed_dict) global_step.assign(it).eval() train_writer.add_summary(summary, it)
tf.train.latest_checkpoint(opt.load_from_checkpoint)) print('--> load from checkpoint ' + opt.load_from_checkpoint) except Exception as ex: print('Unable to load checkpoint ...', ex) sys.exit(0) dice_score = 0 for it in range(0, test_samples): x_batch, y_batch = next(test_generator) # tensorflow wants a different tensor order feed_dict = {img: x_batch, label: y_batch} loss, pred_logits = sess.run([cross_entropy_loss, pred], feed_dict=feed_dict) pred_map = np.argmax(pred_logits[0], axis=2) score = vis.add_sample(pred_map, y_batch[0]) im, gt = deprocess(x_batch[0], dataset_mean, dataset_std, y_batch[0]) # im = Image.fromarray(im) # im.save(os.path.join(opt.load_from_checkpoint, '{0:}.png'.format(it))) # gt = Image.fromarray(gt, 'L') # gt.save(os.path.join(opt.load_from_checkpoint, '{0:}_{1:.3f}.png'.format(it, score))) vis.save_seg(pred_map, name='{0:}_{1:.3f}.png'.format(it, score), im=im, gt=gt) print('[iter %f]: loss=%f, meanIU=%f' % (it, loss, score)) vis.compute_scores()