'Build the graph corresponding to the progressive BRNN model.'

def BuildGraph(self, input_codes):

    layer_depth = self._config['layer_depth']
    layer_count = self._config['layer_count']
    code_shape = input_codes.get_shape()
    code_depth = code_shape[(-1)].value
    if (self._config['coded_layer_count'] > 0):
        prefix_depth = (self._config['coded_layer_count'] * layer_depth)
        if (code_depth < prefix_depth):
            raise ValueError('Invalid    prefix    depth:    {}    VS    {}'.format(prefix_depth, code_depth))
        input_codes = input_codes[:, :, :, :prefix_depth]
    code_shape = input_codes.get_shape()
    code_depth = code_shape[(-1)].value
    if ((code_depth % layer_depth) != 0):
        raise ValueError('Code    depth    must    be    a    multiple    of    the    layer    depth:    {}    vs    {}'.format(code_depth, layer_depth))
    code_layer_count = (code_depth // layer_depth)
    if (code_layer_count > layer_count):
        raise ValueError('Input    codes    have    too    many    layers:    {},    max={}'.format(code_layer_count, layer_count))
    layer_prediction = LayerPrediction(layer_count, layer_depth)
    code_length_block = blocks.CodeLength()
    code_length = []
    code_layers = tf.split(value=input_codes, num_or_size_splits=code_layer_count, axis=3)
    for k in xrange(code_layer_count):
        x = code_layers[k]
        predicted_x = layer_prediction(x)
        epsilon = 0.001
        predicted_x = tf.clip_by_value(predicted_x, ((-1) + epsilon), ((+ 1) - epsilon))
        code_length.append(code_length_block(blocks.ConvertSignCodeToZeroOneCode(x), blocks.ConvertSignCodeToZeroOneCode(predicted_x)))
        tf.summary.scalar('code_length_layer_{:02d}'.format(k), code_length[(-1)])
    code_length = tf.stack(code_length)
    self.loss = tf.reduce_mean(code_length)
    tf.summary.scalar('loss', self.loss)
    dummy_x = tf.zeros_like(code_layers[0])
    for _ in xrange((layer_count - code_layer_count)):
        dummy_predicted_x = layer_prediction(dummy_x)
    self.average_code_length = tf.reduce_mean(code_length)
    if self._optimizer:
        optim_op = self._optimizer.minimize(self.loss, global_step=self._global_step)
        block_updates = blocks.CreateBlockUpdates()
        if block_updates:
            with tf.get_default_graph().control_dependencies([optim_op]):
                self.train_op = tf.group(*block_updates)
        else:
            self.train_op = optim_op
    else:
        self.train_op = None
