def create_sample_graph(data1: np.ndarray, data2: np.ndarray) -> Graph: graph = Graph() # input x = Input('placeholder', [1, 5, 5, 3], Float32()) # Conv1 w1 = Constant('weight1', Float32(), data1) conv1 = Conv('conv1', [1, 4, 4, 3], Float32(), {'X': x, 'W': w1}, kernel_shape=[2, 2]) # activation quantizer s1 = Constant('aq_const1', Int32(), np.array([2], dtype=np.int32)) s2 = Constant('aq_const2', Float32(), np.array([2.0], dtype=np.float32)) aq1 = QTZ_linear_mid_tread_half('aqtz1', [1, 4, 4, 3], Float32(), {'X': conv1, 'Y': s1, 'Z': s2}) # Conv2 w2 = Constant('weight2', Float32(), data2) kq = QTZ_binary_mean_scaling('kqtz1', [1, 2, 2, 3], Float32(), {'input': w2}) conv2 = Conv('conv2', [1, 3, 3, 3], Float32(), {'X': aq1, 'W': kq}, kernel_shape=[2, 2]) conv2.a_quantizer = [aq1] conv2.quantizer = kq conv2.is_quantized = True sc = Constant('bn_scale', Float32(), np.random.rand(3)) be = Constant('bn_b', Float32(), np.random.rand(3)) mu = Constant('bn_mu', Float32(), np.random.rand(3)) va = Constant('bn_var', Float32(), np.random.rand(3)) bn = BatchNormalization('bn', [1, 3, 3, 3], Float32(), {'X': conv2, 'scale': sc, 'B': be, 'mean': mu, 'var': va}) # activation quantizer s3 = Constant('aq_const3', Int32(), np.array([2], dtype=np.int32)) s4 = Constant('aq_const4', Float32(), np.array([2.0], dtype=np.float32)) aq2 = QTZ_linear_mid_tread_half('aqtz2', [1, 3, 3, 3], Float32(), {'X': bn, 'Y': s3, 'Z': s4}) # One output y = Output('output', [1, 3, 3, 3], Float32(), {'input': aq2}) # add ops to the graph graph.add_op_and_inputs(y) return graph
from core.data_types import DataType, Float32, Float64, Int8, Int16, Int32, \ Int64, Uint8, Uint16, Uint32, Uint64, Bool, String from core.exceptions import UnsupportedNode, UnsupportedDataType from core.graph import Graph from core.operators import Operator, Conv, Identity, QTZ_binary_mean_scaling, \ BatchNormalization, QTZ_linear_mid_tread_half, Add, \ MaxPool, AveragePool, Reshape, Softmax, Transpose, Relu, SpaceToDepth, \ Mul, QTZ_binary_channel_wise_mean_scaling, ConcatOnDepth, Maximum, DepthToSpace, ResizeNearestNeighbor, \ Split, Pad, MatMul, Gather, Unique, Cast, Minimum, StridedSlice, Prod, Shape, LeakyRelu DLK_DTYPE_MAP: Dict[str, Optional[DataType]] = { # any 'DT_INVALID': Float32, # primitives 'DT_FLOAT': Float32(), 'DT_INT32': Int32(), 'DT_UINT8': Uint8(), 'DT_INT8': Int8(), 'DT_UINT16': Uint16(), 'DT_INT16': Int16(), 'DT_INT64': Int64(), 'f': Float32(), 'i': Int32(), # primitive vector 'FLOATS': None, 'INTS': None, # custom 'DT_BOOL': Bool(), 'DT_STRING': String(),
Int64, Uint8, Uint16, Uint32, Uint64, Bool, String from core.exceptions import UnsupportedNode, UnsupportedDataType from core.operators import Operator, Conv, Identity, QTZ_binary_mean_scaling, \ BatchNormalization, QTZ_linear_mid_tread_half, Add, \ Pool, MaxPool, AveragePool, Reshape, Softmax, Transpose import core.operators as dlk_op import numpy as np import importlib import functools DLK_DTYPE_MAP: Dict[str, Optional[DataType]] = { # any 'UNDEFINED': None, # primitives 'FLOAT': Float32(), 'INT': Int32(), 'UINT8': Uint8(), 'INT8': Int8(), 'UINT16': Uint16(), 'INT16': Int16(), 'INT32': Int32(), 'INT64': Int64(), 'f': Float32(), 'i': Int32(), # primitive vector 'FLOATS': None, 'INTS': None, # custom 'BOOL': Bool(),