def add_train_metrics(in_dict, result_dict): train_probs = result_dict.pop('train_probs') preds = train_probs > 0.5 if not np.any(preds): print ">>> Predicted 0 pixels." train_target = in_dict['y_full'] result_dict["train_iou"] = iou(preds, train_target)
def add_validate_metrics(in_dict, result_dict): global best_valid_iou global valid_iter valid_iter += 1 valid_out = valid_fn(valid_chunk) valid_out['window_max'] = valid_out['window_max'][0] valid_out['window_min'] = valid_out['window_min'][0] probs = valid_out.pop("valid_probs") preds = probs > 0.5 result_dict.update(valid_out) valid_target = valid_chunk['y_full'] this_iou = iou(preds, valid_target) result_dict["valid_iou"] = this_iou # Save an example image of the current best segmentation # Let's also save one as a snapshot if this_iou > best_valid_iou: best_valid_iou = this_iou store_image( valid_chunk['x_full'][0, 0], valid_chunk['y_full'][0, 0], preds[0, 0], filepath=trial.file_path('segmented_best.jpg'), window_min=valid_out['window_min'], window_max=valid_out['window_max'], ) store_image( valid_chunk['x_full'][0, 0], valid_chunk['y_full'][0, 0], preds[0, 0], filepath=trial.file_path('segmentations/segmented_%04d.jpg' % valid_iter), window_min=valid_out['window_min'], window_max=valid_out['window_max'], )