def _get_datapoints(self, predictions, labels): ''' Precision and recall found for different threshold values. For each value a binary output image is made. The threshold indicate that for a pixel value above threshold value is considered a road pixel. This generate different values for precision and recall and highlight the trade off between precision and recall. ''' #Results in a slack of 3 pixels. labels_with_slack = self._apply_buffer(labels, 3) tests = np.arange(0.0001 , 0.995, 0.01) datapoints = [] #ttt = 0 for threshold in tests: binary_arr = util.create_threshold_image(predictions, threshold) #for i in range(labels.shape[0]): # if np.max(labels[i]) > 0 and ttt < 10: # l = labels[i] # l2 = labels_with_slack[i] # blank_image = Image.new("L", (32, 16)) # im = aug.from_arr_to_label(l, 16) # im2 = aug.from_arr_to_label(l2, 16) # blank_image.paste(im, (0,0)) # blank_image.paste(im2, (16,0)) # blank_image.show() # ttt += 1 precision = self._get_precision(labels_with_slack, binary_arr) pred_with_slack = self._apply_buffer(binary_arr, 3) recall = self._get_recall(labels, binary_arr, pred_with_slack) datapoints.append({"precision": precision, "recall": recall, "threshold": threshold}) return datapoints
def _get_datapoints(self, predictions, labels): ''' Precision and recall found for different threshold values. For each value a binary output image is made. The threshold indicate that for a pixel value above threshold value is considered a road pixel. This generate different values for precision and recall and highlight the trade off between precision and recall. ''' #Results in a slack of 3 pixels. labels_with_slack = self._apply_buffer(labels, 3) tests = np.arange(0.0001, 0.995, 0.01) datapoints = [] #ttt = 0 for threshold in tests: binary_arr = util.create_threshold_image(predictions, threshold) #for i in range(labels.shape[0]): # if np.max(labels[i]) > 0 and ttt < 10: # l = labels[i] # l2 = labels_with_slack[i] # blank_image = Image.new("L", (32, 16)) # im = aug.from_arr_to_label(l, 16) # im2 = aug.from_arr_to_label(l2, 16) # blank_image.paste(im, (0,0)) # blank_image.paste(im2, (16,0)) # blank_image.show() # ttt += 1 precision = self._get_precision(labels_with_slack, binary_arr) pred_with_slack = self._apply_buffer(binary_arr, 3) recall = self._get_recall(labels, binary_arr, pred_with_slack) datapoints.append({ "precision": precision, "recall": recall, "threshold": threshold }) return datapoints
all_diff = [] pred_diff = [] nr_with_road = 0 nr_with_pred = 0 best_trade_off = tradeoff nr_of_examples = data.shape[0] for i in range(nr_of_examples): if (i % 1000 == 0): print("{}%".format(i / float(nr_of_examples) * 100)) data_sample = data[i] label_sample = labels[i] output = evaluate(np.array([data_sample])) output = util.create_threshold_image(output, best_trade_off) diff = np.sum(np.abs(output[0] - label_sample)) / ( dataset_params.output_dim * dataset_params.output_dim) has_road = not (np.max(label_sample) == 0) pred_has_road = not (np.max(output) == 0) if pred_has_road: nr_with_pred += 1 if not has_road: pred_diff.append(diff) if has_road: nr_with_road += 1 road_diff.append(diff) else: #print(diff)
all_diff = [] pred_diff = [] nr_with_road = 0 nr_with_pred = 0 best_trade_off = tradeoff nr_of_examples = data.shape[0] for i in range(nr_of_examples): if(i%1000 == 0): print("{}%".format(i/float(nr_of_examples) * 100)) data_sample = data[i] label_sample = labels[i] output = evaluate(np.array([data_sample])) output = util.create_threshold_image(output, best_trade_off) diff = np.sum(np.abs(output[0] - label_sample))/(dataset_params.output_dim*dataset_params.output_dim) has_road = not (np.max(label_sample) == 0) pred_has_road = not (np.max(output) == 0) if pred_has_road: nr_with_pred +=1 if not has_road: pred_diff.append(diff) if has_road: nr_with_road +=1 road_diff.append(diff) else: #print(diff) #print(np.max(output[0]))