aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorNikhil Raj <nikhil.raj@arm.com>2021-04-02 22:04:39 +0100
committerNikhil Raj <nikhil.raj@arm.com>2021-04-16 14:27:27 +0100
commit6dd178f2395b34cfb360eabb0130c19ed258f5fa (patch)
tree6814e4729bbd1e652d8b9c18c9db28f3bc2f8a8a /python
parented7fce413410d15c501ea52f9e6bfbbf71b3daf1 (diff)
downloadarmnn-6dd178f2395b34cfb360eabb0130c19ed258f5fa.tar.gz
IVGCVSW-5720 Remove the Caffe Parser from ArmNN
Signed-off-by: Nikhil Raj <nikhil.raj@arm.com> Change-Id: Ib00be204f549efa9aa5971ecf65c2dec4a10b10f
Diffstat (limited to 'python')
-rw-r--r--python/pyarmnn/examples/image_classification/example_utils.py2
-rwxr-xr-xpython/pyarmnn/setup.py1
-rw-r--r--python/pyarmnn/src/pyarmnn/__init__.py12
-rw-r--r--python/pyarmnn/src/pyarmnn/swig/armnn_caffeparser.i103
-rwxr-xr-xpython/pyarmnn/swig_generate.py1
-rw-r--r--python/pyarmnn/test/test_caffe_parser.py131
-rw-r--r--python/pyarmnn/test/test_generated.py2
7 files changed, 1 insertions, 251 deletions
diff --git a/python/pyarmnn/examples/image_classification/example_utils.py b/python/pyarmnn/examples/image_classification/example_utils.py
index f0ba91e981..bd43d60da5 100644
--- a/python/pyarmnn/examples/image_classification/example_utils.py
+++ b/python/pyarmnn/examples/image_classification/example_utils.py
@@ -72,7 +72,7 @@ def parse_command_line(desc: str = ""):
parser.add_argument("-d", "--data-dir", help="Data directory which contains all the images.",
action="store", default="")
parser.add_argument("-m", "--model-dir",
- help="Model directory which contains the model file (TF, TFLite, ONNX, Caffe).", action="store",
+ help="Model directory which contains the model file (TF, TFLite, ONNX).", action="store",
default="")
return parser.parse_args()
diff --git a/python/pyarmnn/setup.py b/python/pyarmnn/setup.py
index e1eba4b082..9d9f561ef9 100755
--- a/python/pyarmnn/setup.py
+++ b/python/pyarmnn/setup.py
@@ -283,7 +283,6 @@ if __name__ == '__main__':
ext_list.append(pyarmnn_optional_module)
- add_parsers_ext('CaffeParser', extensions_to_build)
add_parsers_ext('OnnxParser', extensions_to_build)
add_parsers_ext('TfParser', extensions_to_build)
add_parsers_ext('TfLiteParser', extensions_to_build)
diff --git a/python/pyarmnn/src/pyarmnn/__init__.py b/python/pyarmnn/src/pyarmnn/__init__.py
index 19b14a4b09..410e66be11 100644
--- a/python/pyarmnn/src/pyarmnn/__init__.py
+++ b/python/pyarmnn/src/pyarmnn/__init__.py
@@ -7,18 +7,6 @@ import logging
from ._generated.pyarmnn_version import GetVersion, GetMajorVersion, GetMinorVersion
# Parsers
-try:
- from ._generated.pyarmnn_caffeparser import ICaffeParser
-except ImportError as err:
- logger = logging.getLogger(__name__)
- message = "Your ArmNN library instance does not support Caffe models parser functionality. "
- logger.warning("%s Skipped ICaffeParser import.", message)
- logger.debug(str(err))
-
-
- def ICaffeParser():
- """In case people try importing without having Arm NN built with this parser."""
- raise RuntimeError(message)
try:
from ._generated.pyarmnn_onnxparser import IOnnxParser
diff --git a/python/pyarmnn/src/pyarmnn/swig/armnn_caffeparser.i b/python/pyarmnn/src/pyarmnn/swig/armnn_caffeparser.i
deleted file mode 100644
index 538b486aad..0000000000
--- a/python/pyarmnn/src/pyarmnn/swig/armnn_caffeparser.i
+++ /dev/null
@@ -1,103 +0,0 @@
-//
-// Copyright © 2020 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<int, armnn::TensorInfo>;
- %template(MapStringTensorShape) map<std::string, armnn::TensorShape>;
- %template(StringVector) vector<string>;
-}
-
-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 `TensorInfo`) for the network output identified by the given layer name.
-
- Args:
- name (str): Name of the output.
-
- Returns:
- tuple: (`int`, `TensorInfo`)
- ") GetNetworkOutputBindingInfo;
-
- std::pair<int, armnn::TensorInfo> GetNetworkInputBindingInfo(const std::string& name);
- std::pair<int, armnn::TensorInfo> 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<std::string, armnn::TensorShape>& inputShapes,
- const std::vector<std::string>& requestedOutputs) {
- return $self->CreateNetworkFromBinaryFile(graphFile, inputShapes, requestedOutputs).release();
- }
-}
-}
-
-// Clear exception typemap.
-%exception;
diff --git a/python/pyarmnn/swig_generate.py b/python/pyarmnn/swig_generate.py
index 72bccbf49e..a2352c9063 100755
--- a/python/pyarmnn/swig_generate.py
+++ b/python/pyarmnn/swig_generate.py
@@ -107,7 +107,6 @@ if __name__ == "__main__":
wrap_names = ['armnn_version',
'armnn',
- 'armnn_caffeparser',
'armnn_onnxparser',
'armnn_tfparser',
'armnn_tfliteparser',
diff --git a/python/pyarmnn/test/test_caffe_parser.py b/python/pyarmnn/test/test_caffe_parser.py
deleted file mode 100644
index d744b907d4..0000000000
--- a/python/pyarmnn/test/test_caffe_parser.py
+++ /dev/null
@@ -1,131 +0,0 @@
-# Copyright © 2020 Arm Ltd. All rights reserved.
-# SPDX-License-Identifier: MIT
-import os
-
-import pytest
-import pyarmnn as ann
-import numpy as np
-
-
-@pytest.fixture()
-def parser(shared_data_folder):
- """
- Parse and setup the test network to be used for the tests below
- """
-
- # Create caffe parser
- parser = ann.ICaffeParser()
-
- # Specify path to model
- path_to_model = os.path.join(shared_data_folder, 'mock_model.caffemodel')
-
- # Specify the tensor shape relative to the input [1, 1, 28, 28]
- tensor_shape = {'Placeholder': ann.TensorShape((1, 1, 28, 28))}
-
- # Specify the requested_outputs
- requested_outputs = ["output"]
-
- # Parse caffe binary & create network
- parser.CreateNetworkFromBinaryFile(path_to_model, tensor_shape, requested_outputs)
-
- yield parser
-
-
-def test_caffe_parser_swig_destroy():
- assert ann.ICaffeParser.__swig_destroy__, "There is a swig python destructor defined"
- assert ann.ICaffeParser.__swig_destroy__.__name__ == "delete_ICaffeParser"
-
-
-def test_check_caffe_parser_swig_ownership(parser):
- # Check to see that SWIG has ownership for parser. This instructs SWIG to take
- # ownership of the return value. This allows the value to be automatically
- # garbage-collected when it is no longer in use
- assert parser.thisown
-
-
-def test_get_network_input_binding_info(parser):
- input_binding_info = parser.GetNetworkInputBindingInfo("Placeholder")
-
- tensor = input_binding_info[1]
- assert tensor.GetDataType() == 1
- assert tensor.GetNumDimensions() == 4
- assert tensor.GetNumElements() == 784
-
-
-def test_get_network_output_binding_info(parser):
- output_binding_info1 = parser.GetNetworkOutputBindingInfo("output")
-
- # Check the tensor info retrieved from GetNetworkOutputBindingInfo
- tensor1 = output_binding_info1[1]
-
- assert tensor1.GetDataType() == 1
- assert tensor1.GetNumDimensions() == 2
- assert tensor1.GetNumElements() == 10
-
-
-def test_filenotfound_exception(shared_data_folder):
- parser = ann.ICaffeParser()
-
- # path to model
- path_to_model = os.path.join(shared_data_folder, 'some_unknown_network.caffemodel')
-
- # generic tensor shape [1, 1, 1, 1]
- tensor_shape = {'data': ann.TensorShape((1, 1, 1, 1))}
-
- # requested_outputs
- requested_outputs = [""]
-
- with pytest.raises(RuntimeError) as err:
- parser.CreateNetworkFromBinaryFile(path_to_model, tensor_shape, requested_outputs)
-
- # Only check for part of the exception since the exception returns
- # absolute path which will change on different machines.
- assert 'Failed to open graph file' in str(err.value)
-
-
-def test_caffe_parser_end_to_end(shared_data_folder):
- parser = ann.ICaffeParser = ann.ICaffeParser()
-
- # Load the network specifying the inputs and outputs
- input_name = "Placeholder"
- tensor_shape = {input_name: ann.TensorShape((1, 1, 28, 28))}
- requested_outputs = ["output"]
-
- network = parser.CreateNetworkFromBinaryFile(os.path.join(shared_data_folder, 'mock_model.caffemodel'),
- tensor_shape, requested_outputs)
-
- # Specify preferred backend
- preferred_backends = [ann.BackendId('CpuAcc'), ann.BackendId('CpuRef')]
-
- input_binding_info = parser.GetNetworkInputBindingInfo(input_name)
-
- options = ann.CreationOptions()
- runtime = ann.IRuntime(options)
-
- opt_network, messages = ann.Optimize(network, preferred_backends, runtime.GetDeviceSpec(), ann.OptimizerOptions())
-
- assert 0 == len(messages)
-
- net_id, messages = runtime.LoadNetwork(opt_network)
-
- assert "" == messages
-
- # Load test image data stored in input_caffe.npy
- input_tensor_data = np.load(os.path.join(shared_data_folder, 'caffe_parser/input_caffe.npy')).astype(np.float32)
- input_tensors = ann.make_input_tensors([input_binding_info], [input_tensor_data])
-
- # Load output binding info and
- outputs_binding_info = []
- for output_name in requested_outputs:
- outputs_binding_info.append(parser.GetNetworkOutputBindingInfo(output_name))
- output_tensors = ann.make_output_tensors(outputs_binding_info)
-
- runtime.EnqueueWorkload(net_id, input_tensors, output_tensors)
-
- output_vectors = ann.workload_tensors_to_ndarray(output_tensors)
-
- # Load golden output file for result comparison.
- expected_output = np.load(os.path.join(shared_data_folder, 'caffe_parser/golden_output_caffe.npy'))
-
- # Check that output matches golden output to 4 decimal places (there are slight rounding differences after this)
- np.testing.assert_almost_equal(output_vectors[0], expected_output, 4)
diff --git a/python/pyarmnn/test/test_generated.py b/python/pyarmnn/test/test_generated.py
index 0e1d663234..f27d565c2b 100644
--- a/python/pyarmnn/test/test_generated.py
+++ b/python/pyarmnn/test/test_generated.py
@@ -7,7 +7,6 @@ import pytest
import pyarmnn._generated.pyarmnn as generated_armnn
import pyarmnn._generated.pyarmnn as generated_deserializer
-import pyarmnn._generated.pyarmnn_caffeparser as generated_caffe
import pyarmnn._generated.pyarmnn_onnxparser as generated_onnx
import pyarmnn._generated.pyarmnn_tfliteparser as generated_tflite
import pyarmnn._generated.pyarmnn_tfparser as generated_tf
@@ -28,7 +27,6 @@ def get_classes(swig_independent_classes: Tuple):
return list(filter(lambda x: x[0] not in ignored_class_names,
inspect.getmembers(generated_armnn, inspect.isclass) +
inspect.getmembers(generated_deserializer, inspect.isclass) +
- inspect.getmembers(generated_caffe, inspect.isclass) +
inspect.getmembers(generated_tflite, inspect.isclass) +
inspect.getmembers(generated_onnx, inspect.isclass) +
inspect.getmembers(generated_tf, inspect.isclass)))