Giter Club home page Giter Club logo

sartorius_cell_instance_segmentation_kaggle's Introduction

A solution to the Sartorius Cell Instance Segmentation Kaggle

https://www.kaggle.com/c/sartorius-cell-instance-segmentation

Solution summary

  1. Semantic segmentation by Unet.
  2. Instance segmentation by further processing of semantic segmentation with Deep Watershed Transform.

Deep Watershed Transform Network:

Semantic segmentation (Unet)

  1. To generate training target:
python seggit/data/scripts/make_semseg_target.py
  1. To make a training run:
python seggit/training/run_segmentation.py
  1. To make inference:
from seggit.cell_semantic_segmentation import SemanticSegmenter
segmenter = SemanticSegmenter(checkpoint_path='best.pth')
img, semseg = segmenter.predict('sample.png')

Direction Net (DN)

  1. To generate training target:
python seggit/data/scripts/make_uvec.py
  1. To make a training run:
python training/run_direction.py

Watershed Transform Net (WTN)

  1. To generate training target:
python seggit/data/scripts/make_wngy.py
  1. To make a training run:
python training/run_energy.py

Deep Watershed Transform end-to-end (DN + WTN = WN)

  1. To make a training run:
python training/run_watershed.py
  1. To make an inference:
from seggit.deep_watershed_transform import DeepWatershedTransform

dwt = DeepWatershedTransform(checkpoint_path='best.pth')
wngy = dwt.predict(img, semg)

Cell instance segmentation (Unet + WN)

To make an inference :

from seggit.cell_instance_segmentation import CellSegmenter

parser = argparse.ArgumentParser()
CellSegmenter.add_argparse_args(parser)
args = parser.parse_args()
args.pth_unet = 'best_unet.pth'
args.pth_wn = 'best_wn.pth'

segmenter = CellSegmenter(args)

img, instg = segmenter.predict('sample.png')

References

sartorius_cell_instance_segmentation_kaggle's People

Contributors

qap avatar

Watchers

 avatar

sartorius_cell_instance_segmentation_kaggle's Issues

Cannot convert to torchscript when model's forward function instantiates a nn.Module.

This occurs when running pl.LightningModule.to_torchscript, when, in the forward method of the model, there is an instantiation of a nn class, like nn.Upsample. Perhaps, the instantiation needs to happen in the model's __init__ method.

FrontendError: Cannot instantiate class 'Upsample' in a script function:
  File "/kaggle/sartorius_cell_instance_segmentation_kaggle/seggit/models/watershed_transform_net.py", line 47
        x = self.fcn(x)
    
        x = nn.Upsample(input_size)(x)
            ~~~~~~~~~~~ <--- HERE
    
        return x

DN inference breaks

Using original image and semg size, forward propagation raises error. Likely caused by the sizes not being divisible by 32.

Rotational augmentation transforms for uvec

Whole-image maps of:

  • semantic segmentation (semg)
  • distance transform (dtfm)
  • normalised gradient distance transform (uvec)
  • discrete watershed energy (wngy)

are built up by computing them for individual cells, pasting them into the image frame, in order of descending of cell area.

There would be fewer computations if the whole-image uvec map was computed directly from the whole-map dtfm, but the resulting uvec map doesn't appear to mark out the cell boundaries well.

In addition, for rotational transforms during data augmentation, the uvec needs to be computed from the distance transform after the distance transform has been rotated. Its components cannot be simply treated like scalar maps that can be rotated the usual way using albumentations.

Because of these, it seems there are 2 options:

  1. During data augmentation, build all the needed maps from individual cell annotations. Pass individual cells' dtfm through the rotation, compute their uvec, then build up the whole-image uvec map from them. This might be too time-consuming.
  2. Rotate the whole-image uvec map using own rotation implementation, rotate all other maps using albumentations. This might restrict the variety of rotational transformations that can be used though.

What training target for the semantic segmentation stage?

Have tried:

  1. 1-channel target, cells with overlap removed.
  2. 2-channel target. Channel 0 contains cells but with annotation overlap and touching borders removed. Channel 1 contains those regions removed in channel 0. See example.

It seems that the above target choices are geared towards separating the cells.

In the deep watershed transform approach, the semantic segmentation stage seems to be only about separating the different classes. The separation of instances begins with the Direction Net.

In Fig.4 of the deep watershed transform paper, it's seen that the semantic segmentation makes no attempt at separating the two cars. They are merged together under one mask. It's only in the next stage that the direction net is required to predict the direction vectors, which do mark out the boundary between the two cars. The direction loss is maximum when vectors on either side of a boundary point in the same direction.

It therefore looks like the training target should simply be just a 1-channel boolean mask, where it's True if the pixel comes under at least one cell, and False if it comes under no cells.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.