docs/build/html/_generated/deepof.model_utils.html
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>deepof.model_utils — deepof 0.6.2 documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../_static/jupyter-sphinx.css" type="text/css" />
<link rel="stylesheet" href="../_static/thebelab.css" type="text/css" />
<link rel="stylesheet" href="../_static/custom.css" type="text/css" />
<link rel="shortcut icon" href="../_static/deepof.ico"/>
<!--[if lt IE 9]>
<script src="../_static/js/html5shiv.min.js"></script>
<![endif]-->
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/sphinx_highlight.js"></script>
<script src="../_static/thebelab-helper.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@jupyter-widgets/html-manager@^1.0.1/dist/embed-amd.js"></script>
<script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
<script src="../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../index.html">
<img src="../_static/deepof_sidebar.ico" class="logo" alt="Logo"/>
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<!-- Local TOC -->
<div class="local-toc"><ul>
<li><a class="reference internal" href="#">deepof.model_utils</a></li>
</ul>
</div>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">deepof</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item active">deepof.model_utils</li>
<li class="wy-breadcrumbs-aside">
<a href="../_sources/_generated/deepof.model_utils.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<style>
/* CSS overrides for sphinx_rtd_theme */
/* 24px margin */
.nbinput.nblast.container,
.nboutput.nblast.container {
margin-bottom: 19px; /* padding has already 5px */
}
/* ... except between code cells! */
.nblast.container + .nbinput.container {
margin-top: -19px;
}
.admonition > p:before {
margin-right: 4px; /* make room for the exclamation icon */
}
/* Fix math alignment, see https://github.com/rtfd/sphinx_rtd_theme/pull/686 */
.math {
text-align: unset;
}
</style>
<section id="module-deepof.model_utils">
<span id="deepof-model-utils"></span><h1>deepof.model_utils<a class="headerlink" href="#module-deepof.model_utils" title="Permalink to this heading"></a></h1>
<p>Utility functions for both training autoencoder models in deepof.models and tuning hyperparameters with deepof.hypermodels.</p>
<p class="rubric">Functions</p>
<table class="autosummary longtable docutils align-default">
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="deepof.model_utils.cluster_frequencies_regularizer.html#deepof.model_utils.cluster_frequencies_regularizer" title="deepof.model_utils.cluster_frequencies_regularizer"><code class="xref py py-obj docutils literal notranslate"><span class="pre">cluster_frequencies_regularizer</span></code></a>(soft_counts, k)</p></td>
<td><p>Compute the KL divergence between the cluster assignment distribution and a uniform prior across clusters.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="deepof.model_utils.compute_kmeans_loss.html#deepof.model_utils.compute_kmeans_loss" title="deepof.model_utils.compute_kmeans_loss"><code class="xref py py-obj docutils literal notranslate"><span class="pre">compute_kmeans_loss</span></code></a>(latent_means[, weight, ...])</p></td>
<td><p>Add a penalty to the singular values of the Gram matrix of the latent means.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="deepof.model_utils.compute_shannon_entropy.html#deepof.model_utils.compute_shannon_entropy" title="deepof.model_utils.compute_shannon_entropy"><code class="xref py py-obj docutils literal notranslate"><span class="pre">compute_shannon_entropy</span></code></a>(tensor)</p></td>
<td><p>Compute Shannon entropy for a given tensor.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="deepof.model_utils.create_look_ahead_mask.html#deepof.model_utils.create_look_ahead_mask" title="deepof.model_utils.create_look_ahead_mask"><code class="xref py py-obj docutils literal notranslate"><span class="pre">create_look_ahead_mask</span></code></a>(size)</p></td>
<td><p>Create a triangular matrix containing an increasing amount of ones from left to right on each subsequent row.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="deepof.model_utils.create_masks.html#deepof.model_utils.create_masks" title="deepof.model_utils.create_masks"><code class="xref py py-obj docutils literal notranslate"><span class="pre">create_masks</span></code></a>(inp)</p></td>
<td><p>Given an input sequence, it creates all necessary masks to pass it through the transformer architecture.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="deepof.model_utils.create_padding_mask.html#deepof.model_utils.create_padding_mask" title="deepof.model_utils.create_padding_mask"><code class="xref py py-obj docutils literal notranslate"><span class="pre">create_padding_mask</span></code></a>(seq)</p></td>
<td><p>Create a padding mask, with zeros where data is missing, and ones where data is available.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="deepof.model_utils.dcl_loss.html#deepof.model_utils.dcl_loss" title="deepof.model_utils.dcl_loss"><code class="xref py py-obj docutils literal notranslate"><span class="pre">dcl_loss</span></code></a>(history, future, similarity[, ...])</p></td>
<td><p>Compute the DCL loss function, as described in the paper "Debiased Contrastive Learning" (<a class="reference external" href="https://github.com/chingyaoc/DCL/">https://github.com/chingyaoc/DCL/</a>).</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="deepof.model_utils.embedding_model_fitting.html#deepof.model_utils.embedding_model_fitting" title="deepof.model_utils.embedding_model_fitting"><code class="xref py py-obj docutils literal notranslate"><span class="pre">embedding_model_fitting</span></code></a>(preprocessed_object, ...)</p></td>
<td><p>Trains the specified embedding model on the preprocessed data.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="deepof.model_utils.embedding_per_video.html#deepof.model_utils.embedding_per_video" title="deepof.model_utils.embedding_per_video"><code class="xref py py-obj docutils literal notranslate"><span class="pre">embedding_per_video</span></code></a>(coordinates, ...[, ...])</p></td>
<td><p>Use a previously trained model to produce embeddings, soft_counts and breaks per experiment in table_dict format.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="deepof.model_utils.fc_loss.html#deepof.model_utils.fc_loss" title="deepof.model_utils.fc_loss"><code class="xref py py-obj docutils literal notranslate"><span class="pre">fc_loss</span></code></a>(history, future, similarity[, ...])</p></td>
<td><p>Compute the FC loss function, as described in the paper "Fully-Contrastive Learning of Visual Representations" (<a class="reference external" href="https://arxiv.org/abs/2004.11362">https://arxiv.org/abs/2004.11362</a>).</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="deepof.model_utils.find_learning_rate.html#deepof.model_utils.find_learning_rate" title="deepof.model_utils.find_learning_rate"><code class="xref py py-obj docutils literal notranslate"><span class="pre">find_learning_rate</span></code></a>(model, data[, epochs, ...])</p></td>
<td><p>Train the provided model for an epoch with an exponentially increasing learning rate.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="deepof.model_utils.get_angles.html#deepof.model_utils.get_angles" title="deepof.model_utils.get_angles"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_angles</span></code></a>(pos, i, d_model)</p></td>
<td><p>Auxiliary function for positional encoding computation.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="deepof.model_utils.get_callbacks.html#deepof.model_utils.get_callbacks" title="deepof.model_utils.get_callbacks"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_callbacks</span></code></a>(embedding_model, encoder_type)</p></td>
<td><p>Generate callbacks used for model training.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="deepof.model_utils.get_hard_counts.html#deepof.model_utils.get_hard_counts" title="deepof.model_utils.get_hard_counts"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_hard_counts</span></code></a>(soft_counts)</p></td>
<td><p>Compute hard counts per cluster in a differentiable way.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="deepof.model_utils.get_k_nearest_neighbors.html#deepof.model_utils.get_k_nearest_neighbors" title="deepof.model_utils.get_k_nearest_neighbors"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_k_nearest_neighbors</span></code></a>(tensor, k, index)</p></td>
<td><p>Retrieve indices of the k nearest neighbors in tensor to the vector with the specified index.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="deepof.model_utils.get_recurrent_block.html#deepof.model_utils.get_recurrent_block" title="deepof.model_utils.get_recurrent_block"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_recurrent_block</span></code></a>(x, latent_dim, ...)</p></td>
<td><p>Build a recurrent embedding block, using a 1D convolution followed by two bidirectional GRU layers.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="deepof.model_utils.hard_loss.html#deepof.model_utils.hard_loss" title="deepof.model_utils.hard_loss"><code class="xref py py-obj docutils literal notranslate"><span class="pre">hard_loss</span></code></a>(history, future, similarity, ...)</p></td>
<td><p>Compute the Hard loss function, as described in the paper "Contrastive Learning with Hard Negative Samples" (<a class="reference external" href="https://arxiv.org/abs/2011.03343">https://arxiv.org/abs/2011.03343</a>).</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="deepof.model_utils.log_hyperparameters.html#deepof.model_utils.log_hyperparameters" title="deepof.model_utils.log_hyperparameters"><code class="xref py py-obj docutils literal notranslate"><span class="pre">log_hyperparameters</span></code></a>()</p></td>
<td><p>Log hyperparameters in tensorboard.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="deepof.model_utils.nce_loss.html#deepof.model_utils.nce_loss" title="deepof.model_utils.nce_loss"><code class="xref py py-obj docutils literal notranslate"><span class="pre">nce_loss</span></code></a>(history, future, similarity[, ...])</p></td>
<td><p>Compute the NCE loss function, as described in the paper "A Simple Framework for Contrastive Learning of Visual Representations" (<a class="reference external" href="https://arxiv.org/abs/2002.05709">https://arxiv.org/abs/2002.05709</a>).</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="deepof.model_utils.plot_lr_vs_loss.html#deepof.model_utils.plot_lr_vs_loss" title="deepof.model_utils.plot_lr_vs_loss"><code class="xref py py-obj docutils literal notranslate"><span class="pre">plot_lr_vs_loss</span></code></a>(rates, losses)</p></td>
<td><p>Plot learning rate versus the loss function of the model.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="deepof.model_utils.positional_encoding.html#deepof.model_utils.positional_encoding" title="deepof.model_utils.positional_encoding"><code class="xref py py-obj docutils literal notranslate"><span class="pre">positional_encoding</span></code></a>(position, d_model)</p></td>
<td><p>Compute positional encodings, as in <a class="reference external" href="https://proceedings.neurips.cc/paper/2017/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf">https://proceedings.neurips.cc/paper/2017/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf</a>.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="deepof.model_utils.select_contrastive_loss.html#deepof.model_utils.select_contrastive_loss" title="deepof.model_utils.select_contrastive_loss"><code class="xref py py-obj docutils literal notranslate"><span class="pre">select_contrastive_loss</span></code></a>(history, future, ...)</p></td>
<td><p>Select and applies the contrastive loss function to be used in the Contrastive embedding models.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="deepof.model_utils.tune_search.html#deepof.model_utils.tune_search" title="deepof.model_utils.tune_search"><code class="xref py py-obj docutils literal notranslate"><span class="pre">tune_search</span></code></a>(preprocessed_object, ...[, ...])</p></td>
<td><p>Define the search space using keras-tuner and hyperband or bayesian optimization.</p></td>
</tr>
</tbody>
</table>
<p class="rubric">Classes</p>
<table class="autosummary longtable docutils align-default">
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="deepof.model_utils.ClusterControl.html#deepof.model_utils.ClusterControl" title="deepof.model_utils.ClusterControl"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ClusterControl</span></code></a>(*args, **kwargs)</p></td>
<td><p>Identity layer.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="deepof.model_utils.CustomStopper.html#deepof.model_utils.CustomStopper" title="deepof.model_utils.CustomStopper"><code class="xref py py-obj docutils literal notranslate"><span class="pre">CustomStopper</span></code></a>(start_epoch, *args, **kwargs)</p></td>
<td><p>Custom early stopping callback.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="deepof.model_utils.ExponentialLearningRate.html#deepof.model_utils.ExponentialLearningRate" title="deepof.model_utils.ExponentialLearningRate"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ExponentialLearningRate</span></code></a>(factor)</p></td>
<td><p>Simple class that allows to grow learning rate exponentially during training.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="deepof.model_utils.ProbabilisticDecoder.html#deepof.model_utils.ProbabilisticDecoder" title="deepof.model_utils.ProbabilisticDecoder"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ProbabilisticDecoder</span></code></a>(*args, **kwargs)</p></td>
<td><p>Map the reconstruction output of a given decoder to a multivariate normal distribution.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="deepof.model_utils.TransformerDecoder.html#deepof.model_utils.TransformerDecoder" title="deepof.model_utils.TransformerDecoder"><code class="xref py py-obj docutils literal notranslate"><span class="pre">TransformerDecoder</span></code></a>(*args, **kwargs)</p></td>
<td><p>Transformer decoder.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="deepof.model_utils.TransformerDecoderLayer.html#deepof.model_utils.TransformerDecoderLayer" title="deepof.model_utils.TransformerDecoderLayer"><code class="xref py py-obj docutils literal notranslate"><span class="pre">TransformerDecoderLayer</span></code></a>(*args, **kwargs)</p></td>
<td><p>Transformer decoder layer.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="deepof.model_utils.TransformerEncoder.html#deepof.model_utils.TransformerEncoder" title="deepof.model_utils.TransformerEncoder"><code class="xref py py-obj docutils literal notranslate"><span class="pre">TransformerEncoder</span></code></a>(*args, **kwargs)</p></td>
<td><p>Transformer encoder.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="deepof.model_utils.TransformerEncoderLayer.html#deepof.model_utils.TransformerEncoderLayer" title="deepof.model_utils.TransformerEncoderLayer"><code class="xref py py-obj docutils literal notranslate"><span class="pre">TransformerEncoderLayer</span></code></a>(*args, **kwargs)</p></td>
<td><p>Transformer encoder layer.</p></td>
</tr>
</tbody>
</table>
</section>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>© Copyright 2024, Lucas Miranda.</p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>