def main(): parser = \ argparse.ArgumentParser( prog='parser', formatter_class=argparse.RawDescriptionHelpFormatter, description=textwrap.dedent(''' ************************************************************** Result Evaluation ----------------------- The path to Result and Reference Pictures is user-defined path. ************************************************************** ''') ) parser.add_argument('--result_image_path', type=str, help='the path to the result images') parser.add_argument('--ref_image_path', type=str, help='the path to the davis reference path') args = parser.parse_args() result_image_path = args.result_image_path if not result_image_path: raise Exception("No result image path is given neither in " "command line nor environment arguements") ref_image_path = args.ref_image_path if not ref_image_path: raise Exception("No reference images path is given neither in " "command line nor environment arguements") result_imgs = [] ref_imgs = [] for a, b, result_files in os.walk(result_image_path): result_imgs = result_files for a, b, ref_files in os.walk(ref_image_path): ref_imgs = ref_files # if len(result_imgs) != len(ref_imgs): # raise Exception("The number of image in result and ref is not match. Cannot evaluate.") print("+", "-".center(85, '-'), "+") print("|", "pixel_accuracy".center(20), "mean_IU".center(20), "mean_accuracy".center(20), "frequency_weighted_IU".center(20), "|".rjust(2)) result_image_filenames = os.listdir(result_image_path) ref_image_filenames = os.listdir(ref_image_path) image_converter = ImageConverter() each_pixel_accuracy = [] each_mean_IU = [] each_mean_accuracy = [] each_frequency_weighted_IU = [] for i in range(len(result_imgs)): print("filename:", result_image_filenames[i]) result_imgs[i] = image_converter.image_to_array(os.path.join(result_image_path, result_image_filenames[i])) ref_imgs[i] = image_converter.image_to_array(os.path.join(ref_image_path, ref_image_filenames[i])) i_pixel_accuracy = pixel_accuracy(result_imgs[i], ref_imgs[i]) //i_mean_IU = mean_IU(result_imgs[i], ref_imgs[i]) i_mean_IU = db_eval_iou(ref_imgs[i], result_imgs[i]) i_mean_accuracy = mean_accuracy(result_imgs[i], ref_imgs[i]) i_frequency_weighted_IU = frequency_weighted_IU(result_imgs[i], ref_imgs[i]) each_pixel_accuracy.append(i_pixel_accuracy) each_mean_IU.append(i_mean_IU) each_mean_accuracy.append(i_mean_accuracy) each_frequency_weighted_IU.append(i_frequency_weighted_IU) print("|", str(i_pixel_accuracy).center(20), str(i_mean_IU).center(20), str(i_mean_accuracy).center(20), str(i_frequency_weighted_IU).center(20), "|".rjust(2)) print("| mean value:", str(np.mean(each_pixel_accuracy)).center(12), str(np.mean(each_mean_IU)).center(20), str(np.mean(each_mean_accuracy)).center(20), str(np.mean(each_frequency_weighted_IU)).center(20),"|".rjust(2)) print("+", '-'.center(85, '-'), "+")
def forward(self, bottom, top): label = np.squeeze(bottom[1].data) prediction = np.squeeze(np.argmax(bottom[0].data, axis=1)) top[0].data[...] = se.mean_IU(prediction,label)
Dice_pool = [] for i in range(0, Y_true_all.shape[0]): # Define IoU metric y_true = Y_true_all[i, :, :, :1] y_true = np.squeeze(y_true) y_true = resize(y_true, (512, 512), mode='constant', preserve_range=True) thresh = threshold_otsu(y_true) y_true = y_true > thresh # y_true = y_true / 255 y_pred = Y_pre_all[i, :, :, :1] y_pred = np.squeeze(y_pred) print y_true.shape, y_pred.shape meanIOU = mean_IU(y_pred, y_true) print "meanIOU:" print meanIOU ac = pixel_accuracy(y_pred, y_true) print 'Pixel ACC:' print ac mean_acc = mean_accuracy(y_pred, y_true) print "Mean ACC:" print mean_acc dice = dice_coef(y_pred, y_true) print "Dice:" print dice write_data = [str(meanIOU), str(ac), str(mean_acc), str(dice)] csv_writer.writerow(write_data)
def testFourClasses1(self): segm = np.array([[1,2,3,0,0], [0,0,0,0,0]]) gt = np.array([[1,0,0,0,0], [0,0,0,0,0]]) res = es.mean_IU(segm, gt) self.assertEqual(res, np.mean([7.0/9.0, 1]))
def testFiveClasses0(self): segm = np.array([[1,2,3,4,3], [0,0,0,0,0]]) gt = np.array([[1,0,3,0,0], [0,0,0,0,0]]) res = es.mean_IU(segm, gt) self.assertEqual(res, np.mean([5.0/8.0, 1, 1.0/2.0]))
def testTwoClasses2(self): segm = np.array([[0,0,0,0,0], [0,0,0,0,0]]) gt = np.array([[1,0,0,0,0], [0,0,0,0,0]]) res = es.mean_IU(segm, gt) self.assertEqual(res, np.mean([0.9, 0]))
def testThreeClasses1(self): segm = np.array([[0,2,0,0,0], [0,0,0,0,0]]) gt = np.array([[1,0,0,0,0], [0,0,0,0,0]]) res = es.mean_IU(segm, gt) self.assertEqual(res, np.mean([8.0/10.0, 0]))
def testTwoClasses0(self): segm = np.array([[1,1,1,1,1], [1,1,1,1,1]]) gt = np.array([[0,0,0,0,0], [0,0,0,0,0]]) res = es.mean_IU(segm, gt) self.assertEqual(res, 0)
def testOneClass(self): segm = np.array([[0,0], [0,0]]) gt = np.array([[0,0], [0,0]]) res = es.mean_IU(segm, gt) self.assertEqual(res, 1.0)
(input_shape[3], input_shape[2])) input_image = input_image.transpose((2, 0, 1)) input_image = np.asarray([input_image]) gt_image = cv2.resize(gt_image, (output_shape[3], output_shape[2])) out = net.forward_all(**{net.inputs[0]: input_image}) prediction_argmax = net.blobs['deconv6_0_0'].data[0].argmax(axis=0) prediction = np.squeeze(prediction_argmax) prediction = np.resize(prediction, (3, output_shape[2], output_shape[3])) prediction = prediction.transpose(1, 2, 0).astype(np.uint8) Mean_IntersectionOverUnionAccuracy = Metrics.Mean_IntersectionOverUnion( prediction_argmax, gt_image) miou = mean_IU(prediction_argmax, gt_image) print(" {} MIoU : {} {} {}".format( count, Mean_IntersectionOverUnionAccuracy, miou, Mean_IntersectionOverUnionAccuracy - miou)) MIoU.append(Mean_IntersectionOverUnionAccuracy) prediction_rgb = np.zeros(prediction.shape, dtype=np.uint8) label_colours_bgr = label_colours[..., ::-1] cv2.LUT(prediction, label_colours_bgr, prediction_rgb) #cv2.imshow("ENet", prediction_rgb) #key = cv2.waitKey(0) count = count + 1 print("Mean MIoU for validation dataset: {}".format( sum(MIoU) / float(len(MIoU)))) mean_value = " mean : {}".format(sum(MIoU) / float(len(MIoU))) # An "interface" to matplotlib.axes.Axes.hist() method
cls_8 = pred == 8 pred[cls_3] = 1 pred[cls_2] = 2 pred[cls_4] = 2 pred[cls_5] = 2 pred[cls_6] = 2 pred[cls_7] = 2 pred[cls_8] = 2 """ print('unique label after is {}'.format(np.unique(label))) print('unique pred after is {}'.format(np.unique(pred))) pa = eval_segm.pixel_accuracy(pred, label) ma = eval_segm.mean_accuracy(pred, label) rate_precision_mean = eval_segm.mean_precision(pred, label) m_iu, iu = eval_segm.mean_IU(pred, label) fw_iu = eval_segm.frequency_weighted_IU(pred, label) pa_list.append(pa) ma_list.append(ma) list_rate_precision_mean.append(rate_precision_mean) iu_list.append(iu) m_iu_list.append(m_iu) fw_iu_list.append(fw_iu) num_true_positives += eval_segm.get_num_true_positives(pred, label) num_false_positives += eval_segm.get_num_false_positives(pred, label) counts.append(count) print(np.array(count), np.array(gt_count[_name])) acc[i] = 1 - ((np.abs(np.array(count) - np.array(gt_count[_name]))) / np.array(gt_count[_name])) # print("pixel_accuracy: " + str(pa)) # print("mean_accuracy: " + str(ma))
list_mean_acc = [] list_mean_IU = [] list_fpr = [] list_f1_score = [] list_recall = [] list_precision = [] # menampung hasil di result format.csv with open('{} result {}.csv'.format(classes, post_processing_method), 'w') as fsave: for idx in range(len(true_label_img)): pixel_acc = eval_segm.pixel_accuracy(predicted_label_img[idx], true_label_img[idx]) list_pixel_acc.append(pixel_acc) mean_acc = eval_segm.mean_accuracy(predicted_label_img[idx], true_label_img[idx]) list_mean_acc.append(mean_acc) mean_UI = eval_segm.mean_IU(predicted_label_img[idx], true_label_img[idx]) list_mean_IU.append(mean_UI) pred_segm = predicted_label_img[idx].copy() gt_segm = true_label_img[idx].copy() fpr = eval_segm.get_fpr(pred_segm, gt_segm) precision, recall, f1 = eval_segm.get_all(pred_segm, gt_segm) list_f1_score.append(f1) list_precision.append(precision) list_recall.append(recall) list_fpr.append(fpr) # ============================================================================= # filename = true_label[idx].split('\\')[-1] # filename = filename.split('.')[0] # filename = filename.replace(',', ' ') # fsave.write('{},{},{},{}'.format(filename,pixel_acc,mean_UI,mean_acc))