<spanid="average-meter"></span><h2>Average Meter<aclass="headerlink"href="#module-torchreid.utils.avgmeter"title="Permalink to this headline">¶</a></h2>
<dlclass="class">
<dtid="torchreid.utils.avgmeter.AverageMeter">
<emclass="property">class </em><codeclass="descclassname">torchreid.utils.avgmeter.</code><codeclass="descname">AverageMeter</code><aclass="reference internal"href="../_modules/torchreid/utils/avgmeter.html#AverageMeter"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.avgmeter.AverageMeter"title="Permalink to this definition">¶</a></dt>
<dd><p>Computes and stores the average and current value.</p>
<dlclass="docutils">
<dt>Examples::</dt>
<dd><divclass="first last highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="gp">>>></span><spanclass="c1"># Initialize a meter to record loss</span>
<spanid="loggers"></span><h2>Loggers<aclass="headerlink"href="#module-torchreid.utils.loggers"title="Permalink to this headline">¶</a></h2>
<dlclass="class">
<dtid="torchreid.utils.loggers.Logger">
<emclass="property">class </em><codeclass="descclassname">torchreid.utils.loggers.</code><codeclass="descname">Logger</code><spanclass="sig-paren">(</span><em>fpath=None</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/loggers.html#Logger"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.loggers.Logger"title="Permalink to this definition">¶</a></dt>
<dd><p>Writes console output to external text file.</p>
<p>Imported from <aclass="reference external"href="https://github.com/Cysu/open-reid/blob/master/reid/utils/logging.py">https://github.com/Cysu/open-reid/blob/master/reid/utils/logging.py</a></p>
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><strong>fpath</strong> (<em>str</em>) – directory to save logging file.</td>
<dd><divclass="first last highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="gp">>>></span><spanclass="kn">import</span><spanclass="nn">sys</span>
<emclass="property">class </em><codeclass="descclassname">torchreid.utils.loggers.</code><codeclass="descname">RankLogger</code><spanclass="sig-paren">(</span><em>sources</em>, <em>targets</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/loggers.html#RankLogger"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.loggers.RankLogger"title="Permalink to this definition">¶</a></dt>
<dd><p>Records the rank1 matching accuracy obtained for each
test dataset at specified evaluation steps and provides a function
to show the summarized results, which are convenient for analysis.</p>
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><ulclass="first last simple">
<li><strong>sources</strong> (<em>str</em><em> or </em><em>list</em>) – source dataset name(s).</li>
<li><strong>targets</strong> (<em>str</em><em> or </em><em>list</em>) – target dataset name(s).</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dlclass="docutils">
<dt>Examples::</dt>
<dd><divclass="first last highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="gp">>>></span><spanclass="kn">from</span><spanclass="nn">torchreid.utils</span><spanclass="k">import</span><spanclass="n">RankLogger</span>
<codeclass="descname">show_summary</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/loggers.html#RankLogger.show_summary"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.loggers.RankLogger.show_summary"title="Permalink to this definition">¶</a></dt>
<dd><p>Shows saved results.</p>
</dd></dl>
<dlclass="method">
<dtid="torchreid.utils.loggers.RankLogger.write">
<codeclass="descname">write</code><spanclass="sig-paren">(</span><em>name</em>, <em>epoch</em>, <em>rank1</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/loggers.html#RankLogger.write"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.loggers.RankLogger.write"title="Permalink to this definition">¶</a></dt>
<spanid="generic-tools"></span><h2>Generic Tools<aclass="headerlink"href="#module-torchreid.utils.tools"title="Permalink to this headline">¶</a></h2>
<dlclass="function">
<dtid="torchreid.utils.tools.mkdir_if_missing">
<codeclass="descclassname">torchreid.utils.tools.</code><codeclass="descname">mkdir_if_missing</code><spanclass="sig-paren">(</span><em>dirname</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/tools.html#mkdir_if_missing"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.tools.mkdir_if_missing"title="Permalink to this definition">¶</a></dt>
<dd><p>Creates dirname if it is missing.</p>
</dd></dl>
<dlclass="function">
<dtid="torchreid.utils.tools.check_isfile">
<codeclass="descclassname">torchreid.utils.tools.</code><codeclass="descname">check_isfile</code><spanclass="sig-paren">(</span><em>fpath</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/tools.html#check_isfile"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.tools.check_isfile"title="Permalink to this definition">¶</a></dt>
<codeclass="descclassname">torchreid.utils.tools.</code><codeclass="descname">read_json</code><spanclass="sig-paren">(</span><em>fpath</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/tools.html#read_json"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.tools.read_json"title="Permalink to this definition">¶</a></dt>
<dd><p>Reads json file from a path.</p>
</dd></dl>
<dlclass="function">
<dtid="torchreid.utils.tools.write_json">
<codeclass="descclassname">torchreid.utils.tools.</code><codeclass="descname">write_json</code><spanclass="sig-paren">(</span><em>obj</em>, <em>fpath</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/tools.html#write_json"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.tools.write_json"title="Permalink to this definition">¶</a></dt>
<dd><p>Writes to a json file.</p>
</dd></dl>
<dlclass="function">
<dtid="torchreid.utils.tools.download_url">
<codeclass="descclassname">torchreid.utils.tools.</code><codeclass="descname">download_url</code><spanclass="sig-paren">(</span><em>url</em>, <em>dst</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/tools.html#download_url"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.tools.download_url"title="Permalink to this definition">¶</a></dt>
<dd><p>Downloads file from a url to a destination.</p>
<codeclass="descclassname">torchreid.utils.tools.</code><codeclass="descname">read_image</code><spanclass="sig-paren">(</span><em>path</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/tools.html#read_image"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.tools.read_image"title="Permalink to this definition">¶</a></dt>
<dd><p>Reads image from path using <codeclass="docutils literal notranslate"><spanclass="pre">PIL.Image</span></code>.</p>
<codeclass="descclassname">torchreid.utils.tools.</code><codeclass="descname">collect_env_info</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/tools.html#collect_env_info"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.tools.collect_env_info"title="Permalink to this definition">¶</a></dt>
<codeclass="descclassname">torchreid.utils.reidtools.</code><codeclass="descname">visualize_ranked_results</code><spanclass="sig-paren">(</span><em>distmat</em>, <em>dataset</em>, <em>save_dir=''</em>, <em>topk=20</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/reidtools.html#visualize_ranked_results"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.reidtools.visualize_ranked_results"title="Permalink to this definition">¶</a></dt>
<codeclass="descclassname">torchreid.utils.torchtools.</code><codeclass="descname">save_checkpoint</code><spanclass="sig-paren">(</span><em>state</em>, <em>save_dir</em>, <em>is_best=False</em>, <em>remove_module_from_keys=False</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/torchtools.html#save_checkpoint"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.torchtools.save_checkpoint"title="Permalink to this definition">¶</a></dt>
<li><strong>remove_module_from_keys</strong> (<em>bool</em><em>, </em><em>optional</em>) – whether to remove “module.”
from layer names. Default is False.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dlclass="docutils">
<dt>Examples::</dt>
<dd><divclass="first last highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="gp">>>></span><spanclass="n">state</span><spanclass="o">=</span><spanclass="p">{</span>
<codeclass="descclassname">torchreid.utils.torchtools.</code><codeclass="descname">load_checkpoint</code><spanclass="sig-paren">(</span><em>fpath</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/torchtools.html#load_checkpoint"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.torchtools.load_checkpoint"title="Permalink to this definition">¶</a></dt>
<dd><p>Loads checkpoint.</p>
<p><codeclass="docutils literal notranslate"><spanclass="pre">UnicodeDecodeError</span></code> can be well handled, which means
<dd><divclass="first last highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="gp">>>></span><spanclass="kn">from</span><spanclass="nn">torchreid.utils</span><spanclass="k">import</span><spanclass="n">load_checkpoint</span>
<codeclass="descclassname">torchreid.utils.torchtools.</code><codeclass="descname">resume_from_checkpoint</code><spanclass="sig-paren">(</span><em>fpath</em>, <em>model</em>, <em>optimizer=None</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/torchtools.html#resume_from_checkpoint"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.torchtools.resume_from_checkpoint"title="Permalink to this definition">¶</a></dt>
<dd><p>Resumes training from a checkpoint.</p>
<p>This will load (1) model weights and (2) <codeclass="docutils literal notranslate"><spanclass="pre">state_dict</span></code>
of optimizer if <codeclass="docutils literal notranslate"><spanclass="pre">optimizer</span></code> is not None.</p>
<dd><divclass="first last highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="gp">>>></span><spanclass="kn">from</span><spanclass="nn">torchreid.utils</span><spanclass="k">import</span><spanclass="n">resume_from_checkpoint</span>
<codeclass="descclassname">torchreid.utils.torchtools.</code><codeclass="descname">open_all_layers</code><spanclass="sig-paren">(</span><em>model</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/torchtools.html#open_all_layers"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.torchtools.open_all_layers"title="Permalink to this definition">¶</a></dt>
<dd><p>Opens all layers in model for training.</p>
<dlclass="docutils">
<dt>Examples::</dt>
<dd><divclass="first last highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="gp">>>></span><spanclass="kn">from</span><spanclass="nn">torchreid.utils</span><spanclass="k">import</span><spanclass="n">open_all_layers</span>
<codeclass="descclassname">torchreid.utils.torchtools.</code><codeclass="descname">open_specified_layers</code><spanclass="sig-paren">(</span><em>model</em>, <em>open_layers</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/torchtools.html#open_specified_layers"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.torchtools.open_specified_layers"title="Permalink to this definition">¶</a></dt>
<dd><p>Opens specified layers in model for training while keeping
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><ulclass="first last simple">
<li><strong>model</strong> (<em>nn.Module</em>) – neural net model.</li>
<li><strong>open_layers</strong> (<em>str</em><em> or </em><em>list</em>) – layers open for training.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dlclass="docutils">
<dt>Examples::</dt>
<dd><divclass="first last highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="gp">>>></span><spanclass="kn">from</span><spanclass="nn">torchreid.utils</span><spanclass="k">import</span><spanclass="n">open_specified_layers</span>
<spanclass="gp">>>></span><spanclass="c1"># Only model.classifier will be updated.</span>
<codeclass="descclassname">torchreid.utils.torchtools.</code><codeclass="descname">count_num_param</code><spanclass="sig-paren">(</span><em>model</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/torchtools.html#count_num_param"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.torchtools.count_num_param"title="Permalink to this definition">¶</a></dt>
<dd><p>Counts number of parameters in a model while ignoring <codeclass="docutils literal notranslate"><spanclass="pre">self.classifier</span></code>.</p>
<dd><divclass="first last highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="gp">>>></span><spanclass="kn">from</span><spanclass="nn">torchreid.utils</span><spanclass="k">import</span><spanclass="n">count_num_param</span>
<codeclass="descclassname">torchreid.utils.torchtools.</code><codeclass="descname">load_pretrained_weights</code><spanclass="sig-paren">(</span><em>model</em>, <em>weight_path</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/torchtools.html#load_pretrained_weights"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.torchtools.load_pretrained_weights"title="Permalink to this definition">¶</a></dt>
<dd><p>Loads pretrianed weights to model.</p>
<dlclass="docutils">
<dt>Features::</dt>
<dd><ulclass="first last simple">
<li>Incompatible layers (unmatched in name or size) will be ignored.</li>
<li>Can automatically deal with keys containing “module.”.</li>
<li><strong>weight_path</strong> (<em>str</em>) – path to pretrained weights.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dlclass="docutils">
<dt>Examples::</dt>
<dd><divclass="first last highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="gp">>>></span><spanclass="kn">from</span><spanclass="nn">torchreid.utils</span><spanclass="k">import</span><spanclass="n">load_pretrained_weights</span>
<codeclass="descclassname">torchreid.utils.model_complexity.</code><codeclass="descname">compute_model_complexity</code><spanclass="sig-paren">(</span><em>model</em>, <em>input_size</em>, <em>verbose=False</em>, <em>only_conv_linear=True</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/utils/model_complexity.html#compute_model_complexity"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.utils.model_complexity.compute_model_complexity"title="Permalink to this definition">¶</a></dt>
<dd><p>Returns number of parameters and FLOPs.</p>
<li><strong>input_size</strong> (<em>tuple</em>) – input size, e.g. (1, 3, 256, 128).</li>
<li><strong>verbose</strong> (<em>bool</em><em>, </em><em>optional</em>) – shows detailed complexity of
each module. Default is False.</li>
<li><strong>only_conv_linear</strong> (<em>bool</em><em>, </em><em>optional</em>) – only considers convolution
and linear layers when counting flops. Default is True.
If set to False, flops of all layers will be counted.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<dlclass="docutils">
<dt>Examples::</dt>
<dd><divclass="first last highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="gp">>>></span><spanclass="kn">from</span><spanclass="nn">torchreid</span><spanclass="k">import</span><spanclass="n">models</span><spanclass="p">,</span><spanclass="n">utils</span>
Built with <ahref="http://sphinx-doc.org/">Sphinx</a> using a <ahref="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <ahref="https://readthedocs.org">Read the Docs</a>.