Python keras_resnet.models() Examples
The following are 21
code examples of keras_resnet.models().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
keras_resnet
, or try the search function
.
Example #1
Source File: resnet.py From RetinaNet with MIT License | 6 votes |
def download_imagenet(self): """ Downloads ImageNet weights and returns path to weights file. """ resnet_filename = 'ResNet-{}-model.keras.h5' resnet_resource = 'https://github.com/fizyr/keras-models/releases/download/v0.0.1/{}'.format(resnet_filename) depth = int(self.backbone.replace('resnet', '')) filename = resnet_filename.format(depth) resource = resnet_resource.format(depth) if depth == 50: checksum = '3e9f4e4f77bbe2c9bec13b53ee1c2319' elif depth == 101: checksum = '05dc86924389e5b401a9ea0348a3213c' elif depth == 152: checksum = '6ee11ef2b135592f8031058820bb9e71' return get_file( filename, resource, cache_subdir='models', md5_hash=checksum )
Example #2
Source File: resnet_vocab_glo.py From PL-ZSD_Release with MIT License | 6 votes |
def resnet_retinanet(num_classes, backbone='resnet50', inputs=None, modifier=None, **kwargs): validate_backbone(backbone) # choose default input if inputs is None: inputs = keras.layers.Input(shape=(None, None, 3)) if backbone == 'resnet50': resnet = keras_resnet.models.ResNet50(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet101': resnet = keras_resnet.models.ResNet101(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet152': resnet = keras_resnet.models.ResNet152(inputs, include_top=False, freeze_bn=True) # invoke modifier if given if modifier: resnet = modifier(resnet) # create the full model model = retinanet.retinanet_bbox(inputs=inputs, num_classes=num_classes, backbone=resnet, **kwargs) return model
Example #3
Source File: resnet_vocab_glo.py From PL-ZSD_Release with MIT License | 6 votes |
def download_imagenet(backbone): validate_backbone(backbone) backbone = int(backbone.replace('resnet', '')) filename = resnet_filename.format(backbone) resource = resnet_resource.format(backbone) if backbone == 50: checksum = '3e9f4e4f77bbe2c9bec13b53ee1c2319' elif backbone == 101: checksum = '05dc86924389e5b401a9ea0348a3213c' elif backbone == 152: checksum = '6ee11ef2b135592f8031058820bb9e71' return keras.applications.imagenet_utils.get_file( filename, resource, cache_subdir='models', md5_hash=checksum )
Example #4
Source File: resnet.py From PL-ZSD_Release with MIT License | 6 votes |
def download_imagenet(backbone): validate_backbone(backbone) backbone = int(backbone.replace('resnet', '')) filename = resnet_filename.format(backbone) resource = resnet_resource.format(backbone) if backbone == 50: checksum = '3e9f4e4f77bbe2c9bec13b53ee1c2319' elif backbone == 101: checksum = '05dc86924389e5b401a9ea0348a3213c' elif backbone == 152: checksum = '6ee11ef2b135592f8031058820bb9e71' return keras.applications.imagenet_utils.get_file( filename, resource, cache_subdir='models', md5_hash=checksum )
Example #5
Source File: resnet_vocab_w2v.py From PL-ZSD_Release with MIT License | 6 votes |
def resnet_retinanet(num_classes, backbone='resnet50', inputs=None, modifier=None, **kwargs): validate_backbone(backbone) # choose default input if inputs is None: inputs = keras.layers.Input(shape=(None, None, 3)) if backbone == 'resnet50': resnet = keras_resnet.models.ResNet50(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet101': resnet = keras_resnet.models.ResNet101(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet152': resnet = keras_resnet.models.ResNet152(inputs, include_top=False, freeze_bn=True) # invoke modifier if given if modifier: resnet = modifier(resnet) # create the full model model = retinanet.retinanet_bbox(inputs=inputs, num_classes=num_classes, backbone=resnet, **kwargs) return model
Example #6
Source File: resnet_vocab_w2v.py From PL-ZSD_Release with MIT License | 6 votes |
def download_imagenet(backbone): validate_backbone(backbone) backbone = int(backbone.replace('resnet', '')) filename = resnet_filename.format(backbone) resource = resnet_resource.format(backbone) if backbone == 50: checksum = '3e9f4e4f77bbe2c9bec13b53ee1c2319' elif backbone == 101: checksum = '05dc86924389e5b401a9ea0348a3213c' elif backbone == 152: checksum = '6ee11ef2b135592f8031058820bb9e71' return keras.applications.imagenet_utils.get_file( filename, resource, cache_subdir='models', md5_hash=checksum )
Example #7
Source File: resnet.py From keras-m2det with Apache License 2.0 | 6 votes |
def download_imagenet(self): """ Downloads ImageNet weights and returns path to weights file. """ resnet_filename = 'ResNet-{}-model.keras.h5' resnet_resource = 'https://github.com/fizyr/keras-models/releases/download/v0.0.1/{}'.format(resnet_filename) depth = int(self.backbone.replace('resnet', '')) filename = resnet_filename.format(depth) resource = resnet_resource.format(depth) if depth == 50: checksum = '3e9f4e4f77bbe2c9bec13b53ee1c2319' elif depth == 101: checksum = '05dc86924389e5b401a9ea0348a3213c' elif depth == 152: checksum = '6ee11ef2b135592f8031058820bb9e71' return get_file( filename, resource, cache_subdir='models', md5_hash=checksum )
Example #8
Source File: resnet.py From DeepForest with MIT License | 6 votes |
def download_imagenet(self): """ Downloads ImageNet weights and returns path to weights file. """ resnet_filename = 'ResNet-{}-model.keras.h5' resnet_resource = 'https://github.com/fizyr/keras-models/releases/download/v0.0.1/{}'.format(resnet_filename) depth = int(self.backbone.replace('resnet', '')) filename = resnet_filename.format(depth) resource = resnet_resource.format(depth) if depth == 50: checksum = '3e9f4e4f77bbe2c9bec13b53ee1c2319' elif depth == 101: checksum = '05dc86924389e5b401a9ea0348a3213c' elif depth == 152: checksum = '6ee11ef2b135592f8031058820bb9e71' return get_file( filename, resource, cache_subdir='models', md5_hash=checksum )
Example #9
Source File: resnet.py From keras-retinanet with Apache License 2.0 | 6 votes |
def download_imagenet(self): """ Downloads ImageNet weights and returns path to weights file. """ resnet_filename = 'ResNet-{}-model.keras.h5' resnet_resource = 'https://github.com/fizyr/keras-models/releases/download/v0.0.1/{}'.format(resnet_filename) depth = int(self.backbone.replace('resnet', '')) filename = resnet_filename.format(depth) resource = resnet_resource.format(depth) if depth == 50: checksum = '3e9f4e4f77bbe2c9bec13b53ee1c2319' elif depth == 101: checksum = '05dc86924389e5b401a9ea0348a3213c' elif depth == 152: checksum = '6ee11ef2b135592f8031058820bb9e71' return get_file( filename, resource, cache_subdir='models', md5_hash=checksum )
Example #10
Source File: resnet.py From CameraRadarFusionNet with Apache License 2.0 | 6 votes |
def download_imagenet(self): """ Downloads ImageNet weights and returns path to weights file. """ resnet_filename = 'ResNet-{}-model.keras.h5' resnet_resource = 'https://github.com/fizyr/keras-models/releases/download/v0.0.1/{}'.format(resnet_filename) depth = int(self.backbone.replace('resnet', '')) filename = resnet_filename.format(depth) resource = resnet_resource.format(depth) if depth == 50: checksum = '3e9f4e4f77bbe2c9bec13b53ee1c2319' elif depth == 101: checksum = '05dc86924389e5b401a9ea0348a3213c' elif depth == 152: checksum = '6ee11ef2b135592f8031058820bb9e71' return get_file( filename, resource, cache_subdir='models', md5_hash=checksum )
Example #11
Source File: resnet.py From keras-maskrcnn with Apache License 2.0 | 6 votes |
def resnet_maskrcnn(num_classes, backbone='resnet50', inputs=None, modifier=None, mask_dtype=keras.backend.floatx(), **kwargs): # choose default input if inputs is None: inputs = keras.layers.Input(shape=(None, None, 3), name='image') # create the resnet backbone if backbone == 'resnet50': resnet = keras_resnet.models.ResNet50(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet101': resnet = keras_resnet.models.ResNet101(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet152': resnet = keras_resnet.models.ResNet152(inputs, include_top=False, freeze_bn=True) # invoke modifier if given if modifier: resnet = modifier(resnet) # create the full model model = retinanet.retinanet_mask(inputs=inputs, num_classes=num_classes, backbone_layers=resnet.outputs[1:], mask_dtype=mask_dtype, **kwargs) return model
Example #12
Source File: resnet.py From kaggle-rsna18 with MIT License | 6 votes |
def download_imagenet(self): """ Downloads ImageNet weights and returns path to weights file. """ resnet_filename = 'ResNet-{}-model.keras.h5' resnet_resource = 'https://github.com/fizyr/keras-models/releases/download/v0.0.1/{}'.format(resnet_filename) depth = int(self.backbone.replace('resnet', '')) filename = resnet_filename.format(depth) resource = resnet_resource.format(depth) if depth == 50: checksum = '3e9f4e4f77bbe2c9bec13b53ee1c2319' elif depth == 101: checksum = '05dc86924389e5b401a9ea0348a3213c' elif depth == 152: checksum = '6ee11ef2b135592f8031058820bb9e71' return get_file( filename, resource, cache_subdir='models', md5_hash=checksum )
Example #13
Source File: resnet.py From CameraRadarFusionNet with Apache License 2.0 | 5 votes |
def resnet_retinanet(num_classes, backbone='resnet50', inputs=None, modifier=None, cfg=None, **kwargs): """ Constructs a retinanet model using a resnet backbone. Args num_classes: Number of classes to predict. backbone: Which backbone to use (one of ('resnet50', 'resnet101', 'resnet152')). inputs: The inputs to the network (defaults to a Tensor of shape (None, None, 3)). modifier: A function handler which can modify the backbone before using it in retinanet (this can be used to freeze backbone layers for example). Returns RetinaNet model with a ResNet backbone. """ # choose default input if inputs is None: if keras.backend.image_data_format() == 'channels_first': inputs = keras.layers.Input(shape=(3, None, None)) else: inputs = keras.layers.Input(shape=(None, None, 3)) elif isinstance(inputs, tuple): inputs = keras.layers.Input(inputs) # create the resnet backbone if backbone == 'resnet50': resnet = keras_resnet.models.ResNet50(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet101': resnet = keras_resnet.models.ResNet101(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet152': resnet = keras_resnet.models.ResNet152(inputs, include_top=False, freeze_bn=True) else: raise ValueError('Backbone (\'{}\') is invalid.'.format(backbone)) # invoke modifier if given if modifier: resnet = modifier(resnet) # create the full model return retinanet.retinanet(inputs=inputs, num_classes=num_classes, backbone_layers=resnet.outputs[1:], **kwargs)
Example #14
Source File: resnet.py From RetinaNet with MIT License | 5 votes |
def resnet_retinanet(num_classes, backbone='resnet50', inputs=None, modifier=None, **kwargs): """ Constructs a retinanet model using a resnet backbone. Args num_classes: Number of classes to predict. backbone: Which backbone to use (one of ('resnet50', 'resnet101', 'resnet152')). inputs: The inputs to the network (defaults to a Tensor of shape (None, None, 3)). modifier: A function handler which can modify the backbone before using it in retinanet (this can be used to freeze backbone layers for example). Returns RetinaNet model with a ResNet backbone. """ # choose default input if inputs is None: inputs = keras.layers.Input(shape=(None, None, 3)) # create the resnet backbone if backbone == 'resnet50': resnet = keras_resnet.models.ResNet50(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet101': resnet = keras_resnet.models.ResNet101(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet152': resnet = keras_resnet.models.ResNet152(inputs, include_top=False, freeze_bn=True) else: raise ValueError('Backbone (\'{}\') is invalid.'.format(backbone)) # invoke modifier if given if modifier: resnet = modifier(resnet) # create the full model return retinanet.retinanet(inputs=inputs, num_classes=num_classes, backbone_layers=resnet.outputs[1:], **kwargs)
Example #15
Source File: resnet.py From keras-m2det with Apache License 2.0 | 5 votes |
def resnet_m2det(num_classes, backbone='resnet50', inputs=None, modifier=None, **kwargs): """ Constructs a m2det model using a resnet backbone. Args num_classes: Number of classes to predict. backbone: Which backbone to use (one of ('resnet50', 'resnet101', 'resnet152')). inputs: The inputs to the network (defaults to a Tensor of shape (640, 640, 3)). modifier: A function handler which can modify the backbone before using it in m2det (this can be used to freeze backbone layers for example). Returns m2det model with a ResNet backbone. """ # choose default input if inputs is None: if keras.backend.image_data_format() == 'channels_first': inputs = keras.layers.Input(shape=(3, 640, 640)) else: inputs = keras.layers.Input(shape=(640, 640, 3)) # create the resnet backbone if backbone == 'resnet50': resnet = keras_resnet.models.ResNet50(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet101': resnet = keras_resnet.models.ResNet101(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet152': resnet = keras_resnet.models.ResNet152(inputs, include_top=False, freeze_bn=True) else: raise ValueError('Backbone (\'{}\') is invalid.'.format(backbone)) # invoke modifier if given if modifier: resnet = modifier(resnet) # create the full model return m2det.m2det(inputs=inputs, num_classes=num_classes, backbone_layers=resnet.outputs[1:], **kwargs)
Example #16
Source File: train_vocab_w2v.py From PL-ZSD_Release with MIT License | 5 votes |
def create_models(backbone_retinanet, backbone, num_classes, weights, multi_gpu=0, freeze_backbone=False): modifier = freeze_model if freeze_backbone else None # Keras recommends initialising a multi-gpu model on the CPU to ease weight sharing, and to prevent OOM errors. # optionally wrap in a parallel model if multi_gpu > 1: with tf.device('/cpu:0'): model = model_with_weights(backbone_retinanet(num_classes, backbone=backbone, nms=False, modifier=modifier), weights=weights, skip_mismatch=True) training_model = multi_gpu_model(model, gpus=multi_gpu) # append NMS for prediction only classification = model.outputs[1] detections = model.outputs[2] boxes = keras.layers.Lambda(lambda x: x[:, :, :4])(detections) detections = layers.NonMaximumSuppression(name='nms')([boxes, classification, detections]) prediction_model = keras.models.Model(inputs=model.inputs, outputs=model.outputs[:2] + [detections]) else: model = model_with_weights(backbone_retinanet(num_classes, backbone=backbone, nms=True, modifier=modifier), weights=weights, skip_mismatch=True) training_model = model prediction_model = model # compile model training_model.compile( loss={ 'regression' : losses.smooth_l1(), 'classification': losses.focal() }, optimizer=keras.optimizers.adam(lr=1e-5, clipnorm=0.001) ) return model, training_model, prediction_model
Example #17
Source File: resnet.py From kaggle-rsna18 with MIT License | 5 votes |
def resnet_retinanet(num_classes, backbone='resnet50', inputs=None, modifier=None, **kwargs): """ Constructs a retinanet model using a resnet backbone. Args num_classes: Number of classes to predict. backbone: Which backbone to use (one of ('resnet50', 'resnet101', 'resnet152')). inputs: The inputs to the network (defaults to a Tensor of shape (None, None, 3)). modifier: A function handler which can modify the backbone before using it in retinanet (this can be used to freeze backbone layers for example). Returns RetinaNet model with a ResNet backbone. """ # choose default input if inputs is None: if keras.backend.image_data_format() == 'channels_first': inputs = keras.layers.Input(shape=(3, None, None)) else: inputs = keras.layers.Input(shape=(None, None, 3)) # create the resnet backbone if backbone == 'resnet50': resnet = keras_resnet.models.ResNet50(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet101': resnet = keras_resnet.models.ResNet101(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet152': resnet = keras_resnet.models.ResNet152(inputs, include_top=False, freeze_bn=True) else: raise ValueError('Backbone (\'{}\') is invalid.'.format(backbone)) # invoke modifier if given if modifier: resnet = modifier(resnet) # create the full model return retinanet.retinanet(inputs=inputs, num_classes=num_classes, backbone_layers=resnet.outputs[1:], **kwargs)
Example #18
Source File: utils.py From semantic-embeddings with MIT License | 5 votes |
def get_custom_objects(architecture): """ Provides a dictionary with custom objects required for loading a certain model architecture using `keras.models.load_model`. """ if architecture in ('resnet-32', 'resnet-110', 'resnet-110-fc', 'resnet-110-wfc', 'pyramidnet-272-200', 'pyramidnet-110-270'): return { 'ChannelPadding' : cifar_resnet.ChannelPadding } else: return {}
Example #19
Source File: resnet.py From DeepForest with MIT License | 5 votes |
def resnet_retinanet(num_classes, backbone='resnet50', inputs=None, modifier=None, **kwargs): """ Constructs a retinanet model using a resnet backbone. Args num_classes: Number of classes to predict. backbone: Which backbone to use (one of ('resnet50', 'resnet101', 'resnet152')). inputs: The inputs to the network (defaults to a Tensor of shape (None, None, 3)). modifier: A function handler which can modify the backbone before using it in retinanet (this can be used to freeze backbone layers for example). Returns RetinaNet model with a ResNet backbone. """ # choose default input if inputs is None: if keras.backend.image_data_format() == 'channels_first': inputs = keras.layers.Input(shape=(3, None, None)) else: inputs = keras.layers.Input(shape=(None, None, 3)) # create the resnet backbone if backbone == 'resnet50': resnet = keras_resnet.models.ResNet50(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet101': resnet = keras_resnet.models.ResNet101(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet152': resnet = keras_resnet.models.ResNet152(inputs, include_top=False, freeze_bn=True) else: raise ValueError('Backbone (\'{}\') is invalid.'.format(backbone)) # invoke modifier if given if modifier: resnet = modifier(resnet) # create the full model return retinanet.retinanet(inputs=inputs, num_classes=num_classes, backbone_layers=resnet.outputs[1:], **kwargs)
Example #20
Source File: resnet.py From keras-retinanet with Apache License 2.0 | 4 votes |
def resnet_retinanet(num_classes, backbone='resnet50', inputs=None, modifier=None, **kwargs): """ Constructs a retinanet model using a resnet backbone. Args num_classes: Number of classes to predict. backbone: Which backbone to use (one of ('resnet50', 'resnet101', 'resnet152')). inputs: The inputs to the network (defaults to a Tensor of shape (None, None, 3)). modifier: A function handler which can modify the backbone before using it in retinanet (this can be used to freeze backbone layers for example). Returns RetinaNet model with a ResNet backbone. """ # choose default input if inputs is None: if keras.backend.image_data_format() == 'channels_first': inputs = keras.layers.Input(shape=(3, None, None)) else: inputs = keras.layers.Input(shape=(None, None, 3)) # create the resnet backbone if backbone == 'resnet50': resnet = keras_resnet.models.ResNet50(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet101': resnet = keras_resnet.models.ResNet101(inputs, include_top=False, freeze_bn=True) elif backbone == 'resnet152': resnet = keras_resnet.models.ResNet152(inputs, include_top=False, freeze_bn=True) else: raise ValueError('Backbone (\'{}\') is invalid.'.format(backbone)) # invoke modifier if given if modifier: resnet = modifier(resnet) # create the full model # resnet.outputs contains 4 layers backbone_layers = { 'C2': resnet.outputs[0], 'C3': resnet.outputs[1], 'C4': resnet.outputs[2], 'C5': resnet.outputs[3] } return retinanet.retinanet(inputs=inputs, num_classes=num_classes, backbone_layers=backbone_layers, **kwargs)
Example #21
Source File: train_vocab_w2v.py From PL-ZSD_Release with MIT License | 4 votes |
def parse_args(args): parser = argparse.ArgumentParser(description='Simple training script for training a RetinaNet network.') subparsers = parser.add_subparsers(help='Arguments for specific dataset types.', dest='dataset_type') subparsers.required = True coco_parser = subparsers.add_parser('coco') coco_parser.add_argument('coco_path', help='Path to dataset directory (ie. /tmp/COCO).') pascal_parser = subparsers.add_parser('pascal') pascal_parser.add_argument('pascal_path', help='Path to dataset directory (ie. /tmp/VOCdevkit).') kitti_parser = subparsers.add_parser('kitti') kitti_parser.add_argument('kitti_path', help='Path to dataset directory (ie. /tmp/kitti).') def csv_list(string): return string.split(',') oid_parser = subparsers.add_parser('oid') oid_parser.add_argument('main_dir', help='Path to dataset directory.') oid_parser.add_argument('--version', help='The current dataset version is V3.', default='2017_11') oid_parser.add_argument('--labels-filter', help='A list of labels to filter.', type=csv_list, default=None) oid_parser.add_argument('--annotation-cache-dir', help='Path to store annotation cache.', default='.') oid_parser.add_argument('--fixed-labels', help='Use the exact specified labels.', default=False) csv_parser = subparsers.add_parser('csv') csv_parser.add_argument('annotations', help='Path to CSV file containing annotations for training.') csv_parser.add_argument('classes', help='Path to a CSV file containing class label mapping.') csv_parser.add_argument('--val-annotations', help='Path to CSV file containing annotations for validation (optional).') group = parser.add_mutually_exclusive_group() group.add_argument('--snapshot', help='Resume training from a snapshot.') group.add_argument('--imagenet-weights', help='Initialize the model with pretrained imagenet weights. This is the default behaviour.', action='store_const', const=True, default=True) group.add_argument('--weights', help='Initialize the model with weights from a file.') group.add_argument('--no-weights', help='Don\'t initialize the model with any weights.', dest='imagenet_weights', action='store_const', const=False) parser.add_argument('--backbone', help='Backbone model used by retinanet.', default='resnet50', type=str) parser.add_argument('--batch-size', help='Size of the batches.', default=1, type=int) parser.add_argument('--gpu', help='Id of the GPU to use (as reported by nvidia-smi).') parser.add_argument('--multi-gpu', help='Number of GPUs to use for parallel processing.', type=int, default=0) parser.add_argument('--multi-gpu-force', help='Extra flag needed to enable (experimental) multi-gpu support.', action='store_true') parser.add_argument('--epochs', help='Number of epochs to train.', type=int, default=30) parser.add_argument('--steps', help='Number of steps per epoch.', type=int, default=10000) parser.add_argument('--snapshot-path', help='Path to store snapshots of models during training (defaults to \'./snapshots\')', default='./snapshots') parser.add_argument('--tensorboard-dir', help='Log directory for Tensorboard output', default='./logs') parser.add_argument('--no-snapshots', help='Disable saving snapshots.', dest='snapshots', action='store_false') parser.add_argument('--no-evaluation', help='Disable per epoch evaluation.', dest='evaluation', action='store_false') parser.add_argument('--freeze-backbone', help='Freeze training of backbone layers.', action='store_true') return check_args(parser.parse_args(args))