1# model 2model = Model() 3sparseData = Input("sparseData", "TENSOR_FLOAT32", "{5}") 4traversalOrder = Parameter("traversalOrder", "TENSOR_INT32", "{3}", [0, 1, 2]) 5blockMap = Parameter("blockMap", "TENSOR_INT32", "{0}", []) 6dimFormat = Parameter("dimFormat", "TENSOR_INT32", "{3}", [1, 0, 1]) 7dimensions = Parameter("dimensions", "TENSOR_INT32", "{3}", [3, 2, 2]) 8d0ArrSegments = Parameter("d0ArrSegments", "TENSOR_INT32", "{2}", [0, 2]) 9d0ArrIndices = Parameter("d0ArrIndices", "TENSOR_INT32", "{2}", [0, 2]) 10d1ArrSegments = Parameter("d1ArrSegments", "TENSOR_INT32", "{0}", []) 11d1ArrIndices = Parameter("d1ArrIndices", "TENSOR_INT32", "{0}", []) 12d2ArrSegments = Parameter("d2ArrSegments", "TENSOR_INT32", "{5}", [0, 1, 3, 4, 5]) 13d2ArrIndices = Parameter("d2ArrIndices", "TENSOR_INT32", "{5}", [0, 0, 1, 0, 1]) 14denseOut = Output("denseOut", "TENSOR_FLOAT32", "{3, 2, 2}") 15model = model.Operation("DENSIFY", sparseData, traversalOrder, blockMap, dimFormat, 16 dimensions, d0ArrSegments, d0ArrIndices, d1ArrSegments, 17 d1ArrIndices, d2ArrSegments, d2ArrIndices).To(denseOut) 18 19# Example 1. Input in operand 0, 20input0 = {sparseData: # input 0 21 [6.0, 9.0, 8.0, 5.0, 7.0]} 22 23output0 = {denseOut: # output 0 24 [6.0, 0.0, 9.0, 8.0, 0.0, 0.0, 0.0, 0.0, 5.0, 0.0, 0.0, 7.0]} 25 26quant8_symm = DataTypeConverter().Identify({ 27 sparseData: ("TENSOR_QUANT8_SYMM", 4.375), 28 denseOut: ("TENSOR_QUANT8_SYMM", 4.375) 29}) 30 31quant8_asymm = DataTypeConverter().Identify({ 32 sparseData: ("TENSOR_QUANT8_ASYMM", 3.5, 5), 33 denseOut: ("TENSOR_QUANT8_ASYMM", 3.5, 5) 34}) 35 36quant8_asymm_signed = DataTypeConverter().Identify({ 37 sparseData: ("TENSOR_QUANT8_ASYMM_SIGNED", 2.0, -3), 38 denseOut: ("TENSOR_QUANT8_ASYMM_SIGNED", 2.0, -3) 39}) 40 41quant16_symm = DataTypeConverter().Identify({ 42 sparseData: ("TENSOR_QUANT16_SYMM", 3.25), 43 denseOut: ("TENSOR_QUANT16_SYMM", 3.25) 44}) 45 46quant16_asymm = DataTypeConverter().Identify({ 47 sparseData: ("TENSOR_QUANT16_ASYMM", 1.625, 10), 48 denseOut: ("TENSOR_QUANT16_ASYMM", 1.625, 10) 49}) 50 51# Instantiate an example 52Example((input0, output0)).AddVariations("relaxed", "float16", "int32", quant8_symm, 53 quant8_asymm, quant8_asymm_signed, quant16_symm, 54 quant16_asymm) 55