aboutsummaryrefslogtreecommitdiff
path: root/examples/graph_alexnet.cpp
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2018-07-20 13:23:44 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:54:54 +0000
commite2220551b7a64b929650ba9a60529c31e70c13c5 (patch)
tree5d609887f15b4392cdade7bb388710ceafc62260 /examples/graph_alexnet.cpp
parenteff8d95991205e874091576e2d225f63246dd0bb (diff)
downloadComputeLibrary-e2220551b7a64b929650ba9a60529c31e70c13c5.tar.gz
COMPMID-1367: Enable NHWC in graph examples
Change-Id: Iabc54a3a1bdcd46a9a921cda39c7c85fef672b72 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/141449 Reviewed-by: Giorgio Arena <giorgio.arena@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com> Tested-by: Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'examples/graph_alexnet.cpp')
-rw-r--r--examples/graph_alexnet.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/examples/graph_alexnet.cpp b/examples/graph_alexnet.cpp
index 63e7b16128..944a435c3b 100644
--- a/examples/graph_alexnet.cpp
+++ b/examples/graph_alexnet.cpp
@@ -60,7 +60,6 @@ public:
// Checks
ARM_COMPUTE_EXIT_ON_MSG(arm_compute::is_data_type_quantized_asymmetric(common_params.data_type), "Unsupported data type!");
- ARM_COMPUTE_EXIT_ON_MSG(common_params.data_layout == DataLayout::NHWC, "Unsupported data layout!");
// Print parameter values
std::cout << common_params << std::endl;
@@ -72,14 +71,20 @@ public:
const std::array<float, 3> mean_rgb{ { 122.68f, 116.67f, 104.01f } };
std::unique_ptr<IPreprocessor> preprocessor = arm_compute::support::cpp14::make_unique<CaffePreproccessor>(mean_rgb);
+ // Create input descriptor
+ const TensorShape tensor_shape = permute_shape(TensorShape(227U, 227U, 3U, 1U), DataLayout::NCHW, common_params.data_layout);
+ TensorDescriptor input_descriptor = TensorDescriptor(tensor_shape, common_params.data_type).set_layout(common_params.data_layout);
+
+ // Set weights trained layout
+ const DataLayout weights_layout = DataLayout::NCHW;
+
graph << common_params.target
<< common_params.fast_math_hint
- << InputLayer(TensorDescriptor(TensorShape(227U, 227U, 3U, 1U), common_params.data_type),
- get_input_accessor(common_params, std::move(preprocessor)))
+ << InputLayer(input_descriptor, get_input_accessor(common_params, std::move(preprocessor)))
// Layer 1
<< ConvolutionLayer(
11U, 11U, 96U,
- get_weights_accessor(data_path, "/cnn_data/alexnet_model/conv1_w.npy"),
+ get_weights_accessor(data_path, "/cnn_data/alexnet_model/conv1_w.npy", weights_layout),
get_weights_accessor(data_path, "/cnn_data/alexnet_model/conv1_b.npy"),
PadStrideInfo(4, 4, 0, 0))
.set_name("conv1")
@@ -89,7 +94,7 @@ public:
// Layer 2
<< ConvolutionLayer(
5U, 5U, 256U,
- get_weights_accessor(data_path, "/cnn_data/alexnet_model/conv2_w.npy"),
+ get_weights_accessor(data_path, "/cnn_data/alexnet_model/conv2_w.npy", weights_layout),
get_weights_accessor(data_path, "/cnn_data/alexnet_model/conv2_b.npy"),
PadStrideInfo(1, 1, 2, 2), 2)
.set_name("conv2")
@@ -99,7 +104,7 @@ public:
// Layer 3
<< ConvolutionLayer(
3U, 3U, 384U,
- get_weights_accessor(data_path, "/cnn_data/alexnet_model/conv3_w.npy"),
+ get_weights_accessor(data_path, "/cnn_data/alexnet_model/conv3_w.npy", weights_layout),
get_weights_accessor(data_path, "/cnn_data/alexnet_model/conv3_b.npy"),
PadStrideInfo(1, 1, 1, 1))
.set_name("conv3")
@@ -107,7 +112,7 @@ public:
// Layer 4
<< ConvolutionLayer(
3U, 3U, 384U,
- get_weights_accessor(data_path, "/cnn_data/alexnet_model/conv4_w.npy"),
+ get_weights_accessor(data_path, "/cnn_data/alexnet_model/conv4_w.npy", weights_layout),
get_weights_accessor(data_path, "/cnn_data/alexnet_model/conv4_b.npy"),
PadStrideInfo(1, 1, 1, 1), 2)
.set_name("conv4")
@@ -115,7 +120,7 @@ public:
// Layer 5
<< ConvolutionLayer(
3U, 3U, 256U,
- get_weights_accessor(data_path, "/cnn_data/alexnet_model/conv5_w.npy"),
+ get_weights_accessor(data_path, "/cnn_data/alexnet_model/conv5_w.npy", weights_layout),
get_weights_accessor(data_path, "/cnn_data/alexnet_model/conv5_b.npy"),
PadStrideInfo(1, 1, 1, 1), 2)
.set_name("conv5")
@@ -124,21 +129,21 @@ public:
// Layer 6
<< FullyConnectedLayer(
4096U,
- get_weights_accessor(data_path, "/cnn_data/alexnet_model/fc6_w.npy"),
+ get_weights_accessor(data_path, "/cnn_data/alexnet_model/fc6_w.npy", weights_layout),
get_weights_accessor(data_path, "/cnn_data/alexnet_model/fc6_b.npy"))
.set_name("fc6")
<< ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("relu6")
// Layer 7
<< FullyConnectedLayer(
4096U,
- get_weights_accessor(data_path, "/cnn_data/alexnet_model/fc7_w.npy"),
+ get_weights_accessor(data_path, "/cnn_data/alexnet_model/fc7_w.npy", weights_layout),
get_weights_accessor(data_path, "/cnn_data/alexnet_model/fc7_b.npy"))
.set_name("fc7")
<< ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("relu7")
// Layer 8
<< FullyConnectedLayer(
1000U,
- get_weights_accessor(data_path, "/cnn_data/alexnet_model/fc8_w.npy"),
+ get_weights_accessor(data_path, "/cnn_data/alexnet_model/fc8_w.npy", weights_layout),
get_weights_accessor(data_path, "/cnn_data/alexnet_model/fc8_b.npy"))
.set_name("fc8")
// Softmax