def add_flatten_to_2d(self, name, input_name, output_name, axis=1):
        """
        Add a flatten_to_2d layer to the model that flattens the input tensor
        into a 2-dimensional matrix.
        Refer to the ``FlattenTo2DLayerParams`` message in the specification
        (NeuralNetwork.proto) for more details.

        Parameters
        ----------
        name: str
            The name of this layer.
        input_name: str
            The of input blob name of this layer.
        output_name: str
            The output blob name of this layer.
        axis: int, optional
            Axis to perform the operation, default: 1.

        See Also
        --------
        add_flatten
        """

        spec_layer = self._add_generic_layer(name, [input_name], [output_name])
        spec_layer_params = spec_layer.flattenTo2D
        spec_layer_params.axis = axis
        self.rank_dict[output_name] = 2
        return spec_layer

        Add a flatten_to_2d layer to the model that flattens the input tensor
        into a 2-dimensional matrix.
        Refer to the ``FlattenTo2DLayerParams`` message in the specification
        (NeuralNetwork.proto) for more details.

        Parameters
        ----------
        name: str
            The name of this layer.
        input_name: str
            The of input blob name of this layer.
        output_name: str
            The output blob name of this layer.
        axis: int, optional
            Axis to perform the operation, default: 1.

        See Also
        --------
        add_flatten
        
coremltools/models/neural_network/builder.py