I don’t quite understand the show batch here. It’s showing 4 things instead of 2, and not only that, but Jeremy also says “Because fastai knows that you’ve given it a segmentation problem, when you call show batch, it actually combines the two pieces for you and it will color code the photo”
Can someone clarify why its showing 4 things and also what Jeremy meant by combining the two pieces for me and color coding the photo? Does he simply mean that even though we are doing a show batch on the uncolored pictures, it’ll show it as colored?
First, show_batch()'s input (where you put states the number of rows, hence 4 photos!
Second, by combining, segmentation work by having your regular image and then something called a “mask.” It operates like a halloween mask would, going over the photo. Each pixel in this “mask” has a label, much like our regular image problems do. And we can give each pixel color in this “mask” a separate label. Now, when we train our model it is learning to recognize the pixel class from the “mask” onto the photo itself, learning that correlation. Does this make sense?
If you look at the source code, link to GitHub repo, you should see how things are (hard) coded. In particular:
n_items = rows **2 if self.train_ds.x._square_show else rows
Roughly speaking, in the general case, show_batch(rows) displays rows x rows images, i.e. there are as many rows as columns.
If your batch size is too small, then
if self.dl(ds_type).batch_size < n_items: n_items = self.dl(ds_type).batch_size
shows that show_batch() will simply show a many images as your batch size.
Finally,
xs = [self.train_ds.x.reconstruct(grab_idx(x, i)) for i in range(n_items)]
shows how the images are selected (not at random). I haven’t tried to dig deeper, but tracking what reconstruct() does should completely clarify how show_batch() works.