Beispiel #1
0
def optimize_graph_step(model: Model, config: Config) -> None:
    """Optimize graph in the model.

    Parameters
    ----------
    model : Model
        Model that contains the graph

    config : Config
        Collection of configurations

    """
    graph: Graph = model.graph
    pass_remove_identities(graph)
    pass_transpose(graph)

    if config.activate_hard_quantization:
        pass_lookup(graph)
        pass_propagate_quantization_details_into_conv(graph)
        if config.threshold_skipping:
            pass_compute_thresholds(graph)
        pass_pack_weights(graph)
        pass_quantize_convolutions(graph)
        pass_fix_qtz_types_and_format(graph)

    pass_propagate_output_type_backward(graph)
    pass_propagate_datatypes(graph)
    pass_propagate_format(graph)

    pass_constant_folding(graph)
Beispiel #2
0
def optimize_graph_step(graph: Graph, config: Config) -> None:
    """Optimizing graph that imported from tensorflow pb.

    Args:
        graph (Graph): Graph that optimization passes are applying to
        config (Config): Collection of configurations

    Returns:

    
    """

    pass_remove_identities(graph)
    pass_transpose(graph)

    if config.activate_hard_quantization:
        pass_lookup(graph)
        pass_propagate_quantization_details_into_conv(graph)
        if config.threshold_skipping:
            pass_compute_thresholds(graph)
        pass_pack_weights(graph)
        pass_quantize_convolutions(graph)

    if config.threshold_skipping:
        pass_propagate_output_type_backward(graph)
    pass_propagate_datatypes(graph)
    pass_propagate_format(graph)

    pass_constant_folding(graph)
    pass_simplify_batchnorm(graph)
Beispiel #3
0
    def test_pass_transpose(self) -> None:
        """Test code for transposing optimizer pass."""
        data = np.random.rand(3, 2, 2, 1)
        graph1 = self.create_sample_graph(data)
        graph2 = self.create_expected_graph(data)

        pass_transpose(graph1)

        self.assertEqual(graph1, graph2, 'transpose to NHWC failed.')

        print("Test pass #1 transpose passed!")