text: from keras_applications.imagenet_utils import _obtain_input_shape
  from keras import backend as K
  from keras.layers import Input, Convolution2D, MaxPooling2D, Activation, concatenate, Dropout, GlobalAveragePooling2D, \
      warnings
  from keras.models import Model
  from keras.engine.topology import get_source_inputs
  from keras.utils import get_file
  from keras.utils import layer_utils
  
  sq1x1 = "squeeze1x1"
  exp1x1 = "expand1x1"
  exp3x3 = "expand3x3"
  relu = "relu_"
  
  WEIGHTS_PATH = "https://github.com/rcmalli/keras-squeezenet/releases/download/v1.0/squeezenet_weights_tf_dim_ordering_tf_kernels.h5"
  
  # Modular function for Fire Node
  
  def fire_module(x, fire_id, squeeze=16, expand=64):
      s_id = 'fire' + str(fire_id) + '/'
  
      x = Convolution2D(squeeze, (1, 1), padding='valid', name=s_id + sq1x1)(x)
      x = Activation('relu', name=s_id + relu + sq1x1)(x)
  
      left = Convolution2D(expand, (1, 1), padding='valid', name=s_id + exp1x1)(x)
      left = Activation('relu', name=s_id + relu + exp1x1)(left)
  
      right = Convolution2D(expand, (3, 3), padding='same', name=s_id + exp3x3)(x)
      right = Activation('relu', name=s_id + relu + exp3x3)(right)
  
      x = concatenate([left, right], axis=3, name=s_id + 'concat')
      return x
  
  
  # Original SqueezeNet from paper.
  
  def SqueezeNet(input_tensor=None, input_shape=None,
                 weights='imagenet',
                 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/require_flatten`'
                           ' 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=True)
  
      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)
      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)
      out = Activation('softmax', name='loss')(x)
  
      # 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, out, name='squeezenet')
  
      # load weights
      if weights == 'imagenet':
  
          weights_path = get_file('squeezenet_weights_tf_dim_ordering_tf_kernels.h5',
                                      WEIGHTS_PATH,
                                      cache_subdir='models')
          model.load_weights(weights_path)
  
          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
  
  
  