Path: blob/master/samples/nucleus/inspect_nucleus_data.ipynb
240 views
Inspect Nucleus Training Data
Inspect and visualize data loading and pre-processing code.
Configurations
Notebook Preferences
Dataset
Download the dataset from the competition Website. Unzip it and save it in mask_rcnn/datasets/nucleus
. If you prefer a different directory then change the DATASET_DIR
variable above.
Display Samples
Dataset Stats
Loop through all images in the dataset and collect aggregate stats.
Image Size Stats
Nuclei per Image Stats
Nuclei Size Stats
Image Augmentation
Test out different augmentation methods
Image Crops
Microscoy images tend to be large, but nuclei are small. So it's more efficient to train on random crops from large images. This is handled by config.IMAGE_RESIZE_MODE = "crop"
.
Mini Masks
Instance binary masks can get large when training with high resolution images. For example, if training with 1024x1024 image then the mask of a single instance requires 1MB of memory (Numpy uses bytes for boolean values). If an image has 100 instances then that's 100MB for the masks alone.
To improve training speed, we optimize masks:
We store mask pixels that are inside the object bounding box, rather than a mask of the full image. Most objects are small compared to the image size, so we save space by not storing a lot of zeros around the object.
We resize the mask to a smaller size (e.g. 56x56). For objects that are larger than the selected size we lose a bit of accuracy. But most object annotations are not very accuracy to begin with, so this loss is negligable for most practical purposes. Thie size of the mini_mask can be set in the config class.
To visualize the effect of mask resizing, and to verify the code correctness, we visualize some examples.
Anchors
For an FPN network, the anchors must be ordered in a way that makes it easy to match anchors to the output of the convolution layers that predict anchor scores and shifts.
Sort by pyramid level first. All anchors of the first level, then all of the second and so on. This makes it easier to separate anchors by level.
Within each level, sort anchors by feature map processing sequence. Typically, a convolution layer processes a feature map starting from top-left and moving right row by row.
For each feature map cell, pick any sorting order for the anchors of different ratios. Here we match the order of ratios passed to the function.
Data Generator
ROIs
Typically, the RPN network generates region proposals (a.k.a. Regions of Interest, or ROIs). The data generator has the ability to generate proposals as well for illustration and testing purposes. These are controlled by the random_rois
parameter.