From 140fdc76e99c92b2f71865b679de0659a70b713f Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Fri, 16 Feb 2018 11:42:38 +0000 Subject: COMPMID-913: Fix preprocessing step for TF models. Change-Id: If0fbb6bbe5384038124d3dc189274b8266f796ca Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/120771 Reviewed-by: Anthony Barbier Reviewed-by: Pablo Tello Tested-by: Jenkins --- examples/graph_alexnet.cpp | 8 ++++---- examples/graph_googlenet.cpp | 8 ++++---- examples/graph_inception_v3.cpp | 8 +++----- examples/graph_mobilenet.cpp | 8 +++----- examples/graph_squeezenet.cpp | 8 ++++---- examples/graph_squeezenet_v1_1.cpp | 8 ++++---- examples/graph_vgg16.cpp | 8 ++++---- examples/graph_vgg19.cpp | 8 ++++---- 8 files changed, 30 insertions(+), 34 deletions(-) (limited to 'examples') diff --git a/examples/graph_alexnet.cpp b/examples/graph_alexnet.cpp index bd620574b8..d4854a5449 100644 --- a/examples/graph_alexnet.cpp +++ b/examples/graph_alexnet.cpp @@ -49,9 +49,9 @@ public: std::string image; /* Image data */ std::string label; /* Label data */ - constexpr float mean_r = 122.68f; /* Mean value to subtract from red channel */ - 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 */ + // Create a preprocessor object + const std::array mean_rgb{ { 122.68f, 116.67f, 104.01f } }; + std::unique_ptr preprocessor = arm_compute::support::cpp14::make_unique(mean_rgb); // Set target. 0 (NEON), 1 (OpenCL), 2 (OpenCL with Tuner). By default it is NEON const int int_target_hint = argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0; @@ -97,7 +97,7 @@ public: graph << target_hint << Tensor(TensorInfo(TensorShape(227U, 227U, 3U, 1U), 1, DataType::F32), - get_input_accessor(image, mean_r, mean_g, mean_b)) + get_input_accessor(image, std::move(preprocessor))) // Layer 1 << ConvolutionLayer( 11U, 11U, 96U, diff --git a/examples/graph_googlenet.cpp b/examples/graph_googlenet.cpp index 13f6543ef6..1b2f0d6f3b 100644 --- a/examples/graph_googlenet.cpp +++ b/examples/graph_googlenet.cpp @@ -49,9 +49,9 @@ public: std::string image; /* Image data */ std::string label; /* Label data */ - constexpr float mean_r = 122.68f; /* Mean value to subtract from red channel */ - 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 */ + // Create a preprocessor object + const std::array mean_rgb{ { 122.68f, 116.67f, 104.01f } }; + std::unique_ptr preprocessor = arm_compute::support::cpp14::make_unique(mean_rgb); // Set target. 0 (NEON), 1 (OpenCL), 2 (OpenCL with Tuner). By default it is NEON const int int_target_hint = argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0; @@ -95,7 +95,7 @@ public: graph << target_hint << Tensor(TensorInfo(TensorShape(224U, 224U, 3U, 1U), 1, DataType::F32), - get_input_accessor(image, mean_r, mean_g, mean_b)) + get_input_accessor(image, std::move(preprocessor))) << ConvolutionLayer( 7U, 7U, 64U, get_weights_accessor(data_path, "/cnn_data/googlenet_model/conv1/conv1_7x7_s2_w.npy"), diff --git a/examples/graph_inception_v3.cpp b/examples/graph_inception_v3.cpp index f2423eb4bd..338c22763c 100644 --- a/examples/graph_inception_v3.cpp +++ b/examples/graph_inception_v3.cpp @@ -49,8 +49,8 @@ public: std::string image; /* Image data */ std::string label; /* Label data */ - constexpr float mean = 0.f; /* Mean value to subtract from the channels */ - constexpr float std = 255.f; /* Standard deviation value to divide from the channels */ + // Create a preprocessor object + std::unique_ptr preprocessor = arm_compute::support::cpp14::make_unique(); // Set target. 0 (NEON), 1 (OpenCL), 2 (OpenCL with Tuner). By default it is NEON const int int_target_hint = argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0; @@ -92,9 +92,7 @@ public: graph.graph_init(int_target_hint == 2); graph << target_hint << Tensor(TensorInfo(TensorShape(299U, 299U, 3U, 1U), 1, DataType::F32), - get_input_accessor(image, - mean, mean, mean, - std, std, std, false /* Do not convert to BGR */)) + get_input_accessor(image, std::move(preprocessor), false)) << ConvolutionLayer(3U, 3U, 32U, get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_weights.npy"), diff --git a/examples/graph_mobilenet.cpp b/examples/graph_mobilenet.cpp index 0cc636a07d..8c992162eb 100644 --- a/examples/graph_mobilenet.cpp +++ b/examples/graph_mobilenet.cpp @@ -47,8 +47,8 @@ public: std::string image; /* Image data */ std::string label; /* Label data */ - constexpr float mean = 0.f; /* Mean value to subtract from the channels */ - constexpr float std = 255.f; /* Standard deviation value to divide from the channels */ + // Create a preprocessor object + std::unique_ptr preprocessor = arm_compute::support::cpp14::make_unique(); // Set target. 0 (NEON), 1 (OpenCL), 2 (OpenCL with Tuner). By default it is NEON const int int_target_hint = argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0; @@ -113,9 +113,7 @@ public: graph << target_hint << convolution_hint << Tensor(TensorInfo(TensorShape(spatial_size, spatial_size, 3U, 1U), 1, DataType::F32), - get_input_accessor(image, - mean, mean, mean, - std, std, std, false /* Do not convert to BGR */)) + get_input_accessor(image, std::move(preprocessor), false)) << ConvolutionLayer( 3U, 3U, 32U * depth_scale, get_weights_accessor(data_path, "Conv2d_0_weights.npy"), diff --git a/examples/graph_squeezenet.cpp b/examples/graph_squeezenet.cpp index 517d0cc127..303ae25741 100644 --- a/examples/graph_squeezenet.cpp +++ b/examples/graph_squeezenet.cpp @@ -54,9 +54,9 @@ public: std::string image; /* Image data */ std::string label; /* Label data */ - constexpr float mean_r = 122.68f; /* Mean value to subtract from red channel */ - 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 */ + // Create a preprocessor object + const std::array mean_rgb{ { 122.68f, 116.67f, 104.01f } }; + std::unique_ptr preprocessor = arm_compute::support::cpp14::make_unique(mean_rgb); // Set target. 0 (NEON), 1 (OpenCL), 2 (OpenCL with Tuner). By default it is NEON const int int_target_hint = argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0; @@ -99,7 +99,7 @@ public: graph << target_hint << Tensor(TensorInfo(TensorShape(224U, 224U, 3U, 1U), 1, DataType::F32), - get_input_accessor(image, mean_r, mean_g, mean_b)) + get_input_accessor(image, std::move(preprocessor))) << ConvolutionLayer( 7U, 7U, 96U, get_weights_accessor(data_path, "/cnn_data/squeezenet_v1.0_model/conv1_w.npy"), diff --git a/examples/graph_squeezenet_v1_1.cpp b/examples/graph_squeezenet_v1_1.cpp index 3c6be742fa..92a592390e 100644 --- a/examples/graph_squeezenet_v1_1.cpp +++ b/examples/graph_squeezenet_v1_1.cpp @@ -54,9 +54,9 @@ public: std::string image; /* Image data */ std::string label; /* Label data */ - constexpr float mean_r = 122.68f; /* Mean value to subtract from red channel */ - 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 */ + // Create a preprocessor object + const std::array mean_rgb{ { 122.68f, 116.67f, 104.01f } }; + std::unique_ptr preprocessor = arm_compute::support::cpp14::make_unique(mean_rgb); // Set target. 0 (NEON), 1 (OpenCL), 2 (OpenCL with Tuner). By default it is NEON const int int_target_hint = argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0; @@ -99,7 +99,7 @@ public: graph << target_hint << Tensor(TensorInfo(TensorShape(227U, 227U, 3U, 1U), 1, DataType::F32), - get_input_accessor(image, mean_r, mean_g, mean_b)) + get_input_accessor(image, std::move(preprocessor))) << ConvolutionLayer( 3U, 3U, 64U, get_weights_accessor(data_path, "/cnn_data/squeezenet_v1_1_model/conv1_w.npy"), diff --git a/examples/graph_vgg16.cpp b/examples/graph_vgg16.cpp index ccb9dbb19d..eb8bd42e1a 100644 --- a/examples/graph_vgg16.cpp +++ b/examples/graph_vgg16.cpp @@ -61,9 +61,9 @@ public: std::string image; /* Image data */ std::string label; /* Label data */ - constexpr float mean_r = 123.68f; /* Mean value to subtract from red channel */ - constexpr float mean_g = 116.779f; /* Mean value to subtract from green channel */ - constexpr float mean_b = 103.939f; /* Mean value to subtract from blue channel */ + // Create a preprocessor object + const std::array mean_rgb{ { 123.68f, 116.779f, 103.939f } }; + std::unique_ptr preprocessor = arm_compute::support::cpp14::make_unique(mean_rgb); // Set target. 0 (NEON), 1 (OpenCL), 2 (OpenCL with Tuner). By default it is NEON const int int_target_hint = argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0; @@ -111,7 +111,7 @@ public: graph << target_hint << convolution_hint << Tensor(TensorInfo(TensorShape(224U, 224U, 3U, 1U), 1, DataType::F32), - get_input_accessor(image, mean_r, mean_g, mean_b)) + get_input_accessor(image, std::move(preprocessor))) // Layer 1 << ConvolutionLayer( 3U, 3U, 64U, diff --git a/examples/graph_vgg19.cpp b/examples/graph_vgg19.cpp index c940c4ef73..f2864f0f13 100644 --- a/examples/graph_vgg19.cpp +++ b/examples/graph_vgg19.cpp @@ -47,9 +47,9 @@ public: std::string image; /* Image data */ std::string label; /* Label data */ - constexpr float mean_r = 123.68f; /* Mean value to subtract from red channel */ - constexpr float mean_g = 116.779f; /* Mean value to subtract from green channel */ - constexpr float mean_b = 103.939f; /* Mean value to subtract from blue channel */ + // Create a preprocessor object + const std::array mean_rgb{ { 123.68f, 116.779f, 103.939f } }; + std::unique_ptr preprocessor = arm_compute::support::cpp14::make_unique(mean_rgb); // Set target. 0 (NEON), 1 (OpenCL), 2 (OpenCL with Tuner). By default it is NEON const int int_target_hint = argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0; @@ -94,7 +94,7 @@ public: graph << target_hint << convolution_hint << Tensor(TensorInfo(TensorShape(224U, 224U, 3U, 1U), 1, DataType::F32), - get_input_accessor(image, mean_r, mean_g, mean_b)) + get_input_accessor(image, std::move(preprocessor))) // Layer 1 << ConvolutionLayer( 3U, 3U, 64U, -- cgit v1.2.1