from fastai.gen_doc.nbdoc import * from fastai.vision import * from fastai.vision.interpret import * show_doc(SegmentationInterpretation) show_doc(SegmentationInterpretation.top_losses) show_doc(SegmentationInterpretation._interp_show) show_doc(SegmentationInterpretation.show_xyz) show_doc(SegmentationInterpretation._generate_confusion) show_doc(SegmentationInterpretation._plot_intersect_cm) camvid = untar_data(URLs.CAMVID_TINY) path_lbl = camvid/'labels' path_img = camvid/'images' codes = np.loadtxt(camvid/'codes.txt', dtype=str) get_y_fn = lambda x: path_lbl/f'{x.stem}_P{x.suffix}' data = (SegmentationItemList.from_folder(path_img) .split_by_rand_pct() .label_from_func(get_y_fn, classes=codes) .transform(get_transforms(), tfm_y=True, size=128) .databunch(bs=16, path=camvid) .normalize(imagenet_stats)) data.show_batch(rows=2, figsize=(7,5)) learn = unet_learner(data, models.resnet18) learn.fit_one_cycle(3,1e-2) learn.save('mini_train') jekyll_warn("Following results will not make much sense with this underperforming model but functionality will be explained with ease") interp = SegmentationInterpretation.from_learner(learn) top_losses, top_idxs = interp.top_losses(sizes=(128,128)) top_losses, top_idxs plt.hist(to_np(top_losses), bins=20);plt.title("Loss Distribution"); learn.data.classes mean_cm, single_img_cm = interp._generate_confusion() mean_cm.shape, single_img_cm.shape df = interp._plot_intersect_cm(mean_cm, "Mean of Ratio of Intersection given True Label") i = top_idxs[0] df = interp._plot_intersect_cm(single_img_cm[i], f"Ratio of Intersection given True Label, Image:{i}") interp.show_xyz(i, sz=15) jekyll_warn("""With matplotlib colormaps the max number of unique qualitative colors is 20. So if len(classes) > 20 then close class indexes may be plotted with the same color. Let's fix this together :)""") interp.c2i show_doc(ObjectDetectionInterpretation) jekyll_warn("ObjectDetectionInterpretation is not implemented yet. Feel free to implement it :)")