aboutsummaryrefslogtreecommitdiff
path: root/examples/graph_mobilenet.cpp
diff options
context:
space:
mode:
authorGian Marco <gianmarco.iodice@arm.com>2017-12-12 10:08:38 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:42:33 +0000
commitbfa3b52de2cfbd330efc19e2096134a20c645406 (patch)
tree30812054cbeaa87a268bb21174402d3b2ec199d4 /examples/graph_mobilenet.cpp
parent397252889a2d7e7d9d241ee9dcecff3edf2bcff7 (diff)
downloadComputeLibrary-bfa3b52de2cfbd330efc19e2096134a20c645406.tar.gz
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 <anthony.barbier@arm.com> Tested-by: BSG Visual Compute Jenkins server to access repositories on http://mpd-gerrit.cambridge.arm.com <bsgcomp@arm.com>
Diffstat (limited to 'examples/graph_mobilenet.cpp')
-rw-r--r--examples/graph_mobilenet.cpp46
1 files changed, 26 insertions, 20 deletions
diff --git a/examples/graph_mobilenet.cpp b/examples/graph_mobilenet.cpp
index 081fae67e2..0c916c7ba0 100644
--- a/examples/graph_mobilenet.cpp
+++ b/examples/graph_mobilenet.cpp
@@ -32,6 +32,8 @@
using namespace arm_compute::graph;
using namespace arm_compute::graph_utils;
+namespace
+{
BranchLayer get_dwsc_node(const std::string &data_path, std::string &&param_path,
unsigned int conv_filt,
PadStrideInfo dwc_pad_stride_info, PadStrideInfo conv_pad_stride_info)
@@ -66,11 +68,12 @@ BranchLayer get_dwsc_node(const std::string &data_path, std::string &&param_path
return BranchLayer(std::move(sg));
}
+} // namespace
/** Example demonstrating how to implement MobileNet'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_mobilenet(int argc, const char **argv)
{
@@ -82,42 +85,44 @@ void main_graph_mobilenet(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);
+
// 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)
{
- data_path = argv[1];
- std::cout << "Usage: " << argv[0] << " " << argv[1] << " [image] [labels]\n\n";
- std::cout << "No image provided: using random values\n\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\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(
@@ -131,6 +136,7 @@ void main_graph_mobilenet(int argc, const char **argv)
get_weights_accessor(data_path, "/cnn_data/mobilenet_v1_model/Conv2d_0_BatchNorm_beta.npy"),
get_weights_accessor(data_path, "/cnn_data/mobilenet_v1_model/Conv2d_0_BatchNorm_gamma.npy"),
0.001f)
+
<< ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.f))
<< get_dwsc_node(data_path, "Conv2d_1", 64, PadStrideInfo(1, 1, 1, 1), PadStrideInfo(1, 1, 0, 0))
<< get_dwsc_node(data_path, "Conv2d_2", 128, PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::FLOOR), PadStrideInfo(1, 1, 0, 0))
@@ -161,7 +167,7 @@ void main_graph_mobilenet(int argc, const char **argv)
/** Main program for MobileNetV1
*
* @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)
{