Esempio n. 1
0
    def download_imagenet(self):
        """ Download pre-trained weights for the specified backbone name.
        This name is in the format mobilenet{rows}_{alpha} where rows is the
        imagenet shape dimension and 'alpha' controls the width of the network.
        For more info check the explanation from the keras mobilenet script itself.
        """

        alpha = float(self.backbone.split('_')[1])
        rows = int(self.backbone.split('_')[0].replace('mobilenet', ''))

        # load weights
        if keras.backend.image_data_format() == 'channels_first':
            raise ValueError('Weights for "channels_last" format '
                             'are not available.')
        if alpha == 1.0:
            alpha_text = '1_0'
        elif alpha == 0.75:
            alpha_text = '7_5'
        elif alpha == 0.50:
            alpha_text = '5_0'
        else:
            alpha_text = '2_5'

        model_name = 'mobilenet_{}_{}_tf_no_top.h5'.format(alpha_text, rows)
        weights_url = BASE_WEIGHT_PATH + model_name
        weights_path = get_file(model_name, weights_url, cache_subdir='models')

        return weights_path
Esempio n. 2
0
def download_imagenet(backbone):
    """ Download pre-trained weights for the specified backbone name. This name is in the format
        mobilenet{rows}_{alpha} where rows is the imagenet shape dimension and 'alpha' controls
        the width of the network.
        For more info check the explanation from the keras mobilenet script itself
    # Arguments
        backbone    : Backbone name.
    """

    alpha = float(backbone.split('_')[1])
    rows = int(backbone.split('_')[0].replace('mobilenet', ''))

    # load weights
    if keras.backend.image_data_format() == 'channels_first':
        raise ValueError('Weights for "channels_last" format '
                         'are not available.')
    if alpha == 1.0:
        alpha_text = '1_0'
    elif alpha == 0.75:
        alpha_text = '7_5'
    elif alpha == 0.50:
        alpha_text = '5_0'
    else:
        alpha_text = '2_5'

    model_name = 'mobilenet_{}_{}_tf_no_top.h5'.format(alpha_text, rows)
    weights_url = BASE_WEIGHT_PATH + model_name
    weights_path = get_file(model_name, weights_url, cache_subdir='models')

    return weights_path