Beispiel #1
0
    def parse(self):
        logger.debug("Parsing %s...", self.type)

        op = self.tflite
        opcode = self.model.OperatorCodes(op.OpcodeIndex()).BuiltinCode()
        assert (opcode in self.TypeMapping)

        assert (op.InputsLength() == 2)
        assert (op.OutputsLength() == 1)

        self.parseInput(0)
        self.parseInput(1)
        ot = self.parseOutput(0)

        self.fakeBroadcast()

        # options
        op_opt = op.BuiltinOptions()
        if opcode in self.OptionMapping:
            option = self.OptionMapping[opcode]()
            option.Init(op_opt.Bytes, op_opt.Pos)

            handleFusedActivation(self, option, ot)

        self.setParsed()
    def parse(self):
        logger.debug("Parsing %s...", self.type)
        op = self.tflite
        opcode = self.model.OperatorCodes(op.OpcodeIndex()).BuiltinCode()
        assert (opcode is tflite.BuiltinOperator.FULLY_CONNECTED)

        assert (
            op.InputsLength() == 3), "TFLite Fullly Connected always has bias"
        assert (op.OutputsLength() == 1)

        # input
        self.parseInput(0)

        # weight
        self.parseInput(1)

        # bias
        self.parseInput(2, is_bias=True)

        # output
        ot = self.parseOutput(0)

        # options
        op_opt = op.BuiltinOptions()
        option = tflite.FullyConnectedOptions()
        option.Init(op_opt.Bytes, op_opt.Pos)

        assert (not option.KeepNumDims())
        assert (option.WeightsFormat() is
                tflite.FullyConnectedOptionsWeightsFormat.DEFAULT)

        handleFusedActivation(self, option, ot)

        self.setParsed()
Beispiel #3
0
    def parse(self):
        logger.debug("Parsing %s...", self.type)
        op = self.tflite
        opcode = self.model.OperatorCodes(op.OpcodeIndex()).BuiltinCode()
        assert (opcode in self.TypeMapping)

        assert (op.InputsLength() == 1)
        assert (op.OutputsLength() == 1)

        ilayout = Layout('NHWC', 'NCHW')
        self.parseInput(0, ilayout)

        op_opt = op.BuiltinOptions()
        option = tflite.Pool2DOptions()
        option.Init(op_opt.Bytes, op_opt.Pos)
        self.attrs['auto_pad'] = PaddingMapping[option.Padding()]
        self.attrs['kernel_shape'] = [
            option.FilterHeight(), option.FilterWidth()
        ]
        self.attrs['strides'] = [option.StrideH(), option.StrideW()]

        olayout = Layout('NHWC', 'NCHW')
        ot = self.parseOutput(0, olayout)

        handleFusedActivation(self, option, ot)

        self.setParsed()
Beispiel #4
0
    def parse(self):
        logger.debug("Parsing %s...", self.type)
        op = self.tflite
        opcode = self.model.OperatorCodes(op.OpcodeIndex()).BuiltinCode()
        assert (opcode in self.TypeMapping)

        assert (op.InputsLength() == 3), "TFLite Conv always has bias"
        assert (op.OutputsLength() == 1)

        # input
        ilayout = Layout('NHWC', 'NCHW')
        it = self.parseInput(0, ilayout)

        # weight
        wlayout = Layout('CHWM', 'MCHW') if self.isDepthwise else Layout(
            'OHWI', 'OIHW')
        wt = self.parseInput(1, wlayout)

        # bias
        self.parseInput(2, is_bias=True)

        # output
        olayout = Layout('NHWC', 'NCHW')
        ot = self.parseOutput(0, olayout)

        # options
        op_opt = op.BuiltinOptions()
        option = tflite.DepthwiseConv2DOptions(
        ) if self.isDepthwise else tflite.Conv2DOptions()
        option.Init(op_opt.Bytes, op_opt.Pos)

        self.attrs['dilations'] = [
            option.DilationHFactor(),
            option.DilationWFactor()
        ]
        self.attrs['group'] = wt.shape[3] if self.isDepthwise else 1
        self.attrs['kernel_shape'] = wt.shape[1:3]
        self.attrs['strides'] = [option.StrideH(), option.StrideW()]
        # XXX Not enabled as ONNXRuntime has limitation to infer pads for non-1 dilation
        # self.attrs['auto_pad'] = PaddingMapping[option.Padding()]
        if self.isDepthwise:
            assert (option.DepthMultiplier() == 1)
        self.attrs['pads'] = computePaddingSize(option.Padding(),
                                                it.shape[1:3],
                                                self.attrs['kernel_shape'],
                                                self.attrs['strides'],
                                                self.attrs['dilations'])

        handleFusedActivation(self, option, ot)

        self.setParsed()
Beispiel #5
0
    def parse(self):
        logger.debug("Parsing %s...", self.shorty)
        op = self.tflite
        opcode = self.model.OperatorCodes(op.OpcodeIndex()).BuiltinCode()
        assert(opcode is tflite.BuiltinOperator.CONCATENATION)

        assert(op.InputsLength() >= 1)
        assert(op.OutputsLength() == 1)

        for i in range(op.InputsLength()):
            self.parseInput(i)

        op_opt = op.BuiltinOptions()
        option = tflite.ConcatenationOptions()
        option.Init(op_opt.Bytes, op_opt.Pos)
        self.attrs['axis'] = option.Axis()

        self.parseOutput(0)

        handleFusedActivation(self, option, self.outputs[0])

        self.setParsed()