qkeras.qtools.qgraph

Creates networkx graph from a model.

Functions

AddToNodeDict(layer_items, layer, nodes_dict)

Adds layer to a node_dict, indexed by layer.(input or output).ref

CreateGraph(model[, input_quantizers, ...])

create graph.

GenerateGraphFromModel(model, ...)

Generates single source, single sink graph from model.

GenerateInputQuantizerList(input_quantizers, ...)

Generates the list of input quantizers.

GraphAddHiddenInputLayer(model, graph, ...)

For Keras Sequential model api, input layer is hidden.

GraphAddSingleSourceSingleSink(graph)

Connects graph to source and sink nodes.

GraphGetInputs(graph)

Returns edges SOURCE->u that are inputs.

GraphGetOutputs(graph)

Returns edges u->SINK that are outputs.

GraphPropagateActivationsToEdges(graph[, debug])

Traverses graph and move activations to edges.

GraphRemoveNode(graph, v)

Removes node "v" from u -> v -> w, connecting u -> w.

GraphRemoveNodeWithNodeType(graph, node_type)

Removes node with attribute node_type, reconnecting network.

GraphUpdateEdge(graph, node_id, ...)

update the graph edges outgoing from node_id with new quantizer.

PrintGraph(graph[, msg])

Print graph structure.

Exceptions

WrongInputQuantizerError

qkeras.qtools.qgraph.AddToNodeDict(layer_items, layer, nodes_dict)[source]

Adds layer to a node_dict, indexed by layer.(input or output).ref

qkeras.qtools.qgraph.CreateGraph(model, input_quantizers=None, default_source_quantizer='quantized_bits(8, 0, 1)', debug=False)[source]

create graph.

qkeras.qtools.qgraph.GenerateGraphFromModel(model, input_quantizers, default_source_quantizer)[source]

Generates single source, single sink graph from model.

qkeras.qtools.qgraph.GenerateInputQuantizerList(input_quantizers, inputs_length, default_source_quantizer)[source]

Generates the list of input quantizers.

qkeras.qtools.qgraph.GraphAddHiddenInputLayer(model, graph, input_quantizer_map)[source]

For Keras Sequential model api, input layer is hidden. Need to add it.

qkeras.qtools.qgraph.GraphAddSingleSourceSingleSink(graph)[source]

Connects graph to source and sink nodes.

qkeras.qtools.qgraph.GraphGetInputs(graph)[source]

Returns edges SOURCE->u that are inputs.

qkeras.qtools.qgraph.GraphGetOutputs(graph)[source]

Returns edges u->SINK that are outputs.

qkeras.qtools.qgraph.GraphPropagateActivationsToEdges(graph, debug=False)[source]

Traverses graph and move activations to edges.

1.If current dense/conv layer is specified with QA:

outgoing edge (output data type) will be QA type

2.If current dense/conv layer has no QA:

default type (float32) is used as output

3.If current layer is QA layer:

float32 is used by default as output type on the edge

Parameters:
  • graph – graph to inject activations to.

  • debug – debug mode

Returns:

None

qkeras.qtools.qgraph.GraphRemoveNode(graph, v)[source]

Removes node “v” from u -> v -> w, connecting u -> w.

qkeras.qtools.qgraph.GraphRemoveNodeWithNodeType(graph, node_type)[source]

Removes node with attribute node_type, reconnecting network.

qkeras.qtools.qgraph.GraphUpdateEdge(graph, node_id, quantizer_on_edge)[source]

update the graph edges outgoing from node_id with new quantizer.

qkeras.qtools.qgraph.PrintGraph(graph, msg='')[source]

Print graph structure.

exception qkeras.qtools.qgraph.WrongInputQuantizerError[source]

Bases: ValueError