blob: 0c6fcc159a4f82ce6214ecdab217174e74006515 [file] [log] [blame]
Jenkins514be652019-02-28 12:25:18 +00001<!-- HTML header for doxygen 1.8.15-->
2<!-- Remember to use version doxygen 1.8.15 +-->
Kaizen8938bd32017-09-28 14:38:23 +01003<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4<html xmlns="http://www.w3.org/1999/xhtml">
5<head>
6<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
7<meta http-equiv="X-UA-Compatible" content="IE=9"/>
Jenkins514be652019-02-28 12:25:18 +00008<meta name="generator" content="Doxygen 1.8.15"/>
Kaizen8938bd32017-09-28 14:38:23 +01009<meta name="robots" content="NOINDEX, NOFOLLOW" /> <!-- Prevent indexing by search engines -->
10<title>Compute Library: Importing data from existing models</title>
11<link href="tabs.css" rel="stylesheet" type="text/css"/>
12<script type="text/javascript" src="jquery.js"></script>
13<script type="text/javascript" src="dynsections.js"></script>
14<link href="navtree.css" rel="stylesheet" type="text/css"/>
15<script type="text/javascript" src="resize.js"></script>
Anthony Barbier8140e1e2017-12-14 23:48:46 +000016<script type="text/javascript" src="navtreedata.js"></script>
Kaizen8938bd32017-09-28 14:38:23 +010017<script type="text/javascript" src="navtree.js"></script>
18<script type="text/javascript">
Jenkins514be652019-02-28 12:25:18 +000019/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
Kaizen8938bd32017-09-28 14:38:23 +010020 $(document).ready(initResizable);
Jenkins514be652019-02-28 12:25:18 +000021/* @license-end */</script>
Kaizen8938bd32017-09-28 14:38:23 +010022<link href="search/search.css" rel="stylesheet" type="text/css"/>
Anthony Barbier8140e1e2017-12-14 23:48:46 +000023<script type="text/javascript" src="search/searchdata.js"></script>
Kaizen8938bd32017-09-28 14:38:23 +010024<script type="text/javascript" src="search/search.js"></script>
Kaizen8938bd32017-09-28 14:38:23 +010025<script type="text/x-mathjax-config">
26 MathJax.Hub.Config({
27 extensions: ["tex2jax.js"],
28 jax: ["input/TeX","output/HTML-CSS"],
29});
Jenkins514be652019-02-28 12:25:18 +000030</script><script type="text/javascript" async="async" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
Kaizen8938bd32017-09-28 14:38:23 +010031<link href="doxygen.css" rel="stylesheet" type="text/css" />
Jenkins514be652019-02-28 12:25:18 +000032<link href="stylesheet.css" rel="stylesheet" type="text/css"/>
Kaizen8938bd32017-09-28 14:38:23 +010033</head>
34<body>
35<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
36<div id="titlearea">
37<table cellspacing="0" cellpadding="0">
38 <tbody>
39 <tr style="height: 56px;">
Jenkins514be652019-02-28 12:25:18 +000040 <img alt="Compute Library" src="https://raw.githubusercontent.com/ARM-software/ComputeLibrary/gh-pages/ACL_logo.png" style="max-width: 100%;margin-top: 15px;margin-left: 10px"/>
Kaizen8938bd32017-09-28 14:38:23 +010041 <td style="padding-left: 0.5em;">
Jenkins514be652019-02-28 12:25:18 +000042 <div id="projectname">
Jenkins7f09cf72020-01-22 18:08:16 +000043 &#160;<span id="projectnumber">19.11.1</span>
Kaizen8938bd32017-09-28 14:38:23 +010044 </div>
45 </td>
46 </tr>
47 </tbody>
48</table>
49</div>
50<!-- end header part -->
Jenkins514be652019-02-28 12:25:18 +000051<!-- Generated by Doxygen 1.8.15 -->
Kaizen8938bd32017-09-28 14:38:23 +010052<script type="text/javascript">
Jenkins514be652019-02-28 12:25:18 +000053/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
Kaizen8938bd32017-09-28 14:38:23 +010054var searchBox = new SearchBox("searchBox", "search",false,'Search');
Jenkins514be652019-02-28 12:25:18 +000055/* @license-end */
Kaizen8938bd32017-09-28 14:38:23 +010056</script>
Jenkinsb9abeae2018-11-22 11:58:08 +000057<script type="text/javascript" src="menudata.js"></script>
58<script type="text/javascript" src="menu.js"></script>
59<script type="text/javascript">
Jenkins514be652019-02-28 12:25:18 +000060/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
Jenkinsb9abeae2018-11-22 11:58:08 +000061$(function() {
62 initMenu('',true,false,'search.php','Search');
63 $(document).ready(function() { init_search(); });
64});
Jenkins514be652019-02-28 12:25:18 +000065/* @license-end */</script>
Jenkinsb9abeae2018-11-22 11:58:08 +000066<div id="main-nav"></div>
Kaizen8938bd32017-09-28 14:38:23 +010067</div><!-- top -->
68<div id="side-nav" class="ui-resizable side-nav-resizable">
69 <div id="nav-tree">
70 <div id="nav-tree-contents">
71 <div id="nav-sync" class="sync"></div>
72 </div>
73 </div>
74 <div id="splitbar" style="-moz-user-select:none;"
75 class="ui-resizable-handle">
76 </div>
77</div>
78<script type="text/javascript">
Jenkins514be652019-02-28 12:25:18 +000079/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
Kaizen8938bd32017-09-28 14:38:23 +010080$(document).ready(function(){initNavTree('data_import.xhtml','');});
Jenkins514be652019-02-28 12:25:18 +000081/* @license-end */
Kaizen8938bd32017-09-28 14:38:23 +010082</script>
83<div id="doc-content">
84<!-- window showing the filter options -->
85<div id="MSearchSelectWindow"
86 onmouseover="return searchBox.OnSearchSelectShow()"
87 onmouseout="return searchBox.OnSearchSelectHide()"
88 onkeydown="return searchBox.OnSearchSelectKey(event)">
Anthony Barbier8140e1e2017-12-14 23:48:46 +000089</div>
Kaizen8938bd32017-09-28 14:38:23 +010090
91<!-- iframe showing the search results (closed by default) -->
92<div id="MSearchResultsWindow">
93<iframe src="javascript:void(0)" frameborder="0"
94 name="MSearchResults" id="MSearchResults">
95</iframe>
96</div>
97
Jenkins514be652019-02-28 12:25:18 +000098<div class="PageDoc"><div class="header">
Kaizen8938bd32017-09-28 14:38:23 +010099 <div class="headertitle">
100<div class="title">Importing data from existing models </div> </div>
101</div><!--header-->
102<div class="contents">
103<div class="toc"><h3>Table of Contents</h3>
104<ul><li class="level1"><a href="#caffe_data_extractor">Extract data from pre-trained caffe model</a><ul><li class="level2"><a href="#caffe_how_to">How to use the script</a></li>
105<li class="level2"><a href="#caffe_result">What is the expected output from the script</a></li>
106</ul>
107</li>
108<li class="level1"><a href="#tensorflow_data_extractor">Extract data from pre-trained tensorflow model</a><ul><li class="level2"><a href="#tensorflow_how_to">How to use the script</a></li>
109<li class="level2"><a href="#tensorflow_result">What is the expected output from the script</a></li>
110</ul>
111</li>
Jenkins514be652019-02-28 12:25:18 +0000112<li class="level1"><a href="#tf_frozen_model_extractor">Extract data from pre-trained frozen tensorflow model</a><ul><li class="level2"><a href="#tensorflow_frozen_how_to">How to use the script</a></li>
113<li class="level2"><a href="#tensorflow_frozen_result">What is the expected output from the script</a></li>
114</ul>
115</li>
116<li class="level1"><a href="#validate_examples">Validating examples</a></li>
Kaizen8938bd32017-09-28 14:38:23 +0100117</ul>
118</div>
119<div class="textblock"><h1><a class="anchor" id="caffe_data_extractor"></a>
120Extract data from pre-trained caffe model</h1>
121<p>One can find caffe <a href="https://github.com/BVLC/caffe/wiki/Model-Zoo">pre-trained models</a> on caffe's official github repository.</p>
Jenkinsb3a371b2018-05-23 11:36:53 +0100122<p>The caffe_data_extractor.py provided in the scripts folder is an example script that shows how to extract the parameter values from a trained model.</p>
Kaizen8938bd32017-09-28 14:38:23 +0100123<dl class="section note"><dt>Note</dt><dd>complex networks might require altering the script to properly work.</dd></dl>
124<h2><a class="anchor" id="caffe_how_to"></a>
125How to use the script</h2>
126<p>Install caffe following <a href="http://caffe.berkeleyvision.org/installation.html">caffe's document</a>. Make sure the pycaffe has been added into the PYTHONPATH.</p>
127<p>Download the pre-trained caffe model.</p>
Jenkinsb3a371b2018-05-23 11:36:53 +0100128<p>Run the caffe_data_extractor.py script by </p><pre class="fragment"> python caffe_data_extractor.py -m &lt;caffe model&gt; -n &lt;caffe netlist&gt;
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000129</pre><p>For example, to extract the data from pre-trained caffe Alex model to binary file: </p><pre class="fragment"> python caffe_data_extractor.py -m /path/to/bvlc_alexnet.caffemodel -n /path/to/caffe/models/bvlc_alexnet/deploy.prototxt
Kaizen8938bd32017-09-28 14:38:23 +0100130</pre><p>The script has been tested under Python2.7.</p>
131<h2><a class="anchor" id="caffe_result"></a>
132What is the expected output from the script</h2>
133<p>If the script runs successfully, it prints the names and shapes of each layer onto the standard output and generates *.npy files containing the weights and biases of each layer.</p>
Jenkins514be652019-02-28 12:25:18 +0000134<p>The <a class="el" href="namespacearm__compute_1_1utils.xhtml#af214346f90d640ac468dd90fa2a275cc" title="Load the tensor with pre-trained data from a binary file.">arm_compute::utils::load_trained_data</a> shows how one could load the weights and biases into tensor from the .npy file by the help of Accessor.</p>
Kaizen8938bd32017-09-28 14:38:23 +0100135<h1><a class="anchor" id="tensorflow_data_extractor"></a>
136Extract data from pre-trained tensorflow model</h1>
Jenkinsb3a371b2018-05-23 11:36:53 +0100137<p>The script tensorflow_data_extractor.py extracts trainable parameters (e.g. values of weights and biases) from a trained tensorflow model. A tensorflow model consists of the following two files:</p>
Kaizen8938bd32017-09-28 14:38:23 +0100138<p>{model_name}.data-{step}-{global_step}: A binary file containing values of each variable.</p>
139<p>{model_name}.meta: A binary file containing a MetaGraph struct which defines the graph structure of the neural network.</p>
140<dl class="section note"><dt>Note</dt><dd>Since Tensorflow version 0.11 the binary checkpoint file which contains the values for each parameter has the format of: {model_name}.data-{step}-of-{max_step} instead of: {model_name}.ckpt When dealing with binary files with version &gt;= 0.11, only pass {model_name} to -m option; when dealing with binary files with version &lt; 0.11, pass the whole file name {model_name}.ckpt to -m option.</dd>
141<dd>
142This script relies on the parameters to be extracted being in the 'trainable_variables' tensor collection. By default all variables are automatically added to this collection unless specified otherwise by the user. Thus should a user alter this default behavior and/or want to extract parameters from other collections, tf.GraphKeys.TRAINABLE_VARIABLES should be replaced accordingly.</dd></dl>
143<h2><a class="anchor" id="tensorflow_how_to"></a>
144How to use the script</h2>
145<p>Install tensorflow and numpy.</p>
146<p>Download the pre-trained tensorflow model.</p>
Jenkinsb3a371b2018-05-23 11:36:53 +0100147<p>Run tensorflow_data_extractor.py with </p><pre class="fragment"> python tensorflow_data_extractor -m &lt;path_to_binary_checkpoint_file&gt; -n &lt;path_to_metagraph_file&gt;
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000148</pre><p>For example, to extract the data from pre-trained tensorflow Alex model to binary files: </p><pre class="fragment"> python tensorflow_data_extractor -m /path/to/bvlc_alexnet -n /path/to/bvlc_alexnet.meta
149</pre><p>Or for binary checkpoint files before Tensorflow 0.11: </p><pre class="fragment"> python tensorflow_data_extractor -m /path/to/bvlc_alexnet.ckpt -n /path/to/bvlc_alexnet.meta
Kaizen8938bd32017-09-28 14:38:23 +0100150</pre><dl class="section note"><dt>Note</dt><dd>with versions &gt;= Tensorflow 0.11 only model name is passed to the -m option</dd></dl>
151<p>The script has been tested with Tensorflow 1.2, 1.3 on Python 2.7.6 and Python 3.4.3.</p>
152<h2><a class="anchor" id="tensorflow_result"></a>
153What is the expected output from the script</h2>
154<p>If the script runs successfully, it prints the names and shapes of each parameter onto the standard output and generates .npy files containing the weights and biases of each layer.</p>
Jenkins514be652019-02-28 12:25:18 +0000155<p>The <a class="el" href="namespacearm__compute_1_1utils.xhtml#af214346f90d640ac468dd90fa2a275cc" title="Load the tensor with pre-trained data from a binary file.">arm_compute::utils::load_trained_data</a> shows how one could load the weights and biases into tensor from the .npy file by the help of Accessor.</p>
156<h1><a class="anchor" id="tf_frozen_model_extractor"></a>
157Extract data from pre-trained frozen tensorflow model</h1>
158<p>The script tf_frozen_model_extractor.py extracts trainable parameters (e.g. values of weights and biases) from a frozen trained Tensorflow model.</p>
159<h2><a class="anchor" id="tensorflow_frozen_how_to"></a>
160How to use the script</h2>
161<p>Install Tensorflow and NumPy.</p>
162<p>Download the pre-trained Tensorflow model and freeze the model using the architecture and the checkpoint file.</p>
163<p>Run tf_frozen_model_extractor.py with </p><pre class="fragment"> python tf_frozen_model_extractor -m &lt;path_to_frozen_pb_model_file&gt; -d &lt;path_to_store_parameters&gt;
164</pre><p>For example, to extract the data from pre-trained Tensorflow model to binary files: </p><pre class="fragment"> python tf_frozen_model_extractor -m /path/to/inceptionv3.pb -d ./data
165</pre><h2><a class="anchor" id="tensorflow_frozen_result"></a>
166What is the expected output from the script</h2>
167<p>If the script runs successfully, it prints the names and shapes of each parameter onto the standard output and generates .npy files containing the weights and biases of each layer.</p>
168<p>The <a class="el" href="namespacearm__compute_1_1utils.xhtml#af214346f90d640ac468dd90fa2a275cc" title="Load the tensor with pre-trained data from a binary file.">arm_compute::utils::load_trained_data</a> shows how one could load the weights and biases into tensor from the .npy file by the help of Accessor.</p>
169<h1><a class="anchor" id="validate_examples"></a>
170Validating examples</h1>
171<p>Using one of the provided scripts will generate files containing the trainable parameters.</p>
172<p>You can validate a given graph example on a list of inputs by running: </p><pre class="fragment">LD_LIBRARY_PATH=lib ./&lt;graph_example&gt; --validation-range='&lt;validation_range&gt;' --validation-file='&lt;validation_file&gt;' --validation-path='/path/to/test/images/' --data='/path/to/weights/'
173</pre><p>e.g:</p>
174<p>LD_LIBRARY_PATH=lib ./bin/graph_alexnet &ndash;target=CL &ndash;layout=NHWC &ndash;type=F32 &ndash;threads=4 &ndash;validation-range='16666,24998' &ndash;validation-file='val.txt' &ndash;validation-path='images/' &ndash;data='data/'</p>
175<p>where: validation file is a plain document containing a list of images along with their expected label value. e.g: </p><pre class="fragment">val_00000001.JPEG 65
176val_00000002.JPEG 970
177val_00000003.JPEG 230
178val_00000004.JPEG 809
179val_00000005.JPEG 516
180</pre><p>&ndash;validation-range is the index range of the images within the validation file you want to check: e.g:</p>
181<p>&ndash;validation-range='100,200' will validate 100 images starting from 100th one in the validation file.</p>
182<p>This can be useful when parallelizing the validation process is needed. </p>
183</div></div><!-- PageDoc -->
184</div><!-- contents -->
Kaizen8938bd32017-09-28 14:38:23 +0100185</div><!-- doc-content -->
186<!-- start footer part -->
187<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
188 <ul>
Jenkins7f09cf72020-01-22 18:08:16 +0000189 <li class="footer">Generated on Wed Jan 22 2020 18:07:49 for Compute Library by
Kaizen8938bd32017-09-28 14:38:23 +0100190 <a href="http://www.doxygen.org/index.html">
Jenkins514be652019-02-28 12:25:18 +0000191 <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.15 </li>
Kaizen8938bd32017-09-28 14:38:23 +0100192 </ul>
193</div>
194</body>
195</html>