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_googlenet.cpp | 47 ++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'examples/graph_googlenet.cpp') diff --git a/examples/graph_googlenet.cpp b/examples/graph_googlenet.cpp index b7ff4e4bf0..d08382ab8e 100644 --- a/examples/graph_googlenet.cpp +++ b/examples/graph_googlenet.cpp @@ -34,6 +34,8 @@ using namespace arm_compute::graph; using namespace arm_compute::graph_utils; +namespace +{ BranchLayer get_inception_node(const std::string &data_path, std::string &¶m_path, unsigned int a_filt, std::tuple b_filters, @@ -88,11 +90,12 @@ BranchLayer get_inception_node(const std::string &data_path, std::string &¶m return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d)); } +} // namespace /** Example demonstrating how to implement Googlenet'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_googlenet(int argc, const char **argv) { @@ -104,44 +107,45 @@ void main_graph_googlenet(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( @@ -152,6 +156,7 @@ void main_graph_googlenet(int argc, const char **argv) << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))) << NormalizationLayer(NormalizationLayerInfo(NormType::CROSS_MAP, 5, 0.0001f, 0.75f)) + << convolution_hint << ConvolutionLayer( 1U, 1U, 64U, get_weights_accessor(data_path, "/cnn_data/googlenet_model/conv2/conv2_3x3_reduce_w.npy"), @@ -191,7 +196,7 @@ void main_graph_googlenet(int argc, const char **argv) /** Main program for Googlenet * * @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