def get_list_from_model(learn:Learner, ds_type:DatasetType, batch:Tuple)->[]: "Factory method to convert a batch of model images to a list of ModelImageSet." image_sets = [] x,y = batch[0],batch[1] preds = learn.pred_batch(ds_type=ds_type, batch=(x,y), reconstruct=True) for orig_px, real_px, gen in zip(x,y,preds): orig, real = Image(px=orig_px), Image(px=real_px) image_set = ModelImageSet(orig=orig, real=real, gen=gen) image_sets.append(image_set) return image_sets
def show_prediction_vs_actual(sample_idx: int, learn: Learner) -> ImageSegment: """Return predicted mask, additionally print input image and tile-level label""" sample = learn.data.valid_ds[sample_idx] image, label = sample print("Label: " + str(label.__repr__())) image.show() batch = learn.data.one_item(image) pred = learn.pred_batch(batch=batch).squeeze(dim=0) img = pred.argmax(dim=0, keepdim=True) predicted_colors = torch.zeros(len(ALL_CLASSES)) for i in img.unique(): predicted_colors[i] = 1 print("Predicted colors: " + str(predicted_colors)) image_segment = ImageSegment(img) return image_segment