Group Abstract Group Abstract

Message Boards Message Boards

UNET image segmentation in stem cells research

POSTED BY: Ali Hashmi
11 Replies
POSTED BY: Wolfgang Hitzl

Hi Wolfgang,

I am glad it worked for you. It is very nice dataset btw. Cheers to you

POSTED BY: Ali Hashmi

Hi Wolfgang,

Looks great!!

It might be of interest to the community, i have transformed the notebook into proper paclet. With some demos and documentation. I have extended the networks with some other CONV blocks based on ResNet and others. All methods are fully generalized for 2D and 3D.

UNET

Enjoy!

POSTED BY: Martijn Froeling
Attachments:
POSTED BY: Martijn Froeling

Hi Martijn,

Great stuff generalizing the network !! Could you kindly attach your notebook here with the sections (single class vs. multi-class) arranged separately. Many thanks !

POSTED BY: Ali Hashmi

I have attached the notebook. It also contains the code to generate the test images.

POSTED BY: Martijn Froeling

Great! As a developer in the Wolfram ML team, it's always gratifying to see people doing interesting stuff with what we provide.

There are a couple of comments i'd ike to make about this:

First, you evaluate the final performance using the pixelwise accuracy, but in semantic segmentation there is a more informative measure, namely mean intersection over union (IoU). Geometrically, that corresponds with measuring intersection / union ratio of the "blobs" corresponding to a fixed class in the prediction and ground truth masks, and then averaging those ratios for all classes. In formulas, for a given image:

$$IoU_{c} = \frac{TP_c}{TP_c + FP_c + FN_c}$$ $$IoU = Mean(IoU_c)$$

Where c is a class and TPc, FPc and FN_c are, respectively, the number of true positive, false positive and false negative predictions for class c. The true positives give you the measure of the blob intersections, while the sum gives you the union. A reasonable (but probably not the best) implementation of IoU might be:

classIOU[pred_, gt_, class_] := 
 Block[{positionP, positionN, tp, fp, fn},
  positionP = Position[pred, class];
  positionN = Delete[Range@Length[pred], positionP];
  positionP = Flatten[positionP];
  tp = Count[gt[[positionP]], class];
  fp = Length[positionP] - tp;
  fn = Count[gt[[positionN]], class];
  N[tp/(tp + fp + fn)]
  ]
IOU[pred_, gt_, nClasses_] := Mean@Table[classIOU[pred, gt, c], {c, nClasses}]

This assumes that your data is flattened and your classes are identified with integers starting from 1.

In general, IoU is preferable to pixel accuracy because it makes up for class imbalances in the masks by averaging class-wise accuracies. Suppose, in a 1-D example, that "1" is background and "2" is gastruloid, and your prediction and ground truth masks look like this:

pred = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
groundTruth = {1, 1, 1, 1, 2, 1, 1, 1, 1, 1} 

Pixel-level accuracy would be 90% here, but IoU gives you 45% (90% for background, 0% for gastruloid classes), because you completely failed to segment the gastruloid. Then, in you particular case, looks like you have a good balancing between background and object pixels in your data, so IoU shouldn't be far from pixelwise accuracy.

The second comment is just a technical one: when evaluating the accuracy you run the trained network in a Table, i.e. on each input separately. The framework also supports batch evaluation (or listable, if you want to say it à la WL). In this case, our neural network framework will figure out a suitable parallelization strategy and the computation will be much faster than a serial one. So you could, more efficiently, pre-compute net[data] outside the table and then compare it with the ground truths.

Again, congratulations for your work, the results look very good!

Thanks Matteo for the valuable input and the encouraging remarks. I will at some point replace the Hamming Distance criterion with the one you are proposing for gauging accuracy. Regarding your second comment, I realized it a few days back but I just felt lazy to make the change :)

POSTED BY: Ali Hashmi
POSTED BY: EDITORIAL BOARD
Posted 7 years ago
POSTED BY: Carl Lange

Thanks a lot Carl. Actually I did not know if there are nets available in the repository for segmentation. The repository is very cool btw !

POSTED BY: Ali Hashmi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard