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"/> |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame^] | 7 | <meta name="generator" content="Doxygen 1.8.13"/> |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 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> |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 15 | <script type="text/javascript" src="navtreedata.js"></script> |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 16 | <script type="text/javascript" src="navtree.js"></script> |
| 17 | <script type="text/javascript"> |
| 18 | $(document).ready(initResizable); |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 19 | </script> |
| 20 | <link href="search/search.css" rel="stylesheet" type="text/css"/> |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 21 | <script type="text/javascript" src="search/searchdata.js"></script> |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 22 | <script type="text/javascript" src="search/search.js"></script> |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 23 | <script type="text/x-mathjax-config"> |
| 24 | MathJax.Hub.Config({ |
| 25 | extensions: ["tex2jax.js"], |
| 26 | jax: ["input/TeX","output/HTML-CSS"], |
| 27 | }); |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 28 | </script><script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js"></script> |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 29 | <link href="doxygen.css" rel="stylesheet" type="text/css" /> |
| 30 | </head> |
| 31 | <body> |
| 32 | <div id="top"><!-- do not remove this div, it is closed by doxygen! --> |
| 33 | <div id="titlearea"> |
| 34 | <table cellspacing="0" cellpadding="0"> |
| 35 | <tbody> |
| 36 | <tr style="height: 56px;"> |
| 37 | <td style="padding-left: 0.5em;"> |
| 38 | <div id="projectname">Compute Library |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame^] | 39 |  <span id="projectnumber">18.11</span> |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 40 | </div> |
| 41 | </td> |
| 42 | </tr> |
| 43 | </tbody> |
| 44 | </table> |
| 45 | </div> |
| 46 | <!-- end header part --> |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame^] | 47 | <!-- Generated by Doxygen 1.8.13 --> |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 48 | <script type="text/javascript"> |
| 49 | var searchBox = new SearchBox("searchBox", "search",false,'Search'); |
| 50 | </script> |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame^] | 51 | <script type="text/javascript" src="menudata.js"></script> |
| 52 | <script type="text/javascript" src="menu.js"></script> |
| 53 | <script type="text/javascript"> |
| 54 | $(function() { |
| 55 | initMenu('',true,false,'search.php','Search'); |
| 56 | $(document).ready(function() { init_search(); }); |
| 57 | }); |
| 58 | </script> |
| 59 | <div id="main-nav"></div> |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 60 | </div><!-- top --> |
| 61 | <div id="side-nav" class="ui-resizable side-nav-resizable"> |
| 62 | <div id="nav-tree"> |
| 63 | <div id="nav-tree-contents"> |
| 64 | <div id="nav-sync" class="sync"></div> |
| 65 | </div> |
| 66 | </div> |
| 67 | <div id="splitbar" style="-moz-user-select:none;" |
| 68 | class="ui-resizable-handle"> |
| 69 | </div> |
| 70 | </div> |
| 71 | <script type="text/javascript"> |
| 72 | $(document).ready(function(){initNavTree('data_import.xhtml','');}); |
| 73 | </script> |
| 74 | <div id="doc-content"> |
| 75 | <!-- window showing the filter options --> |
| 76 | <div id="MSearchSelectWindow" |
| 77 | onmouseover="return searchBox.OnSearchSelectShow()" |
| 78 | onmouseout="return searchBox.OnSearchSelectHide()" |
| 79 | onkeydown="return searchBox.OnSearchSelectKey(event)"> |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 80 | </div> |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 81 | |
| 82 | <!-- iframe showing the search results (closed by default) --> |
| 83 | <div id="MSearchResultsWindow"> |
| 84 | <iframe src="javascript:void(0)" frameborder="0" |
| 85 | name="MSearchResults" id="MSearchResults"> |
| 86 | </iframe> |
| 87 | </div> |
| 88 | |
| 89 | <div class="header"> |
| 90 | <div class="headertitle"> |
| 91 | <div class="title">Importing data from existing models </div> </div> |
| 92 | </div><!--header--> |
| 93 | <div class="contents"> |
| 94 | <div class="toc"><h3>Table of Contents</h3> |
| 95 | <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> |
| 96 | <li class="level2"><a href="#caffe_result">What is the expected output from the script</a></li> |
| 97 | </ul> |
| 98 | </li> |
| 99 | <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> |
| 100 | <li class="level2"><a href="#tensorflow_result">What is the expected output from the script</a></li> |
| 101 | </ul> |
| 102 | </li> |
| 103 | </ul> |
| 104 | </div> |
| 105 | <div class="textblock"><h1><a class="anchor" id="caffe_data_extractor"></a> |
| 106 | Extract data from pre-trained caffe model</h1> |
| 107 | <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> |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 108 | <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> |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 109 | <dl class="section note"><dt>Note</dt><dd>complex networks might require altering the script to properly work.</dd></dl> |
| 110 | <h2><a class="anchor" id="caffe_how_to"></a> |
| 111 | How to use the script</h2> |
| 112 | <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> |
| 113 | <p>Download the pre-trained caffe model.</p> |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 114 | <p>Run the caffe_data_extractor.py script by </p><pre class="fragment"> python caffe_data_extractor.py -m <caffe model> -n <caffe netlist> |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 115 | </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 |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 116 | </pre><p>The script has been tested under Python2.7.</p> |
| 117 | <h2><a class="anchor" id="caffe_result"></a> |
| 118 | What is the expected output from the script</h2> |
| 119 | <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> |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 120 | <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> |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 121 | <h1><a class="anchor" id="tensorflow_data_extractor"></a> |
| 122 | Extract data from pre-trained tensorflow model</h1> |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 123 | <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> |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 124 | <p>{model_name}.data-{step}-{global_step}: A binary file containing values of each variable.</p> |
| 125 | <p>{model_name}.meta: A binary file containing a MetaGraph struct which defines the graph structure of the neural network.</p> |
| 126 | <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> |
| 127 | <dd> |
| 128 | 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> |
| 129 | <h2><a class="anchor" id="tensorflow_how_to"></a> |
| 130 | How to use the script</h2> |
| 131 | <p>Install tensorflow and numpy.</p> |
| 132 | <p>Download the pre-trained tensorflow model.</p> |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 133 | <p>Run tensorflow_data_extractor.py with </p><pre class="fragment"> python tensorflow_data_extractor -m <path_to_binary_checkpoint_file> -n <path_to_metagraph_file> |
Anthony Barbier | 8140e1e | 2017-12-14 23:48:46 +0000 | [diff] [blame] | 134 | </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 |
| 135 | </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 |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 136 | </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> |
| 137 | <p>The script has been tested with Tensorflow 1.2, 1.3 on Python 2.7.6 and Python 3.4.3.</p> |
| 138 | <h2><a class="anchor" id="tensorflow_result"></a> |
| 139 | What is the expected output from the script</h2> |
| 140 | <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> |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 141 | <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> |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 142 | </div></div><!-- contents --> |
| 143 | </div><!-- doc-content --> |
| 144 | <!-- start footer part --> |
| 145 | <div id="nav-path" class="navpath"><!-- id is needed for treeview function! --> |
| 146 | <ul> |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame^] | 147 | <li class="footer">Generated on Thu Nov 22 2018 11:57:44 for Compute Library by |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 148 | <a href="http://www.doxygen.org/index.html"> |
Jenkins | b9abeae | 2018-11-22 11:58:08 +0000 | [diff] [blame^] | 149 | <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li> |
Kaizen | 8938bd3 | 2017-09-28 14:38:23 +0100 | [diff] [blame] | 150 | </ul> |
| 151 | </div> |
| 152 | </body> |
| 153 | </html> |