aboutsummaryrefslogtreecommitdiff
path: root/src/armnnCaffeParser/CaffeParser.hpp
diff options
context:
space:
mode:
authortelsoa01 <telmo.soares@arm.com>2018-08-31 09:22:23 +0100
committertelsoa01 <telmo.soares@arm.com>2018-08-31 09:22:23 +0100
commitc577f2c6a3b4ddb6ba87a882723c53a248afbeba (patch)
treebd7d4c148df27f8be6649d313efb24f536b7cf34 /src/armnnCaffeParser/CaffeParser.hpp
parent4c7098bfeab1ffe1cdc77f6c15548d3e73274746 (diff)
downloadarmnn-c577f2c6a3b4ddb6ba87a882723c53a248afbeba.tar.gz
Release 18.08
Diffstat (limited to 'src/armnnCaffeParser/CaffeParser.hpp')
-rw-r--r--src/armnnCaffeParser/CaffeParser.hpp141
1 files changed, 87 insertions, 54 deletions
diff --git a/src/armnnCaffeParser/CaffeParser.hpp b/src/armnnCaffeParser/CaffeParser.hpp
index 0b31e187dd..51867b6ace 100644
--- a/src/armnnCaffeParser/CaffeParser.hpp
+++ b/src/armnnCaffeParser/CaffeParser.hpp
@@ -25,60 +25,34 @@ namespace armnnCaffeParser
using BindingPointInfo = std::pair<armnn::LayerBindingId, armnn::TensorInfo>;
-class CaffeParser : public ICaffeParser
+class CaffeParserBase: public ICaffeParser
{
public:
+
+ // Because we haven't looked at reducing the memory usage when loading from Text/String
+ // have to retain these functions here for the moment.
/// Create the network from a protobuf text file on disk
virtual armnn::INetworkPtr CreateNetworkFromTextFile(
const char* graphFile,
const std::map<std::string, armnn::TensorShape>& inputShapes,
const std::vector<std::string>& requestedOutputs) override;
- /// Create the network from a protobuf binary file on disk
- virtual armnn::INetworkPtr CreateNetworkFromBinaryFile(
- const char* graphFile,
- const std::map<std::string, armnn::TensorShape>& inputShapes,
- const std::vector<std::string>& requestedOutputs) override;
- /// Create the network directly from protobuf text in a string. Useful for debugging/testing
+ /// Creates the network directly from protobuf text in a string. Useful for debugging/testing.
virtual armnn::INetworkPtr CreateNetworkFromString(
const char* protoText,
const std::map<std::string, armnn::TensorShape>& inputShapes,
const std::vector<std::string>& requestedOutputs) override;
- /// Retrieve binding info (layer id and tensor info) for the network input identified by the given layer name
+ /// Retrieves binding info (layer id and tensor info) for the network input identified by the given layer name.
virtual BindingPointInfo GetNetworkInputBindingInfo(const std::string& name) const override;
- /// Retrieve binding info (layer id and tensor info) for the network output identified by the given layer name
+ /// Retrieves binding info (layer id and tensor info) for the network output identified by the given layer name.
virtual BindingPointInfo GetNetworkOutputBindingInfo(const std::string& name) const override;
-public:
- CaffeParser();
-
-private:
- static std::pair<armnn::LayerBindingId, armnn::TensorInfo> GetBindingInfo(const std::string& layerName,
- const char* bindingPointDesc,
- const std::unordered_map<std::string, BindingPointInfo>& bindingInfos);
-
- /// Parses a NetParameter loaded into memory from one of the other CreateNetwork*
- armnn::INetworkPtr CreateNetworkFromNetParameter(
- caffe::NetParameter& netParam,
- const std::map<std::string, armnn::TensorShape>& inputShapes,
- const std::vector<std::string>& requestedOutputs);
-
- /// does the actual conversion from caffe::NetParameter to armnn::INetwork
- void LoadNetParam(caffe::NetParameter& netParameter);
-
- /// Find the Caffe layers listed as inputs (bottoms) for a given layer.
- std::vector<const caffe::LayerParameter*> GetInputs(const caffe::LayerParameter& layerParam);
-
- /// Modifies the Caffe network to replace "in-place" layers (whose top() and bottom() are both the same)
- /// with regular layers. This simplifies further parsing.
- void ResolveInPlaceLayers(caffe::NetParameter& netParameter);
-
- /// Converts Caffe's protobuf tensor shape format to ArmNN's
- armnn::TensorInfo BlobShapeToTensorInfo(const caffe::BlobShape& blobShape) const;
+ CaffeParserBase();
+protected:
/// Adds an armnn layer to m_Network given a Caffe LayerParameter of the correct type
/// and is responsible for recording any newly created IOutputSlots using SetArmnnOutputSlotForCaffeTop().
/// @{
@@ -97,46 +71,105 @@ private:
void ParseDropoutLayer(const caffe::LayerParameter& layerParam);
/// @}
+ /// ParseConv may use these helpers depending on the group parameter
+ /// @{
+ void AddConvLayerWithSplits(const caffe::LayerParameter& layerParam,
+ const armnn::Convolution2dDescriptor & desc,
+ unsigned int kernelW,
+ unsigned int kernelH);
+ void AddConvLayerWithDepthwiseConv(const caffe::LayerParameter& layerParam,
+ const armnn::Convolution2dDescriptor & desc,
+ unsigned int kernelW,
+ unsigned int kernelH);
+ /// @}
+
+ /// Converts Caffe's protobuf tensor shape format to ArmNN's
+ armnn::TensorInfo BlobShapeToTensorInfo(const caffe::BlobShape& blobShape) const;
+
void TrackInputBinding(armnn::IConnectableLayer* layer,
- armnn::LayerBindingId id,
- const armnn::TensorInfo& tensorInfo);
+ armnn::LayerBindingId id,
+ const armnn::TensorInfo& tensorInfo);
+
+ static void TrackBindingPoint(armnn::IConnectableLayer* layer, armnn::LayerBindingId id,
+ const armnn::TensorInfo& tensorInfo,
+ const char* bindingPointDesc,
+ std::unordered_map<std::string, BindingPointInfo>& nameToBindingInfo);
void TrackOutputBinding(armnn::IConnectableLayer* layer,
- armnn::LayerBindingId id,
- const armnn::TensorInfo& tensorInfo);
+ armnn::LayerBindingId id,
+ const armnn::TensorInfo& tensorInfo);
- static void TrackBindingPoint(armnn::IConnectableLayer* layer, armnn::LayerBindingId id,
- const armnn::TensorInfo& tensorInfo,
- const char* bindingPointDesc,
- std::unordered_map<std::string, BindingPointInfo>& nameToBindingInfo);
+
+ void SetArmnnOutputSlotForCaffeTop(const std::string& caffeTopName, armnn::IOutputSlot& armnnOutputSlot);
/// Retrieves the Armnn IOutputSlot representing the given Caffe top.
/// Throws if it cannot be found (e.g. not parsed yet).
armnn::IOutputSlot& GetArmnnOutputSlotForCaffeTop(const std::string& caffeTopName) const;
- void SetArmnnOutputSlotForCaffeTop(const std::string& caffeTopName, armnn::IOutputSlot& armnnOutputSlot);
+ static std::pair<armnn::LayerBindingId, armnn::TensorInfo> GetBindingInfo(
+ const std::string& layerName,
+ const char* bindingPointDesc,
+ const std::unordered_map<std::string, BindingPointInfo>& bindingInfos);
+
void Cleanup();
- armnn::INetworkPtr m_Network;
+ using OperationParsingFunction = void(CaffeParserBase::*)(const caffe::LayerParameter& layerParam);
- std::map<std::string, const caffe::LayerParameter*> m_CaffeLayersByTopName;
+ /// Maps Caffe layer names to parsing member functions.
+ static const std::map<std::string, OperationParsingFunction> ms_CaffeLayerNameToParsingFunctions;
- using OperationParsingFunction = void(CaffeParser::*)(const caffe::LayerParameter& layerParam);
+ /// maps input layer names to their corresponding ids and tensor infos
+ std::unordered_map<std::string, BindingPointInfo> m_NetworkInputsBindingInfo;
- /// map of Caffe layer names to parsing member functions
- static const std::map<std::string, OperationParsingFunction> ms_CaffeLayerNameToParsingFunctions;
+ /// maps output layer names to their corresponding ids and tensor infos
+ std::unordered_map<std::string, BindingPointInfo> m_NetworkOutputsBindingInfo;
+
+ armnn::INetworkPtr m_Network;
std::map<std::string, armnn::TensorShape> m_InputShapes;
- std::vector<std::string> m_RequestedOutputs;
/// As we add armnn layers we store the armnn IOutputSlot which corresponds to the Caffe tops.
std::unordered_map<std::string, armnn::IOutputSlot*> m_ArmnnOutputSlotForCaffeTop;
- /// maps input layer names to their corresponding ids and tensor infos
- std::unordered_map<std::string, BindingPointInfo> m_NetworkInputsBindingInfo;
+ std::vector<std::string> m_RequestedOutputs;
+
+
+ // Stuff which has gone to base class simply because we haven't done any
+ // memory optimisation on the text/string format. If we move this to a layer
+ // by layer parse as well these can move to the CaffeParser class.
+ std::map<std::string, const caffe::LayerParameter*> m_CaffeLayersByTopName;
+
+ /// Parses a NetParameter loaded into memory from one of the other CreateNetwork*
+ armnn::INetworkPtr CreateNetworkFromNetParameter(
+ caffe::NetParameter& netParam,
+ const std::map<std::string, armnn::TensorShape>& inputShapes,
+ const std::vector<std::string>& requestedOutputs);
+
+ /// does the actual conversion from caffe::NetParameter to armnn::INetwork
+ void LoadNetParam(caffe::NetParameter& netParameter);
+
+ /// Find the Caffe layers listed as inputs (bottoms) for a given layer.
+ std::vector<const caffe::LayerParameter*> GetInputs(const caffe::LayerParameter& layerParam);
+
+ /// Modifies the Caffe network to replace "in-place" layers (whose top() and bottom() are both the same)
+ /// with regular layers. This simplifies further parsing.
+ void ResolveInPlaceLayers(caffe::NetParameter& netParameter);
+
+};
+
+class CaffeParser : public CaffeParserBase
+{
+public:
+
+ /// Create the network from a protobuf binary file on disk
+ virtual armnn::INetworkPtr CreateNetworkFromBinaryFile(
+ const char* graphFile,
+ const std::map<std::string, armnn::TensorShape>& inputShapes,
+ const std::vector<std::string>& requestedOutputs) override;
+
+public:
+ CaffeParser();
- /// maps output layer names to their corresponding ids and tensor infos
- std::unordered_map<std::string, BindingPointInfo> m_NetworkOutputsBindingInfo;
};
} \ No newline at end of file