What should DataBlock summary return? | Problems with masks when doing image segmentation

I am having problems working with image segmentation with DataBlocks following the DataBlock tutorial and The Walk with Fastai 2. The masks I pass as targets for training are displayed blank when calling DataBlock data loaders’ show_batch function.

I recently found the DataBlock’s summary function and am currently analysing what it shows. At the moment I am wondering what the final sample should show. For me it looks like this:

Building one sample
  Pipeline: PILBase.create
    starting from
    applying PILBase.create gives
      PILImage mode=RGB size=4000x4000
  Pipeline: <lambda> -> PILBase.create
    starting from
    applying <lambda> gives
    applying PILBase.create gives
      PILMask mode=L size=4000x4000
Final sample: (PILImage mode=RGB size=4000x4000, PILMask mode=L size=4000x4000)
  1. If I understand correctly the final sample is a mask as an image and the same mask as PILMask. Is it how it should be?

  2. Also, before it says that the DataBlock, I guess, found 16 items, which is the correct number of input and target pairs I pass (8 images, 8 masks). After that, it says 2 datasets of sizes 13,3. I am confused about it. What does it mean? 13+3 is 16. However, shouldn’t it be 2 datasets of sizes 8, 8?

My directory setup is:

  • a directory ‘photos’ which I write to code as train_path.
  • the directory has folders ‘v1’ through ‘v8’ in it
  • Every vX folder contains two folders: ‘photo’ and ‘mask’ where each contains appropriate photos.

My guess is that I am not passing the input and target mask correctly because I haven’t seen anyone passing photos in this setup. However, I want to keep the set up that way, because later I will put more input and target photos in them

  1. Earlier I mentioned the problem with mask. In the summery I found Setting up after_batch: Pipeline: IntToFloatTensor -- {'div': 255.0, 'div_mask': 1} . As I read around it converts input into tensor. I assume, that ‘div_mask’ states for to divide mask pixel values - not to change them. Could it be some way changing it to fix the mask problem I am having?
    I use a custom get_msk method get_msk = lambda o: 'photos/{}/masks/mask.tif'.format(o.parts[1]). I create a PILMask using it and print it. It does show the mask I am expecting, so the file itself is fine.

Thank you

  1. As I see it, the final sample is a tuple of the result from (block[0],block[1]) , which you defined in your DataBlock(blocks=( <your block0> , <your block1)…)
    Have a look at Jeremys explanation in Lesson 2 - Deep learning for Coders https://youtu.be/BvHmRx14HQ8?t=4897
1 Like

2 datasets of sizes 13,3

That means you have 13items in the training set and 3 in your validation set.
The ratio depends on how you setup your splitter. E.g if you use RandomSplitter then it defaults to 20% for validation set.

1 Like