aboutsummaryrefslogtreecommitdiff
path: root/examples/graph_resnext50.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_resnext50.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_resnext50.cpp')
-rw-r--r--examples/graph_resnext50.cpp32
1 files changed, 19 insertions, 13 deletions
diff --git a/examples/graph_resnext50.cpp b/examples/graph_resnext50.cpp
index c0e9b9f22a..e7ef013f17 100644
--- a/examples/graph_resnext50.cpp
+++ b/examples/graph_resnext50.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;
@@ -68,26 +67,32 @@ public:
// Get trainable parameters data path
std::string data_path = common_params.data_path;
+ // Create input descriptor
+ const TensorShape tensor_shape = permute_shape(TensorShape(224U, 224U, 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(224U, 224U, 3U, 1U), common_params.data_type),
- get_input_accessor(common_params))
+ << InputLayer(input_descriptor, get_input_accessor(common_params))
<< ScaleLayer(get_weights_accessor(data_path, "/cnn_data/resnext50_model/bn_data_mul.npy"),
get_weights_accessor(data_path, "/cnn_data/resnext50_model/bn_data_add.npy"))
.set_name("bn_data/Scale")
<< ConvolutionLayer(
7U, 7U, 64U,
- get_weights_accessor(data_path, "/cnn_data/resnext50_model/conv0_weights.npy"),
+ get_weights_accessor(data_path, "/cnn_data/resnext50_model/conv0_weights.npy", weights_layout),
get_weights_accessor(data_path, "/cnn_data/resnext50_model/conv0_biases.npy"),
PadStrideInfo(2, 2, 2, 3, 2, 3, DimensionRoundingType::FLOOR))
.set_name("conv0/Convolution")
<< ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv0/Relu")
<< PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::FLOOR))).set_name("pool0");
- add_residual_block(data_path, /*ofm*/ 256, /*stage*/ 1, /*num_unit*/ 3, /*stride_conv_unit1*/ 1);
- add_residual_block(data_path, 512, 2, 4, 2);
- add_residual_block(data_path, 1024, 3, 6, 2);
- add_residual_block(data_path, 2048, 4, 3, 2);
+ add_residual_block(data_path, weights_layout, /*ofm*/ 256, /*stage*/ 1, /*num_unit*/ 3, /*stride_conv_unit1*/ 1);
+ add_residual_block(data_path, weights_layout, 512, 2, 4, 2);
+ add_residual_block(data_path, weights_layout, 1024, 3, 6, 2);
+ add_residual_block(data_path, weights_layout, 2048, 4, 3, 2);
graph << PoolingLayer(PoolingLayerInfo(PoolingType::AVG)).set_name("pool1")
<< FlattenLayer().set_name("predictions/Reshape")
@@ -116,7 +121,8 @@ private:
CommonGraphParams common_params;
Stream graph;
- void add_residual_block(const std::string &data_path, unsigned int base_depth, unsigned int stage, unsigned int num_units, unsigned int stride_conv_unit1)
+ void add_residual_block(const std::string &data_path, DataLayout weights_layout,
+ unsigned int base_depth, unsigned int stage, unsigned int num_units, unsigned int stride_conv_unit1)
{
for(unsigned int i = 0; i < num_units; ++i)
{
@@ -137,7 +143,7 @@ private:
SubStream right(graph);
right << ConvolutionLayer(
1U, 1U, base_depth / 2,
- get_weights_accessor(data_path, unit_path + "conv1_weights.npy"),
+ get_weights_accessor(data_path, unit_path + "conv1_weights.npy", weights_layout),
get_weights_accessor(data_path, unit_path + "conv1_biases.npy"),
PadStrideInfo(1, 1, 0, 0))
.set_name(unit_name + "conv1/convolution")
@@ -145,7 +151,7 @@ private:
<< ConvolutionLayer(
3U, 3U, base_depth / 2,
- get_weights_accessor(data_path, unit_path + "conv2_weights.npy"),
+ get_weights_accessor(data_path, unit_path + "conv2_weights.npy", weights_layout),
std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
pad_grouped_conv, 32)
.set_name(unit_name + "conv2/convolution")
@@ -156,7 +162,7 @@ private:
<< ConvolutionLayer(
1U, 1U, base_depth,
- get_weights_accessor(data_path, unit_path + "conv3_weights.npy"),
+ get_weights_accessor(data_path, unit_path + "conv3_weights.npy", weights_layout),
get_weights_accessor(data_path, unit_path + "conv3_biases.npy"),
PadStrideInfo(1, 1, 0, 0))
.set_name(unit_name + "conv3/convolution");
@@ -166,7 +172,7 @@ private:
{
left << ConvolutionLayer(
1U, 1U, base_depth,
- get_weights_accessor(data_path, unit_path + "sc_weights.npy"),
+ get_weights_accessor(data_path, unit_path + "sc_weights.npy", weights_layout),
std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr),
PadStrideInfo(stride_conv_unit1, stride_conv_unit1, 0, 0))
.set_name(unit_name + "sc/convolution")