def print_ced_compare_methods( method_errors,method_names,test_data,log_path='', save_log=True, norm='interocular distance'): plt.yticks(np.linspace(0, 1, 11)) plot_cumulative_error_distribution( [list(err) for err in list(method_errors)], legend_entries=list(method_names), marker_style=['s'], marker_size=7, x_label='Normalised Point-to-Point Error\n('+norm+')\n*'+test_data+' set*' ) if save_log: plt.savefig(os.path.join(log_path,'nme_ced_on_'+test_data+'_set.png'), bbox_inches='tight') print ('ced plot path: ' + os.path.join(log_path,'nme_ced_on_'+test_data+'_set.png')) plt.close()
def plot_ced_3dMDLab(errors): errs = [[ error_vtx for error_mesh in errors[key] for error_vtx in error_mesh ] for key in errors.keys()] legs = [method for method in errors.keys()] tab = statistics_table(errs, legs, 0.105, 0.01, precision=4, sort_by='auc') r = plot_cumulative_error_distribution( errs, legend_font_size=20, line_width=5, marker_size=10, axes_font_size=20, error_range=[0, 0.105, 0.01], marker_edge_width=4, y_label='Vertexes proportion', x_label='Normalized dense vertex error', title='', legend_entries=legs, axes_y_ticks=list(np.arange(0., 1.05, 0.1)), figure_size=(7, 5)) plt.gca().set_axisbelow(True) plt.gca().yaxis.grid(color='gray', linestyle='dashed') return tab, r
def plot_ced(errors, method_names=['MDM']): from menpofit.visualize import plot_cumulative_error_distribution # plot the ced and store it at the root. fig = plt.figure() fig.add_subplot(111) plot_cumulative_error_distribution(errors, legend_entries=method_names, error_range=(0, 0.09, 0.005)) # shift the main graph to make room for the legend ax = plt.gca() box = ax.get_position() ax.set_position([box.x0, box.y0, box.width * 0.9, box.height]) fig.canvas.draw() data = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='') data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,)) plt.clf() return data
def plot_ced(errors, method_names=['MDM']): from matplotlib import pyplot as plt from menpofit.visualize import plot_cumulative_error_distribution import numpy as np # plot the ced and store it at the root. fig = plt.figure() fig.add_subplot(111) plot_cumulative_error_distribution(errors, legend_entries=method_names, error_range=(0, 0.09, 0.005)) # shift the main graph to make room for the legend ax = plt.gca() box = ax.get_position() ax.set_position([box.x0, box.y0, box.width * 0.9, box.height]) fig.canvas.draw() data = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='') data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,)) plt.clf() return data
def print_nme_statistics( errors, model_path, network_type, test_data, max_error=0.08, log_path='', save_log=True, plot_ced=True, norm='interocular distance'): auc, failures = AUC(errors, max_error=max_error) print ("\n****** NME statistics for " + network_type + " Network ******\n") print ("* model path: " + model_path) print ("* dataset: " + test_data + ' set') print ("\n* Normalized mean error (percentage of "+norm+"): %.2f" % (100 * np.mean(errors))) print ("\n* AUC @ %.2f: %.2f" % (max_error, 100 * auc)) print ("\n* failure rate @ %.2f: %.2f" % (max_error, 100 * failures) + '%') if plot_ced: plt.figure() plt.yticks(np.linspace(0, 1, 11)) plot_cumulative_error_distribution( list(errors), legend_entries=[network_type], marker_style=['s'], marker_size=7, x_label='Normalised Point-to-Point Error\n('+norm+')\n*' + test_data + ' set*', ) if save_log: with open(os.path.join(log_path, network_type.lower() + "_nme_statistics_on_" + test_data + "_set.txt"), "wb") as f: f.write(b"************************************************") f.write(("\n****** NME statistics for " + str(network_type) + " Network ******\n").encode()) f.write(b"************************************************") f.write(("\n\n* model path: " + str(model_path)).encode()) f.write(("\n\n* dataset: " + str(test_data) + ' set').encode()) f.write(b"\n\n* Normalized mean error (percentage of "+norm+"): %.2f" % (100 * np.mean(errors))) f.write(b"\n\n* AUC @ %.2f: %.2f" % (max_error, 100 * auc)) f.write(("\n\n* failure rate @ %.2f: %.2f" % (max_error, 100 * failures) + '%').encode()) if plot_ced: plt.savefig(os.path.join(log_path, network_type.lower() + '_nme_ced_on_' + test_data + '_set.png'), bbox_inches='tight') plt.close() print ('\nlog path: ' + log_path)