(include_top=True, weights='imagenet',
               input_tensor=None, input_shape=None,
               pooling=None,
               classes=1000)
return model
Instantiates the SqueezeNet architecture.
Instantiates the SqueezeNet architecture.
Instantiates the SqueezeNet architecture .
def SqueezeNet(include_top=True, weights='imagenet',
               input_tensor=None, input_shape=None,
               pooling=None,
               classes=1000):
    """Instantiates the SqueezeNet architecture.
    """
        
    if weights not in {'imagenet', None}:
        raise ValueError('The `weights` argument should be either '
                         '`None` (random initialization) or `imagenet` '
                         '(pre-training on ImageNet).')

    if weights == 'imagenet' and classes != 1000:
        raise ValueError('If using `weights` as imagenet with `include_top`'
                         ' as true, `classes` should be 1000')


    input_shape = _obtain_input_shape(input_shape,
                                      default_size=227,
                                      min_size=48,
                                      data_format=K.image_data_format(),
                                      require_flatten=include_top)

    if input_tensor is None:
        img_input = Input(shape=input_shape)
    else:
        if not K.is_keras_tensor(input_tensor):
            img_input = Input(tensor=input_tensor, shape=input_shape)
        else:
            img_input = input_tensor


    x = Convolution2D(64, (3, 3), strides=(2, 2), padding='valid', name='conv1')(img_input)
    x = Activation('relu', name='relu_conv1')(x)
    x = MaxPooling2D(pool_size=(3, 3), strides=(2, 2), name='pool1')(x)

    x = fire_module(x, fire_id=2, squeeze=16, expand=64)
    x = fire_module(x, fire_id=3, squeeze=16, expand=64)
    x = MaxPooling2D(pool_size=(3, 3), strides=(2, 2), name='pool3')(x)

    x = fire_module(x, fire_id=4, squeeze=32, expand=128)
    x = fire_module(x, fire_id=5, squeeze=32, expand=128)
    x = MaxPooling2D(pool_size=(3, 3), strides=(2, 2), name='pool5')(x)

    x = fire_module(x, fire_id=6, squeeze=48, expand=192)
    x = fire_module(x, fire_id=7, squeeze=48, expand=192)
    x = fire_module(x, fire_id=8, squeeze=64, expand=256)
    x = fire_module(x, fire_id=9, squeeze=64, expand=256)
    
    if include_top:
        # It's not obvious where to cut the network... 
        # Could do the 8th or 9th layer... some work recommends cutting earlier layers.
    
        x = Dropout(0.5, name='drop9')(x)

        x = Convolution2D(classes, (1, 1), padding='valid', name='conv10')(x)
        x = Activation('relu', name='relu_conv10')(x)
        x = GlobalAveragePooling2D()(x)
        x = Activation('softmax', name='loss')(x)
    else:
        if pooling == 'avg':
            x = GlobalAveragePooling2D()(x)
        elif pooling=='max':
            x = GlobalMaxPooling2D()(x)
        elif pooling==None:
            pass
        else:
            raise ValueError("Unknown argument for 'pooling'=" + pooling)

    # Ensure that the model takes into account
    # any potential predecessors of `input_tensor`.
    if input_tensor is not None:
        inputs = get_source_inputs(input_tensor)
    else:
        inputs = img_input

    model = Model(inputs, x, name='squeezenet')

    # load weights
    if weights == 'imagenet':
        if include_top:
            weights_path = get_file('squeezenet_weights_tf_dim_ordering_tf_kernels.h5',
                                    WEIGHTS_PATH,
                                    cache_subdir='models')
        else:
            weights_path = get_file('squeezenet_weights_tf_dim_ordering_tf_kernels_notop.h5',
                                    WEIGHTS_PATH_NO_TOP,
                                    cache_subdir='models')
            
        model.load_weights(weights_path)
        if K.backend() == 'theano':
            layer_utils.convert_all_kernels_in_model(model)

        if K.image_data_format() == 'channels_first':

            if K.backend() == 'tensorflow':
                warnings.warn('You are using the TensorFlow backend, yet you '
                              'are using the Theano '
                              'image data format convention '
                              '(`image_data_format="channels_first"`). '
                              'For best performance, set '
                              '`image_data_format="channels_last"` in '
                              'your Keras config '
                              'at ~/.keras/keras.json.')
    return model
def SqueezeNet ( include_top = True , weights = 'imagenet' , input_tensor = None , input_shape = None , pooling = None , classes = 1000 ) : if weights not in { 'imagenet' , None } : raise ValueError ( 'The `weights` argument should be either ' '`None` (random initialization) or `imagenet` ' '(pre-training on ImageNet).' ) if weights == 'imagenet' and classes != 1000 : raise ValueError ( 'If using `weights` as imagenet with `include_top`' ' as true, `classes` should be 1000' ) input_shape = _obtain_input_shape ( input_shape , default_size = 227 , min_size = 48 , data_format = K . image_data_format ( ) , require_flatten = include_top ) if input_tensor is None : img_input = Input ( shape = input_shape ) else : if not K . is_keras_tensor ( input_tensor ) : img_input = Input ( tensor = input_tensor , shape = input_shape ) else : img_input = input_tensor x = Convolution2D ( 64 , ( 3 , 3 ) , strides = ( 2 , 2 ) , padding = 'valid' , name = 'conv1' ) ( img_input ) x = Activation ( 'relu' , name = 'relu_conv1' ) ( x ) x = MaxPooling2D ( pool_size = ( 3 , 3 ) , strides = ( 2 , 2 ) , name = 'pool1' ) ( x ) x = fire_module ( x , fire_id = 2 , squeeze = 16 , expand = 64 ) x = fire_module ( x , fire_id = 3 , squeeze = 16 , expand = 64 ) x = MaxPooling2D ( pool_size = ( 3 , 3 ) , strides = ( 2 , 2 ) , name = 'pool3' ) ( x ) x = fire_module ( x , fire_id = 4 , squeeze = 32 , expand = 128 ) x = fire_module ( x , fire_id = 5 , squeeze = 32 , expand = 128 ) x = MaxPooling2D ( pool_size = ( 3 , 3 ) , strides = ( 2 , 2 ) , name = 'pool5' ) ( x ) x = fire_module ( x , fire_id = 6 , squeeze = 48 , expand = 192 ) x = fire_module ( x , fire_id = 7 , squeeze = 48 , expand = 192 ) x = fire_module ( x , fire_id = 8 , squeeze = 64 , expand = 256 ) x = fire_module ( x , fire_id = 9 , squeeze = 64 , expand = 256 ) if include_top : # It's not obvious where to cut the network...  # Could do the 8th or 9th layer... some work recommends cutting earlier layers. x = Dropout ( 0.5 , name = 'drop9' ) ( x ) x = Convolution2D ( classes , ( 1 , 1 ) , padding = 'valid' , name = 'conv10' ) ( x ) x = Activation ( 'relu' , name = 'relu_conv10' ) ( x ) x = GlobalAveragePooling2D ( ) ( x ) x = Activation ( 'softmax' , name = 'loss' ) ( x ) else : if pooling == 'avg' : x = GlobalAveragePooling2D ( ) ( x ) elif pooling == 'max' : x = GlobalMaxPooling2D ( ) ( x ) elif pooling == None : pass else : raise ValueError ( "Unknown argument for 'pooling'=" + pooling ) # Ensure that the model takes into account # any potential predecessors of `input_tensor`. if input_tensor is not None : inputs = get_source_inputs ( input_tensor ) else : inputs = img_input model = Model ( inputs , x , name = 'squeezenet' ) # load weights if weights == 'imagenet' : if include_top : weights_path = get_file ( 'squeezenet_weights_tf_dim_ordering_tf_kernels.h5' , WEIGHTS_PATH , cache_subdir = 'models' ) else : weights_path = get_file ( 'squeezenet_weights_tf_dim_ordering_tf_kernels_notop.h5' , WEIGHTS_PATH_NO_TOP , cache_subdir = 'models' ) model . load_weights ( weights_path ) if K . backend ( ) == 'theano' : layer_utils . convert_all_kernels_in_model ( model ) if K . image_data_format ( ) == 'channels_first' : if K . backend ( ) == 'tensorflow' : warnings . warn ( 'You are using the TensorFlow backend, yet you ' 'are using the Theano ' 'image data format convention ' '(`image_data_format="channels_first"`). ' 'For best performance, set ' '`image_data_format="channels_last"` in ' 'your Keras config ' 'at ~/.keras/keras.json.' ) return model