From 245d64c60d0ea30f5080ff53225b5169927e24d6 Mon Sep 17 00:00:00 2001 From: Matthew Bentham Date: Mon, 2 Dec 2019 12:59:43 +0000 Subject: Work in progress of python bindings for Arm NN Not built or tested in any way Signed-off-by: Matthew Bentham Change-Id: Ie7f92b529aa5087130f0c5cc8c17db1581373236 --- .../pyarmnn/src/pyarmnn/swig/armnn_caffeparser.i | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 python/pyarmnn/src/pyarmnn/swig/armnn_caffeparser.i (limited to 'python/pyarmnn/src/pyarmnn/swig/armnn_caffeparser.i') diff --git a/python/pyarmnn/src/pyarmnn/swig/armnn_caffeparser.i b/python/pyarmnn/src/pyarmnn/swig/armnn_caffeparser.i new file mode 100644 index 0000000000..fa1a71fd9f --- /dev/null +++ b/python/pyarmnn/src/pyarmnn/swig/armnn_caffeparser.i @@ -0,0 +1,103 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// +%module pyarmnn_caffeparser +%{ +#define SWIG_FILE_WITH_INIT +#include "armnnCaffeParser/ICaffeParser.hpp" +#include "armnn/INetwork.hpp" +%} + +//typemap definitions and other common stuff +%include "standard_header.i" + +namespace std { + %template(BindingPointInfo) pair; + %template(MapStringTensorShape) map; + %template(StringVector) vector; +} + +namespace armnnCaffeParser +{ + +%feature("docstring", +" +Interface for creating a parser object using Caffe (http://caffe.berkeleyvision.org/) caffemodel files. + +Parsers are used to automatically construct Arm NN graphs from model files. + +") ICaffeParser; + +%nodefaultctor ICaffeParser; +class ICaffeParser +{ +public: + // Documentation + %feature("docstring", + " + Retrieve binding info (layer id and tensor info) for the network input identified by the given layer name. + + Args: + name (str): Name of the input. + + Returns: + tuple: (`int`, `TensorInfo`) + ") GetNetworkInputBindingInfo; + + %feature("docstring", + " + Retrieve binding info (layer id and tensor info) for the network output identified by the given layer name. + + Args: + name (str): Name of the output. + + Returns: + tuple: (`int`, `TensorInfo`) + ") GetNetworkOutputBindingInfo; + + std::pair GetNetworkInputBindingInfo(const std::string& name); + std::pair GetNetworkOutputBindingInfo(const std::string& name); +}; + +%extend ICaffeParser { + // This is not a substitution of the default constructor of the Armnn class. It tells swig to create custom __init__ + // method for ICaffeParser python object that will use static factory method to do the job. + + ICaffeParser() { + return armnnCaffeParser::ICaffeParser::CreateRaw(); + } + + // The following does not replace a real destructor of the Armnn class. + // It creates a functions that will be called when swig object goes out of the scope to clean resources. + // so the user doesn't need to call ICaffeParser::Destroy himself. + // $self` is a pointer to extracted ArmNN ICaffeParser object. + + ~ICaffeParser() { + armnnCaffeParser::ICaffeParser::Destroy($self); + } + + %feature("docstring", + " + Create the network from a Caffe caffemodel binary file on disk. + + Args: + graphFile: Path to the caffe model to be parsed. + inputShapes (tuple): (`string`, `TensorShape`) A tuple containing the input name and TensorShape information for the network. + requestedOutputs (list): A list of the output tensor names. + + Returns: + INetwork: INetwork object for the parsed Caffe model. + ") CreateNetworkFromBinaryFile; + + %newobject CreateNetworkFromBinaryFile; + armnn::INetwork* CreateNetworkFromBinaryFile(const char* graphFile, + const std::map& inputShapes, + const std::vector& requestedOutputs) { + return $self->CreateNetworkFromBinaryFile(graphFile, inputShapes, requestedOutputs).release(); + } +} +} + +// Clear exception typemap. +%exception; -- cgit v1.2.1