def get_val_mIoU(): print("Start to get mIoU on val set...") #prediction_files = glob.glob(os.path.join(FLAGS.saved_prediction_val_gray, '*.png')) #f = open(VAL_LIST) #lines = f.readlines() annotation_files = glob.glob( os.path.join(CITYSCAPE_ANNO_DIR, 'val/*/*_gtFine_labelTrainIds.png')) prediction_files = [ os.path.join(FLAGS.saved_prediction_val_gray, os.path.join(os.path.basename(filename))) for filename in annotation_files ] prediction_files = [ filename.replace('_gtFine_labelTrainIds.png', '_leftImg8bit.png') for filename in prediction_files ] for i, annotation_file in enumerate(annotation_files): annotation_data = cv2.imread(annotation_file, cv2.IMREAD_GRAYSCALE) annotation_data = annotation_data.reshape(-1) if i == 0: annotations_data = annotation_data else: annotations_data = np.concatenate( (annotations_data, annotation_data)) print(annotations_data.shape) for i, prediction_file in enumerate(prediction_files): prediction_data = cv2.imread(prediction_file, cv2.IMREAD_GRAYSCALE) prediction_data = prediction_data.reshape(-1) if i == 0: predictions_data = prediction_data else: predictions_data = np.concatenate( (predictions_data, prediction_data)) print(predictions_data.shape) mIoU, IoU = Utils.cal_batch_mIoU(predictions_data, annotations_data, FLAGS.classes) print(mIoU) print(IoU)
def get_val_mIoU(): print("Start to get mIoU on val set...") f = open(VAL_LIST) lines = f.readlines() annotation_files = [ os.path.join(ANNOTATION_PATH, line.strip() + '.png') for line in lines ] prediction_files = [ os.path.join(saved_prediction_val_gray, line.strip() + '.png') for line in lines ] for i, annotation_file in enumerate(annotation_files): annotation_data = cv2.imread(annotation_file, cv2.IMREAD_GRAYSCALE) annotation_data = annotation_data.reshape(-1) if i == 0: annotations_data = annotation_data else: annotations_data = np.concatenate( (annotations_data, annotation_data)) print(annotations_data.shape) for i, prediction_file in enumerate(prediction_files): prediction_data = cv2.imread(prediction_file, cv2.IMREAD_GRAYSCALE) prediction_data = prediction_data.reshape(-1) if i == 0: predictions_data = prediction_data else: predictions_data = np.concatenate( (predictions_data, prediction_data)) print(predictions_data.shape) mIoU, IoU = Utils.cal_batch_mIoU(predictions_data, annotations_data, CLASSES) print(mIoU) print(IoU)
keep_prob: 1.0 }) learning_rate = sess.run(lr) if i % FLAGS.print_steps == 0 and FLAGS.dataset == 'train': print(datetime.datetime.now().strftime("%Y.%m.%d-%H:%M:%S"), " | Step: %d | Train loss all: %f" % (i, train_loss_val_all)) if i % FLAGS.print_steps == 0 and FLAGS.dataset == 'trainval': print(datetime.datetime.now().strftime("%Y.%m.%d-%H:%M:%S"), " | Step: %d | Train loss all: %f" % (i, train_loss_val_all)) if i % FLAGS.iou_steps == 0 and FLAGS.dataset == 'train': train_mIoU_val, train_IoU_val = Utils.cal_batch_mIoU( pred_train, b_anno, FLAGS.classes) test_mIoU_val, test_IoU_val = Utils.cal_batch_mIoU( pred_test, b_anno_test, FLAGS.classes) sess.run(tf.assign(train_mIoU, train_mIoU_val)) sess.run(tf.assign(test_mIoU, test_mIoU_val)) print('------------------------------') print( "Step: %d | Lr: %f | Train loss all: %f | Train loss: %f | Train mIoU: %f | Test loss all: %f | Test loss: %f | Test mIoU: %f" % (i, learning_rate, train_loss_val_all, train_loss_val, train_mIoU_val, test_loss_val_all, test_loss_val, test_mIoU_val)) print('------------------------------') print(train_IoU_val)
mIoU_val_all = [] for i in range(NUMS): b_image, b_anno, b_filename = sess.run( [image_batch, anno_batch, filename]) b_image_0, b_anno = input_data.aug_std(b_image, b_anno, type='test') pred = sess.run(prediction, feed_dict={ x: b_image_0, y: b_anno, keep_prob: 1.0 }) mIoU_val, IoU_val = Utils.cal_batch_mIoU(pred, b_anno, CLASSES) #mIoU_val = sess.run(mIoU) #print(mIoU_val) mIoU_val_all.append(mIoU_val) basename = b_filename[0].split('.')[0] ''' # save raw image, annotation, and prediction pred = pred.astype(np.uint8) b_anno = b_anno.astype(np.uint8) pred_color = color_gray(pred[0, :, :]) b_anno_color = color_gray(b_anno[0, :, :]) img = Image.fromarray(b_image[0]) anno = Image.fromarray(b_anno_color)
test_summary = sess.run(merged, feed_dict={x: image_batch_val, y: anno_batch_val}) test_summary_writer.add_summary(test_summary, i) if i % PRINT_STEPS == 0: train_loss_val_all = sess.run(loss_all, feed_dict={x: image_batch, y: anno_batch}) print(datetime.datetime.now().strftime("%Y.%m.%d-%H:%M:%S"), " | Step: %d, | Train loss all: %f" % (i, train_loss_val_all)) if i % SAVE_SUMMARY_STEPS == 0: learning_rate = sess.run(lr) pred_train, train_loss_val_all, train_loss_val = sess.run([predictions, loss_all, loss], feed_dict={x: image_batch, y: anno_batch}) pred_test, test_loss_val_all, test_loss_val = sess.run([predictions, loss_all, loss], feed_dict={x: image_batch_val, y: anno_batch_val}) train_mIoU_val, train_IoU_val = Utils.cal_batch_mIoU(pred_train, anno_batch, CLASSES) test_mIoU_val, test_IoU_val = Utils.cal_batch_mIoU(pred_test, anno_batch_val, CLASSES) sess.run(tf.assign(train_mIoU, train_mIoU_val)) sess.run(tf.assign(test_mIoU, test_mIoU_val)) print('------------------------------') print(datetime.datetime.now().strftime("%Y.%m.%d-%H:%M:%S"), " | Step: %d, | Lr: %f, | train loss all: %f, | train loss: %f, | train mIoU: %f, | test loss all: %f, | test loss: %f, | test mIoU: %f" % ( i, learning_rate, train_loss_val_all, train_loss_val, train_mIoU_val, test_loss_val_all, test_loss_val, test_mIoU_val)) print('------------------------------') print(train_IoU_val) print(test_IoU_val) print('------------------------------') #prediction = tf.argmax(logits, axis=-1, name='predictions') if i % SAVE_CHECKPOINT_STEPS == 0: if not os.path.exists('images'):
x: b_image_test, y: b_anno_test, keep_prob: 1.0 }) learning_rate = sess.run(lr) if i % 10 == 0: print( "train step: %d, learning rate: %f, train loss all: %f, train loss: %f, test loss all: %f, test loss: %f," % (i, learning_rate, train_loss_val_all, train_loss_val, test_loss_val_all, test_loss_val)) if i % 200 == 0: train_mIoU_val, train_IoU_val = Utils.cal_batch_mIoU( pred_train, b_anno, CLASSES) test_mIoU_val, test_IoU_val = Utils.cal_batch_mIoU( pred_test, b_anno_test, CLASSES) sess.run(tf.assign(train_mIoU, train_mIoU_val)) sess.run(tf.assign(test_mIoU, test_mIoU_val)) print( "train step: %d, learning rate: %f, train loss all: %f, train loss: %f, train mIoU: %f, test loss all: %f, test loss: %f, test mIoU: %f" % (i, learning_rate, train_loss_val_all, train_loss_val, train_mIoU_val, test_loss_val_all, test_loss_val, test_mIoU_val)) print(train_IoU_val) print(test_IoU_val) if i % 6000 == 0: