text: import tensorflow as tf
  import tensorflow.contrib.slim as slim
  from tensorflow.contrib.layers.python.layers import utils
  
  
  class DeepCNN(object):
      def __init__(self, inputs, is_training):
          self._scope = 'deep_cnn'
  
          with slim.arg_scope(self._arg_scope(is_training)):
              self.build_net(inputs)
  
      def build_net(self, inputs):
          """
          Net structure described in crnn paper
          feature_maps = [32, 32, 64, 64, 128, 128, 256, 256, 512, 512, 512]
          """
          with tf.variable_scope(self._scope, self._scope, [inputs]) as sc:
              end_points_collection = sc.name + '_end_points'
  
              with slim.arg_scope([slim.conv2d, slim.max_pool2d, slim.batch_norm],
                                  outputs_collections=end_points_collection):
                  net = slim.conv2d(inputs, 32, 3, 1, scope='conv1')
                  net = slim.conv2d(net, 32, 3, 1, scope='conv2')
  
                  net = slim.conv2d(net, 64, 3, 1, scope='conv3')
                  net = slim.conv2d(net, 64, 3, 1, scope='conv4')
  
                  net = slim.max_pool2d(net, 2, 2, scope='pool1')
  
                  net = slim.conv2d(net, 128, 3, 1, scope='conv5')
                  net = slim.conv2d(net, 128, 3, 1, scope='conv6')
  
                  net = slim.max_pool2d(net, 2, 2, scope='pool2')
  
                  net = slim.conv2d(net, 256, 3, scope='conv7')
                  net = slim.conv2d(net, 256, 3, scope='conv8')
  
                  net = slim.max_pool2d(net, 2, [2, 1], scope='pool3')
  
                  net = slim.conv2d(net, 512, 3, scope='conv9')
                  net = slim.conv2d(net, 512, 3, scope='conv10')
  
                  net = slim.max_pool2d(net, 2, [1, 1], scope='pool4')
  
                  net = slim.conv2d(net, 512, 2, padding='VALID', scope='conv11')
  
                  net = slim.dropout(net, keep_prob=0.5)
  
              self.end_points = utils.convert_collection_to_dict(end_points_collection)
              self.net = net
  
      def _arg_scope(self, is_training):
          batch_norm_params = {
              'is_training': is_training,
              # Decay for the moving averages.
              'decay': 0.995,
              # epsilon to prevent 0s in variance.
              'epsilon': 0.00001
          }
  
          with slim.arg_scope([slim.conv2d],
                              normalizer_fn=slim.batch_norm,
                              normalizer_params=batch_norm_params):
              with slim.arg_scope([slim.dropout], is_training=is_training) as sc:
                  return sc
  
  
  if __name__ == '__main__':
      import sys
  
      sys.path.insert(0, '../../libs')
      from tf_utils import print_endpoints
  
      inputs = tf.placeholder(tf.float32, [1, 37, 315, 1], name="inputs")
      is_training = tf.placeholder(tf.bool, name="is_training")
      img_file = '/Users/cwq/data/test.jpg'
  
      net = DeepCNN(inputs, is_training)
      print_endpoints(net, inputs, is_training, img_file)
  