From bfa3b52de2cfbd330efc19e2096134a20c645406 Mon Sep 17 00:00:00 2001 From: Gian Marco Date: Tue, 12 Dec 2017 10:08:38 +0000 Subject: COMPMID-556 - Fix examples - Fixed data type issue in cl_sgemm - Added support for NEON and OpenCL targets in graph examples. Before we could run only OpenCL target - Add auto_init() in NEDepthwiseVectorToTensorKernel Change-Id: I4410ce6f4992b2375b980634fe55f1083cf3c471 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/112850 Reviewed-by: Anthony Barbier Tested-by: BSG Visual Compute Jenkins server to access repositories on http://mpd-gerrit.cambridge.arm.com --- examples/graph_squeezenet.cpp | 47 ++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'examples/graph_squeezenet.cpp') diff --git a/examples/graph_squeezenet.cpp b/examples/graph_squeezenet.cpp index 1743509256..c8c411aa8b 100644 --- a/examples/graph_squeezenet.cpp +++ b/examples/graph_squeezenet.cpp @@ -35,6 +35,8 @@ using namespace arm_compute::graph; using namespace arm_compute::graph_utils; using namespace arm_compute::logging; +namespace +{ BranchLayer get_expand_fire_node(const std::string &data_path, std::string &¶m_path, unsigned int expand1_filt, unsigned int expand3_filt) { std::string total_path = "/cnn_data/squeezenet_v1.0_model/" + param_path + "_"; @@ -56,11 +58,12 @@ BranchLayer get_expand_fire_node(const std::string &data_path, std::string &&par return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b)); } +} // namespace /** Example demonstrating how to implement Squeezenet's network using the Compute Library's graph API * * @param[in] argc Number of arguments - * @param[in] argv Arguments ( [optional] Path to the weights folder, [optional] image, [optional] labels ) + * @param[in] argv Arguments ( [optional] Target (0 = NEON, 1 = OpenCL), [optional] Path to the weights folder, [optional] image, [optional] labels ) */ void main_graph_squeezenet(int argc, const char **argv) { @@ -72,44 +75,45 @@ void main_graph_squeezenet(int argc, const char **argv) constexpr float mean_g = 116.67f; /* Mean value to subtract from green channel */ constexpr float mean_b = 104.01f; /* Mean value to subtract from blue channel */ + // Set target. 0 (NEON), 1 (OpenCL). By default it is NEON + TargetHint target_hint = set_target_hint(argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0); + ConvolutionMethodHint convolution_hint = target_hint == TargetHint::NEON ? ConvolutionMethodHint::GEMM : ConvolutionMethodHint::DIRECT; + // Parse arguments if(argc < 2) { // Print help - std::cout << "Usage: " << argv[0] << " [path_to_data] [image] [labels]\n\n"; + std::cout << "Usage: " << argv[0] << " [target] [path_to_data] [image] [labels]\n\n"; std::cout << "No data folder provided: using random values\n\n"; } else if(argc == 2) { - //Do something with argv[1] - data_path = argv[1]; - std::cout << "Usage: " << argv[0] << " " << argv[1] << " [image] [labels]\n\n"; - std::cout << "No image provided: using random values\n"; + std::cout << "Usage: " << argv[0] << " " << argv[1] << " [path_to_data] [image] [labels]\n\n"; + std::cout << "No data folder provided: using random values\n\n"; } else if(argc == 3) { - data_path = argv[1]; - image = argv[2]; - std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " [labels]\n\n"; - std::cout << "No text file with labels provided: skipping output accessor\n"; + data_path = argv[2]; + std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " [image] [labels]\n\n"; + std::cout << "No image provided: using random values\n\n"; } - else + else if(argc == 4) { - data_path = argv[1]; - image = argv[2]; - label = argv[3]; + data_path = argv[2]; + image = argv[3]; + std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " " << argv[3] << " [labels]\n\n"; + std::cout << "No text file with labels provided: skipping output accessor\n\n"; } - - // Check if OpenCL is available and initialize the scheduler - TargetHint hint = TargetHint::NEON; - if(Graph::opencl_is_available()) + else { - hint = TargetHint::OPENCL; + data_path = argv[2]; + image = argv[3]; + label = argv[4]; } Graph graph; - graph << hint + graph << target_hint << Tensor(TensorInfo(TensorShape(224U, 224U, 3U, 1U), 1, DataType::F32), get_input_accessor(image, mean_r, mean_g, mean_b)) << ConvolutionLayer( @@ -117,6 +121,7 @@ void main_graph_squeezenet(int argc, const char **argv) get_weights_accessor(data_path, "/cnn_data/squeezenet_v1.0_model/conv1_w.npy"), get_weights_accessor(data_path, "/cnn_data/squeezenet_v1.0_model/conv1_b.npy"), PadStrideInfo(2, 2, 0, 0)) + << convolution_hint << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))) << ConvolutionLayer( @@ -194,7 +199,7 @@ void main_graph_squeezenet(int argc, const char **argv) /** Main program for Squeezenet v1.0 * * @param[in] argc Number of arguments - * @param[in] argv Arguments ( [optional] Path to the weights folder, [optional] image, [optional] labels ) + * @param[in] argv Arguments ( [optional] Target (0 = NEON, 1 = OpenCL), [optional] Path to the weights folder, [optional] image, [optional] labels ) */ int main(int argc, const char **argv) { -- cgit v1.2.1