<spanid="id1"></span><h1>torchreid.engine<aclass="headerlink"href="#torchreid-engine"title="Permalink to this headline">¶</a></h1>
<divclass="section"id="base-engine">
<h2>Base Engine<aclass="headerlink"href="#base-engine"title="Permalink to this headline">¶</a></h2>
<dlclass="class">
<dtid="torchreid.engine.engine.Engine">
<emclass="property">class </em><codeclass="descclassname">torchreid.engine.engine.</code><codeclass="descname">Engine</code><spanclass="sig-paren">(</span><em>datamanager</em>, <em>model</em>, <em>optimizer=None</em>, <em>scheduler=None</em>, <em>use_cpu=False</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/engine/engine.html#Engine"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.engine.engine.Engine"title="Permalink to this definition">¶</a></dt>
<dd><p>A generic base Engine class for both image- and video-reid.</p>
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><ulclass="first last simple">
<li><strong>datamanager</strong> (<aclass="reference internal"href="data.html#torchreid.data.datamanager.DataManager"title="torchreid.data.datamanager.DataManager"><em>DataManager</em></a>) – an instance of <codeclass="docutils literal notranslate"><spanclass="pre">torchreid.data.ImageDataManager</span></code>
or <codeclass="docutils literal notranslate"><spanclass="pre">torchreid.data.VideoDataManager</span></code>.</li>
<li><strong>model</strong> (<em>nn.Module</em>) – model instance.</li>
<li><strong>optimizer</strong> (<em>Optimizer</em>) – an Optimizer.</li>
<li><strong>scheduler</strong> (<em>LRScheduler</em><em>, </em><em>optional</em>) – if None, no learning rate decay will be performed.</li>
<li><strong>use_cpu</strong> (<em>bool</em><em>, </em><em>optional</em>) – use cpu. Default is False.</li>
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><ulclass="first last simple">
<li><strong>save_dir</strong> (<em>str</em>) – directory to save model.</li>
<li><strong>max_epoch</strong> (<em>int</em>) – maximum epoch.</li>
<li><strong>start_epoch</strong> (<em>int</em><em>, </em><em>optional</em>) – starting epoch. Default is 0.</li>
<li><strong>fixbase_epoch</strong> (<em>int</em><em>, </em><em>optional</em>) – number of epochs to train <codeclass="docutils literal notranslate"><spanclass="pre">open_layers</span></code> (new layers)
in <codeclass="docutils literal notranslate"><spanclass="pre">max_epoch</span></code>.</li>
<li><strong>open_layers</strong> (<em>str</em><em> or </em><em>list</em><em>, </em><em>optional</em>) – layers (attribute names) open for training.</li>
<li><strong>start_eval</strong> (<em>int</em><em>, </em><em>optional</em>) – from which epoch to start evaluation. Default is 0.</li>
will be performed every test time, so it is recommended to enable <codeclass="docutils literal notranslate"><spanclass="pre">visrank</span></code> when
<codeclass="docutils literal notranslate"><spanclass="pre">test_only</span></code> is True. The ranked images will be saved to
“save_dir/ranks-epoch/dataset_name”, e.g. “save_dir/ranks-60/market1501”.</li>
<li><strong>visrank_topk</strong> (<em>int</em><em>, </em><em>optional</em>) – top-k ranked images to be visualized. Default is 20.</li>
<li><strong>use_metric_cuhk03</strong> (<em>bool</em><em>, </em><em>optional</em>) – use single-gallery-shot setting for cuhk03.
Default is False. This should be enabled when using cuhk03 classic split.</li>
<li><strong>ranks</strong> (<em>list</em><em>, </em><em>optional</em>) – cmc ranks to be computed. Default is [1, 5, 10, 20].</li>
<pclass="last">This function has been called in <codeclass="docutils literal notranslate"><spanclass="pre">run()</span></code> when necessary.</p>
</div>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<pclass="last">The test pipeline implemented in this function suits both image- and
video-reid. In general, a subclass of Engine only needs to re-implement
<codeclass="docutils literal notranslate"><spanclass="pre">_extract_features()</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">_parse_data_for_eval()</span></code> when necessary,
but not a must. Please refer to the source code for more details.</p>
will be performed every test time, so it is recommended to enable <codeclass="docutils literal notranslate"><spanclass="pre">visrank</span></code> when
<codeclass="docutils literal notranslate"><spanclass="pre">test_only</span></code> is True. The ranked images will be saved to
“save_dir/ranks-epoch/dataset_name”, e.g. “save_dir/ranks-60/market1501”.</li>
<li><strong>visrank_topk</strong> (<em>int</em><em>, </em><em>optional</em>) – top-k ranked images to be visualized. Default is 20.</li>
<li><strong>save_dir</strong> (<em>str</em>) – directory to save visualized results if <codeclass="docutils literal notranslate"><spanclass="pre">visrank</span></code> is True.</li>
<li><strong>use_metric_cuhk03</strong> (<em>bool</em><em>, </em><em>optional</em>) – use single-gallery-shot setting for cuhk03.
Default is False. This should be enabled when using cuhk03 classic split.</li>
<li><strong>ranks</strong> (<em>list</em><em>, </em><em>optional</em>) – cmc ranks to be computed. Default is [1, 5, 10, 20].</li>
<codeclass="descname">train</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/engine/engine.html#Engine.train"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.engine.engine.Engine.train"title="Permalink to this definition">¶</a></dt>
<dd><p>Performs training on source datasets for one epoch.</p>
<p>This will be called every epoch in <codeclass="docutils literal notranslate"><spanclass="pre">run()</span></code>, e.g.</p>
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><ulclass="first last simple">
<li><strong>datamanager</strong> (<aclass="reference internal"href="data.html#torchreid.data.datamanager.DataManager"title="torchreid.data.datamanager.DataManager"><em>DataManager</em></a>) – an instance of <codeclass="docutils literal notranslate"><spanclass="pre">torchreid.data.ImageDataManager</span></code>
or <codeclass="docutils literal notranslate"><spanclass="pre">torchreid.data.VideoDataManager</span></code>.</li>
<li><strong>model</strong> (<em>nn.Module</em>) – model instance.</li>
<li><strong>optimizer</strong> (<em>Optimizer</em>) – an Optimizer.</li>
<li><strong>scheduler</strong> (<em>LRScheduler</em><em>, </em><em>optional</em>) – if None, no learning rate decay will be performed.</li>
<li><strong>use_cpu</strong> (<em>bool</em><em>, </em><em>optional</em>) – use cpu. Default is False.</li>
<li><strong>label_smooth</strong> (<em>bool</em><em>, </em><em>optional</em>) – use label smoothing regularizer. Default is True.</li>
<codeclass="descname">train</code><spanclass="sig-paren">(</span><em>epoch</em>, <em>max_epoch</em>, <em>trainloader</em>, <em>fixbase_epoch=0</em>, <em>open_layers=None</em>, <em>print_freq=10</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/engine/image/softmax.html#ImageSoftmaxEngine.train"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.engine.image.softmax.ImageSoftmaxEngine.train"title="Permalink to this definition">¶</a></dt>
<dd><p>Performs training on source datasets for one epoch.</p>
<p>This will be called every epoch in <codeclass="docutils literal notranslate"><spanclass="pre">run()</span></code>, e.g.</p>
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><ulclass="first last simple">
<li><strong>datamanager</strong> (<aclass="reference internal"href="data.html#torchreid.data.datamanager.DataManager"title="torchreid.data.datamanager.DataManager"><em>DataManager</em></a>) – an instance of <codeclass="docutils literal notranslate"><spanclass="pre">torchreid.data.ImageDataManager</span></code>
or <codeclass="docutils literal notranslate"><spanclass="pre">torchreid.data.VideoDataManager</span></code>.</li>
<li><strong>model</strong> (<em>nn.Module</em>) – model instance.</li>
<li><strong>optimizer</strong> (<em>Optimizer</em>) – an Optimizer.</li>
<li><strong>margin</strong> (<em>float</em><em>, </em><em>optional</em>) – margin for triplet loss. Default is 0.3.</li>
<li><strong>weight_t</strong> (<em>float</em><em>, </em><em>optional</em>) – weight for triplet loss. Default is 1.</li>
<li><strong>weight_x</strong> (<em>float</em><em>, </em><em>optional</em>) – weight for softmax loss. Default is 1.</li>
<li><strong>scheduler</strong> (<em>LRScheduler</em><em>, </em><em>optional</em>) – if None, no learning rate decay will be performed.</li>
<li><strong>use_cpu</strong> (<em>bool</em><em>, </em><em>optional</em>) – use cpu. Default is False.</li>
<li><strong>label_smooth</strong> (<em>bool</em><em>, </em><em>optional</em>) – use label smoothing regularizer. Default is True.</li>
<spanclass="n">train_sampler</span><spanclass="o">=</span><spanclass="s1">'RandomIdentitySampler'</span><spanclass="c1"># this is important</span>
<codeclass="descname">train</code><spanclass="sig-paren">(</span><em>epoch</em>, <em>max_epoch</em>, <em>trainloader</em>, <em>fixbase_epoch=0</em>, <em>open_layers=None</em>, <em>print_freq=10</em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/torchreid/engine/image/triplet.html#ImageTripletEngine.train"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#torchreid.engine.image.triplet.ImageTripletEngine.train"title="Permalink to this definition">¶</a></dt>
<dd><p>Performs training on source datasets for one epoch.</p>
<p>This will be called every epoch in <codeclass="docutils literal notranslate"><spanclass="pre">run()</span></code>, e.g.</p>
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><ulclass="first last simple">
<li><strong>datamanager</strong> (<aclass="reference internal"href="data.html#torchreid.data.datamanager.DataManager"title="torchreid.data.datamanager.DataManager"><em>DataManager</em></a>) – an instance of <codeclass="docutils literal notranslate"><spanclass="pre">torchreid.data.ImageDataManager</span></code>
or <codeclass="docutils literal notranslate"><spanclass="pre">torchreid.data.VideoDataManager</span></code>.</li>
<li><strong>model</strong> (<em>nn.Module</em>) – model instance.</li>
<li><strong>optimizer</strong> (<em>Optimizer</em>) – an Optimizer.</li>
<li><strong>scheduler</strong> (<em>LRScheduler</em><em>, </em><em>optional</em>) – if None, no learning rate decay will be performed.</li>
<li><strong>use_cpu</strong> (<em>bool</em><em>, </em><em>optional</em>) – use cpu. Default is False.</li>
<li><strong>label_smooth</strong> (<em>bool</em><em>, </em><em>optional</em>) – use label smoothing regularizer. Default is True.</li>
<li><strong>pooling_method</strong> (<em>str</em><em>, </em><em>optional</em>) – how to pool features for a tracklet.
Default is “avg” (average). Choices are [“avg”, “max”].</li>
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><ulclass="first last simple">
<li><strong>datamanager</strong> (<aclass="reference internal"href="data.html#torchreid.data.datamanager.DataManager"title="torchreid.data.datamanager.DataManager"><em>DataManager</em></a>) – an instance of <codeclass="docutils literal notranslate"><spanclass="pre">torchreid.data.ImageDataManager</span></code>
or <codeclass="docutils literal notranslate"><spanclass="pre">torchreid.data.VideoDataManager</span></code>.</li>
<li><strong>model</strong> (<em>nn.Module</em>) – model instance.</li>
<li><strong>optimizer</strong> (<em>Optimizer</em>) – an Optimizer.</li>
<li><strong>margin</strong> (<em>float</em><em>, </em><em>optional</em>) – margin for triplet loss. Default is 0.3.</li>
<li><strong>weight_t</strong> (<em>float</em><em>, </em><em>optional</em>) – weight for triplet loss. Default is 1.</li>
<li><strong>weight_x</strong> (<em>float</em><em>, </em><em>optional</em>) – weight for softmax loss. Default is 1.</li>
<li><strong>scheduler</strong> (<em>LRScheduler</em><em>, </em><em>optional</em>) – if None, no learning rate decay will be performed.</li>
<li><strong>use_cpu</strong> (<em>bool</em><em>, </em><em>optional</em>) – use cpu. Default is False.</li>
<li><strong>label_smooth</strong> (<em>bool</em><em>, </em><em>optional</em>) – use label smoothing regularizer. Default is True.</li>
<li><strong>pooling_method</strong> (<em>str</em><em>, </em><em>optional</em>) – how to pool features for a tracklet.
Default is “avg” (average). Choices are [“avg”, “max”].</li>
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>.