def NuclearSegmentationModel(input_shape=(None, None, 1), backbone='resnet50', use_pretrained_weights=True): """ A RetinaMask model with a ResNet50 backbone for nuclear segmentation trained on DAPI data. Args: input_shape (tuple): a 3-length tuple of the input data shape. backbone (str): name of the backbone to use for the model. use_pretrained_weights (bool): whether to load pre-trained weights. Only supports the ResNet50 backbone. """ backbone_levels = ['C1', 'C2', 'C3', 'C4', 'C5'] pyramid_levels = ['P2', 'P3', 'P4'] anchor_size_dict = {'P2': 8, 'P3': 16, 'P4': 32} # Set up the prediction model anchor_params = generate_anchor_params(pyramid_levels, anchor_size_dict) model = model_zoo.RetinaMask( backbone=backbone, use_imagenet=False, panoptic=True, num_semantic_heads=2, num_semantic_classes=[4, 4], input_shape=input_shape, num_classes=1, backbone_levels=backbone_levels, pyramid_levels=pyramid_levels, anchor_params=anchor_params, norm_method='whole_image') if use_pretrained_weights: if backbone == 'resnet50': # '/data/models/resnet50_panoptic_train-val_DVV_V4.h5' weights_path = get_file( 'resnet50_panoptic_nuclear_segmentation.h5', WEIGHTS_PATH, cache_subdir='models', md5_hash='6e925c49cb05a1e3b0e2210220922445') model.load_weights(weights_path) else: raise ValueError('Backbone %s does not have a weights file.' % backbone) return model
def PhaseSegmentationModel(input_shape=(None, None, 1), backbone='resnet50', use_pretrained_weights=True): """ A RetinaMask model with a ResNet50 backbone for cytoplasmic segmentation trained on phase data. Args: input_shape (tuple): a 3-length tuple of the input data shape. backbone (str): name of the backbone to use for the model. use_pretrained_weights (bool): whether to load pre-trained weights. Only supports the ResNet50 backbone. """ backbone_levels = ['C1', 'C2', 'C3', 'C4', 'C5'] pyramid_levels = ['P3', 'P4', 'P5', 'P6'] anchor_size_dicts = {'P3': 32, 'P4': 64, 'P5': 128, 'P6': 256} anchor_params = generate_anchor_params(pyramid_levels, anchor_size_dicts) model = model_zoo.RetinaMask( backbone=backbone, use_imagenet=False, panoptic=False, num_semantic_heads=2, num_semantic_classes=[4, 4], input_shape=input_shape, num_classes=1, backbone_levels=backbone_levels, pyramid_levels=pyramid_levels, anchor_params=anchor_params, norm_method='whole_image') if use_pretrained_weights: if backbone == 'resnet50': weights_path = get_file( 'resnet50_retinanet_20190813_all_phase_512.h5', WEIGHTS_PATH, cache_subdir='models', md5_hash='ce31d084fadf7b907a25ab1fcf25529a') model.load_weights(weights_path) else: raise ValueError('Backbone %s does not have a weights file.' % backbone) return model
def PhaseSegmentationModel(input_shape=(None, None, 1), backbone='resnet50', use_pretrained_weights=True): """Initialize a model for cytoplasmic segmentation based on phase data. """ backbone_levels = ['C1', 'C2', 'C3', 'C4', 'C5'] pyramid_levels = ['P3', 'P4', 'P5', 'P6'] anchor_size_dicts = {'P3': 32, 'P4': 64, 'P5': 128, 'P6': 256} anchor_params = generate_anchor_params(pyramid_levels, anchor_size_dicts) model = model_zoo.RetinaMask(backbone=backbone, use_imagenet=False, panoptic=False, num_semantic_heads=2, num_semantic_classes=[4, 4], input_shape=input_shape, num_classes=1, backbone_levels=backbone_levels, pyramid_levels=pyramid_levels, anchor_params=anchor_params, norm_method='whole_image') if use_pretrained_weights: if backbone == 'resnet50': weights_path = get_file( 'resnet50_retinanet_20190813_all_phase_512.h5', WEIGHTS_PATH, cache_subdir='models', md5_hash='ce31d084fadf7b907a25ab1fcf25529a') model.load_weights(weights_path) else: raise ValueError('Backbone %s does not have a weights file.' % backbone) return model
def NuclearSegmentationModel(input_shape=(None, None, 1), backbone='resnet50', use_pretrained_weights=True): """Initialize a model for nuclear segmentation based on dapi data.""" backbone_levels = ['C1', 'C2', 'C3', 'C4', 'C5'] pyramid_levels = ['P2', 'P3', 'P4'] anchor_size_dict = {'P2': 8, 'P3': 16, 'P4': 32} # Set up the prediction model anchor_params = generate_anchor_params(pyramid_levels, anchor_size_dict) model = model_zoo.RetinaMask(backbone=backbone, use_imagenet=False, panoptic=True, num_semantic_heads=2, num_semantic_classes=[4, 4], input_shape=input_shape, num_classes=1, backbone_levels=backbone_levels, pyramid_levels=pyramid_levels, anchor_params=anchor_params, norm_method='whole_image') if use_pretrained_weights: if backbone == 'resnet50': # '/data/models/resnet50_panoptic_train-val_DVV_V4.h5' weights_path = get_file( 'resnet50_panoptic_nuclear_segmentation.h5', WEIGHTS_PATH, cache_subdir='models', md5_hash='6e925c49cb05a1e3b0e2210220922445') model.load_weights(weights_path) else: raise ValueError('Backbone %s does not have a weights file.' % backbone) return model