Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 1 | <!-- HTML header for doxygen 1.8.9.1--> |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 4 | <head> |
| 5 | <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> |
| 6 | <meta http-equiv="X-UA-Compatible" content="IE=9"/> |
| 7 | <meta name="generator" content="Doxygen 1.8.6"/> |
| 8 | <meta name="robots" content="NOINDEX, NOFOLLOW" /> <!-- Prevent indexing by search engines --> |
| 9 | <title>Compute Library: Importing data from existing models</title> |
| 10 | <link href="tabs.css" rel="stylesheet" type="text/css"/> |
| 11 | <script type="text/javascript" src="jquery.js"></script> |
| 12 | <script type="text/javascript" src="dynsections.js"></script> |
| 13 | <link href="navtree.css" rel="stylesheet" type="text/css"/> |
| 14 | <script type="text/javascript" src="resize.js"></script> |
| 15 | <script type="text/javascript" src="navtree.js"></script> |
| 16 | <script type="text/javascript"> |
| 17 | $(document).ready(initResizable); |
| 18 | $(window).load(resizeHeight); |
| 19 | </script> |
| 20 | <link href="search/search.css" rel="stylesheet" type="text/css"/> |
| 21 | <script type="text/javascript" src="search/search.js"></script> |
| 22 | <script type="text/javascript"> |
| 23 | $(document).ready(function() { searchBox.OnSelectItem(0); }); |
| 24 | </script> |
| 25 | <script type="text/x-mathjax-config"> |
| 26 | MathJax.Hub.Config({ |
| 27 | extensions: ["tex2jax.js"], |
| 28 | jax: ["input/TeX","output/HTML-CSS"], |
| 29 | }); |
| 30 | </script><script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js"></script> |
| 31 | <link href="doxygen.css" rel="stylesheet" type="text/css" /> |
| 32 | </head> |
| 33 | <body> |
| 34 | <div id="top"><!-- do not remove this div, it is closed by doxygen! --> |
| 35 | <div id="titlearea"> |
| 36 | <table cellspacing="0" cellpadding="0"> |
| 37 | <tbody> |
| 38 | <tr style="height: 56px;"> |
| 39 | <td style="padding-left: 0.5em;"> |
| 40 | <div id="projectname">Compute Library |
Kaizen | bf8b01d | 2017-10-12 14:26:51 +0100 | [diff] [blame] | 41 |  <span id="projectnumber">17.10</span> |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 42 | </div> |
| 43 | </td> |
| 44 | </tr> |
| 45 | </tbody> |
| 46 | </table> |
| 47 | </div> |
| 48 | <!-- end header part --> |
| 49 | <!-- Generated by Doxygen 1.8.6 --> |
| 50 | <script type="text/javascript"> |
| 51 | var searchBox = new SearchBox("searchBox", "search",false,'Search'); |
| 52 | </script> |
| 53 | <div id="navrow1" class="tabs"> |
| 54 | <ul class="tablist"> |
| 55 | <li><a href="index.xhtml"><span>Main Page</span></a></li> |
| 56 | <li class="current"><a href="pages.xhtml"><span>Related Pages</span></a></li> |
| 57 | <li><a href="namespaces.xhtml"><span>Namespaces</span></a></li> |
| 58 | <li><a href="annotated.xhtml"><span>Data Structures</span></a></li> |
| 59 | <li><a href="files.xhtml"><span>Files</span></a></li> |
| 60 | <li> |
| 61 | <div id="MSearchBox" class="MSearchBoxInactive"> |
| 62 | <span class="left"> |
| 63 | <img id="MSearchSelect" src="search/mag_sel.png" |
| 64 | onmouseover="return searchBox.OnSearchSelectShow()" |
| 65 | onmouseout="return searchBox.OnSearchSelectHide()" |
| 66 | alt=""/> |
| 67 | <input type="text" id="MSearchField" value="Search" accesskey="S" |
| 68 | onfocus="searchBox.OnSearchFieldFocus(true)" |
| 69 | onblur="searchBox.OnSearchFieldFocus(false)" |
| 70 | onkeyup="searchBox.OnSearchFieldChange(event)"/> |
| 71 | </span><span class="right"> |
| 72 | <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a> |
| 73 | </span> |
| 74 | </div> |
| 75 | </li> |
| 76 | </ul> |
| 77 | </div> |
| 78 | </div><!-- top --> |
| 79 | <div id="side-nav" class="ui-resizable side-nav-resizable"> |
| 80 | <div id="nav-tree"> |
| 81 | <div id="nav-tree-contents"> |
| 82 | <div id="nav-sync" class="sync"></div> |
| 83 | </div> |
| 84 | </div> |
| 85 | <div id="splitbar" style="-moz-user-select:none;" |
| 86 | class="ui-resizable-handle"> |
| 87 | </div> |
| 88 | </div> |
| 89 | <script type="text/javascript"> |
| 90 | $(document).ready(function(){initNavTree('data_import.xhtml','');}); |
| 91 | </script> |
| 92 | <div id="doc-content"> |
| 93 | <!-- window showing the filter options --> |
| 94 | <div id="MSearchSelectWindow" |
| 95 | onmouseover="return searchBox.OnSearchSelectShow()" |
| 96 | onmouseout="return searchBox.OnSearchSelectHide()" |
| 97 | onkeydown="return searchBox.OnSearchSelectKey(event)"> |
| 98 | <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark"> </span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark"> </span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(11)"><span class="SelectionMark"> </span>Pages</a></div> |
| 99 | |
| 100 | <!-- iframe showing the search results (closed by default) --> |
| 101 | <div id="MSearchResultsWindow"> |
| 102 | <iframe src="javascript:void(0)" frameborder="0" |
| 103 | name="MSearchResults" id="MSearchResults"> |
| 104 | </iframe> |
| 105 | </div> |
| 106 | |
| 107 | <div class="header"> |
| 108 | <div class="headertitle"> |
| 109 | <div class="title">Importing data from existing models </div> </div> |
| 110 | </div><!--header--> |
| 111 | <div class="contents"> |
| 112 | <div class="toc"><h3>Table of Contents</h3> |
| 113 | <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> |
| 114 | <li class="level2"><a href="#caffe_result">What is the expected output from the script</a></li> |
| 115 | </ul> |
| 116 | </li> |
| 117 | <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> |
| 118 | <li class="level2"><a href="#tensorflow_result">What is the expected output from the script</a></li> |
| 119 | </ul> |
| 120 | </li> |
| 121 | </ul> |
| 122 | </div> |
| 123 | <div class="textblock"><h1><a class="anchor" id="caffe_data_extractor"></a> |
| 124 | Extract data from pre-trained caffe model</h1> |
| 125 | <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> |
| 126 | <p>The <a class="el" href="caffe__data__extractor_8py.xhtml">caffe_data_extractor.py</a> provided in the <a class="el" href="dir_2bdd315ee2dbfd8cefe64730e37333fd.xhtml">scripts</a> folder is an example script that shows how to extract the parameter values from a trained model.</p> |
| 127 | <dl class="section note"><dt>Note</dt><dd>complex networks might require altering the script to properly work.</dd></dl> |
| 128 | <h2><a class="anchor" id="caffe_how_to"></a> |
| 129 | How to use the script</h2> |
| 130 | <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> |
| 131 | <p>Download the pre-trained caffe model.</p> |
| 132 | <p>Run the <a class="el" href="caffe__data__extractor_8py.xhtml">caffe_data_extractor.py</a> script by </p> |
| 133 | <pre class="fragment"> python caffe_data_extractor.py -m <caffe model> -n <caffe netlist> |
| 134 | </pre><p>For example, to extract the data from pre-trained caffe Alex model to binary file: </p> |
| 135 | <pre class="fragment"> python caffe_data_extractor.py -m /path/to/bvlc_alexnet.caffemodel -n /path/to/caffe/models/bvlc_alexnet/deploy.prototxt |
| 136 | </pre><p>The script has been tested under Python2.7.</p> |
| 137 | <h2><a class="anchor" id="caffe_result"></a> |
| 138 | What is the expected output from the script</h2> |
| 139 | <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> |
| 140 | <p>The <a class="el" href="namespacearm__compute_1_1utils.xhtml#af214346f90d640ac468dd90fa2a275cc">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> |
| 141 | <h1><a class="anchor" id="tensorflow_data_extractor"></a> |
| 142 | Extract data from pre-trained tensorflow model</h1> |
| 143 | <p>The script <a class="el" href="tensorflow__data__extractor_8py.xhtml">tensorflow_data_extractor.py</a> 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> |
| 144 | <p>{model_name}.data-{step}-{global_step}: A binary file containing values of each variable.</p> |
| 145 | <p>{model_name}.meta: A binary file containing a MetaGraph struct which defines the graph structure of the neural network.</p> |
| 146 | <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 >= 0.11, only pass {model_name} to -m option; when dealing with binary files with version < 0.11, pass the whole file name {model_name}.ckpt to -m option.</dd> |
| 147 | <dd> |
| 148 | This 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> |
| 149 | <h2><a class="anchor" id="tensorflow_how_to"></a> |
| 150 | How to use the script</h2> |
| 151 | <p>Install tensorflow and numpy.</p> |
| 152 | <p>Download the pre-trained tensorflow model.</p> |
| 153 | <p>Run <a class="el" href="tensorflow__data__extractor_8py.xhtml">tensorflow_data_extractor.py</a> with </p> |
| 154 | <pre class="fragment"> python tensorflow_data_extractor -m <path_to_binary_checkpoint_file> -n <path_to_metagraph_file> |
| 155 | </pre><p>For example, to extract the data from pre-trained tensorflow Alex model to binary files: </p> |
| 156 | <pre class="fragment"> python tensorflow_data_extractor -m /path/to/bvlc_alexnet -n /path/to/bvlc_alexnet.meta |
| 157 | </pre><p>Or for binary checkpoint files before Tensorflow 0.11: </p> |
| 158 | <pre class="fragment"> python tensorflow_data_extractor -m /path/to/bvlc_alexnet.ckpt -n /path/to/bvlc_alexnet.meta |
| 159 | </pre><dl class="section note"><dt>Note</dt><dd>with versions >= Tensorflow 0.11 only model name is passed to the -m option</dd></dl> |
| 160 | <p>The script has been tested with Tensorflow 1.2, 1.3 on Python 2.7.6 and Python 3.4.3.</p> |
| 161 | <h2><a class="anchor" id="tensorflow_result"></a> |
| 162 | What is the expected output from the script</h2> |
| 163 | <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> |
| 164 | <p>The <a class="el" href="namespacearm__compute_1_1utils.xhtml#af214346f90d640ac468dd90fa2a275cc">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> |
| 165 | </div></div><!-- contents --> |
| 166 | </div><!-- doc-content --> |
| 167 | <!-- start footer part --> |
| 168 | <div id="nav-path" class="navpath"><!-- id is needed for treeview function! --> |
| 169 | <ul> |
Kaizen | bf8b01d | 2017-10-12 14:26:51 +0100 | [diff] [blame] | 170 | <li class="footer">Generated on Thu Oct 12 2017 14:26:35 for Compute Library by |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 171 | <a href="http://www.doxygen.org/index.html"> |
| 172 | <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6 </li> |
| 173 | </ul> |
| 174 | </div> |
| 175 | </body> |
| 176 | </html> |