def show_prediction_channels(prediction_tensor): channel_images = [] for chan in prediction_tensor: z = np.zeros(chan.shape) channel = np.stack([chan.cpu().detach().numpy(), z, z], axis=2) channel_images.append(channel) channels_images = np.array(channel_images) display_all(channel_images)
labels = labels.to(device) predictions = model(inputs) metrics = defaultdict(float) epoch_samples = inputs.size(0) loss = calc_loss(predictions, labels, metrics) print_metrics(metrics, epoch_samples, 'val') predictions = F.sigmoid(predictions) import helper input_images = [tensor_to_np(x) for x in inputs] mask_images = [helper.masks_to_colorimg(x) for x in labels] prediction_images = [helper.masks_to_colorimg(x) for x in predictions] chicken.display_all(input_images + mask_images + prediction_images) def pred_to_channels(single_pred): channel_images = [] # z = np.zeros(pix.shape) for pix in single_pred: z = np.zeros(pix.shape) channel = np.stack([pix, z, z], axis=2) channel_images.append(channel) return np.array(channel_images) channel_images = pred_to_channels(predictions[0])
def display_all(self, images, figs_per_page=20, titles=None): images = chicken.squeeze(images) images = chicken.data2d_to_grayscale(images) chicken.display_all(images, figs_per_page, titles) return