blob: 328e6a7851452e89be8c54a77a2b551c18bd9fb4 [file] [log] [blame]
Kaizen8938bd32017-09-28 14:38:23 +01001<!-- 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"/>
Jenkinsb9abeae2018-11-22 11:58:08 +00007<meta name="generator" content="Doxygen 1.8.13"/>
Kaizen8938bd32017-09-28 14:38:23 +01008<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 Barbier8140e1e2017-12-14 23:48:46 +000015<script type="text/javascript" src="navtreedata.js"></script>
Kaizen8938bd32017-09-28 14:38:23 +010016<script type="text/javascript" src="navtree.js"></script>
17<script type="text/javascript">
18 $(document).ready(initResizable);
Kaizen8938bd32017-09-28 14:38:23 +010019</script>
20<link href="search/search.css" rel="stylesheet" type="text/css"/>
Anthony Barbier8140e1e2017-12-14 23:48:46 +000021<script type="text/javascript" src="search/searchdata.js"></script>
Kaizen8938bd32017-09-28 14:38:23 +010022<script type="text/javascript" src="search/search.js"></script>
Kaizen8938bd32017-09-28 14:38:23 +010023<script type="text/x-mathjax-config">
24 MathJax.Hub.Config({
25 extensions: ["tex2jax.js"],
26 jax: ["input/TeX","output/HTML-CSS"],
27});
Anthony Barbier8140e1e2017-12-14 23:48:46 +000028</script><script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
Kaizen8938bd32017-09-28 14:38:23 +010029<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
Jenkinsb9abeae2018-11-22 11:58:08 +000039 &#160;<span id="projectnumber">18.11</span>
Kaizen8938bd32017-09-28 14:38:23 +010040 </div>
41 </td>
42 </tr>
43 </tbody>
44</table>
45</div>
46<!-- end header part -->
Jenkinsb9abeae2018-11-22 11:58:08 +000047<!-- Generated by Doxygen 1.8.13 -->
Kaizen8938bd32017-09-28 14:38:23 +010048<script type="text/javascript">
49var searchBox = new SearchBox("searchBox", "search",false,'Search');
50</script>
Jenkinsb9abeae2018-11-22 11:58:08 +000051<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>
Kaizen8938bd32017-09-28 14:38:23 +010060</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 Barbier8140e1e2017-12-14 23:48:46 +000080</div>
Kaizen8938bd32017-09-28 14:38:23 +010081
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>
106Extract 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>
Jenkinsb3a371b2018-05-23 11:36:53 +0100108<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 +0100109<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>
111How 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>
Jenkinsb3a371b2018-05-23 11:36:53 +0100114<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 +0000115</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 +0100116</pre><p>The script has been tested under Python2.7.</p>
117<h2><a class="anchor" id="caffe_result"></a>
118What 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>
Jenkinsb3a371b2018-05-23 11:36:53 +0100120<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 +0100121<h1><a class="anchor" id="tensorflow_data_extractor"></a>
122Extract data from pre-trained tensorflow model</h1>
Jenkinsb3a371b2018-05-23 11:36:53 +0100123<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 +0100124<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 &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>
127<dd>
128This 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>
130How to use the script</h2>
131<p>Install tensorflow and numpy.</p>
132<p>Download the pre-trained tensorflow model.</p>
Jenkinsb3a371b2018-05-23 11:36:53 +0100133<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 +0000134</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
Kaizen8938bd32017-09-28 14:38:23 +0100136</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>
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>
139What 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>
Jenkinsb3a371b2018-05-23 11:36:53 +0100141<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 +0100142</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>
Jenkinsb9abeae2018-11-22 11:58:08 +0000147 <li class="footer">Generated on Thu Nov 22 2018 11:57:44 for Compute Library by
Kaizen8938bd32017-09-28 14:38:23 +0100148 <a href="http://www.doxygen.org/index.html">
Jenkinsb9abeae2018-11-22 11:58:08 +0000149 <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li>
Kaizen8938bd32017-09-28 14:38:23 +0100150 </ul>
151</div>
152</body>
153</html>