<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Patrick Emami</title>
    <description>Research Scientist at the National Renewable Energy Lab
</description>
    <link>https://pemami4911.github.io/</link>
    <atom:link href="https://pemami4911.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Wed, 11 Jun 2025 14:56:26 +0000</pubDate>
    <lastBuildDate>Wed, 11 Jun 2025 14:56:26 +0000</lastBuildDate>
    <generator>Jekyll v3.10.0</generator>
    
      <item>
        <title>Plug &amp; Play Directed Evolution of Proteins with Gradient-based Discrete MCMC</title>
        <description>&lt;script type=&quot;text/javascript&quot; async=&quot;&quot; src=&quot;https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML&quot;&gt;
&lt;/script&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
  TeX: { equationNumbers: { autoNumber: &quot;AMS&quot; } },
  tex2jax: {inlineMath: [[&apos;$&apos;,&apos;$&apos;], [&apos;\\(&apos;,&apos;\\)&apos;]]}
});
&lt;/script&gt;

&lt;hr /&gt;
&lt;p&gt;&lt;a href=&quot;https://pemami4911.github.io&quot;&gt;&lt;strong&gt;Patrick Emami&lt;/strong&gt;&lt;/a&gt;, &lt;a href=&quot;https://dblp.org/pid/230/7966.html&quot;&gt;Aidan Perreault&lt;/a&gt;, &lt;a href=&quot;https://scholar.google.com/citations?user=N4r7gmAAAAAJ&amp;amp;hl=en&amp;amp;oi=ao&quot;&gt;Jeff Law&lt;/a&gt;, &lt;a href=&quot;https://scholar.google.com/citations?user=971GyxQAAAAJ&amp;amp;hl=en&amp;amp;oi=sra&quot;&gt;David Biagioni&lt;/a&gt;, &lt;a href=&quot;https://pcstj.com/cv/&quot;&gt;Peter C. St. John&lt;/a&gt;.
Machine Learning: Science and Technology, 2023. 
Presented at &lt;a href=&quot;https://www.mlsb.io/&quot;&gt;NeurIPS’22 Workshop on Machine Learning in Structural Biology&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://iopscience.iop.org/article/10.1088/2632-2153/accacd&quot;&gt;[DOI]&lt;/a&gt; &lt;a href=&quot;https://arxiv.org/abs/2212.09925&quot;&gt;[arxiv]&lt;/a&gt; &lt;a href=&quot;https://github.com/pemami4911/ppde&quot;&gt;[Paper code]&lt;/a&gt;   &lt;a href=&quot;https://github.com/NREL/EvoProtGrad&quot;&gt;[EvoProtGrad library]&lt;/a&gt;&lt;/p&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/img/PPDE/Proteins_qual_1row.png&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;p class=&quot;image-caption&quot;&gt;The marginal frequency of each sequence position visualized on the 3D structure of the wild type is the fraction of protein variants in the sampled variant pool that have a mutation at that sequence position. For example, nearly 100% of discovered UBE4B variants have a mutation at position 1145.&lt;/p&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;announcing-evoprotgrad&quot;&gt;Announcing EvoProtGrad&lt;/h2&gt;

&lt;p&gt;7/21/23: We have released a Python package accompanying this work with HuggingFace integration for supporting a wide range of protein language models. Check it out on &lt;a href=&quot;https://github.com/NREL/EvoProtGrad&quot;&gt;Github&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pip &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;evo_prot_grad
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;quick-demo&quot;&gt;Quick demo&lt;/h3&gt;

&lt;p&gt;Evolve the avGFP protein with &lt;a href=&quot;https://huggingface.co/Rostlab/prot_bert&quot;&gt;Rostlab/prot_bert&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;evo_prot_grad&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;prot_bert_expert&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;evo_prot_grad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_expert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;bert&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;variants&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;scores&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;evo_prot_grad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DirectedEvolution&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
                   &lt;span class=&quot;n&quot;&gt;wt_fasta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;test/gfp.fasta&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;# path to wild type fasta file
&lt;/span&gt;                   &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;best&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;                &lt;span class=&quot;c1&quot;&gt;# return best, last, all variants    
&lt;/span&gt;                   &lt;span class=&quot;n&quot;&gt;experts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prot_bert_expert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# list of experts to compose
&lt;/span&gt;                   &lt;span class=&quot;n&quot;&gt;parallel_chains&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;            &lt;span class=&quot;c1&quot;&gt;# number of parallel chains to run
&lt;/span&gt;                   &lt;span class=&quot;n&quot;&gt;n_steps&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;                   &lt;span class=&quot;c1&quot;&gt;# number of MCMC steps per chain
&lt;/span&gt;                   &lt;span class=&quot;n&quot;&gt;max_mutations&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;             &lt;span class=&quot;c1&quot;&gt;# maximum number of mutations per variant
&lt;/span&gt;                   &lt;span class=&quot;n&quot;&gt;verbose&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;                  &lt;span class=&quot;c1&quot;&gt;# print debug info to command line
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;p&gt;Machine-learning-based directed evolution can be used to engineer new proteins that have improved productivity or catalyze new reactions. Basically, starting from a known protein sequence, directed evolution proceeds by identifying candidate mutations, experimentally verifying them, and then using the gained information to search for better mutations. &lt;a href=&quot;http://www.cheme.caltech.edu/groups/fha/old_website_2011_06_08/Arnold_ACR_1998.pdf&quot;&gt;The intention is for this iterative process to resemble natural evolution&lt;/a&gt;. One way ML can help streamline this design loop is by optimizing the candidate indentification step.&lt;/p&gt;

&lt;p&gt;In this paper, we introduce a plug and play protein sampler for this step. The sampler mixes and matches &lt;em&gt;unsupervised&lt;/em&gt; evolutionary sequence models (e.g., protein language models) with &lt;em&gt;supervised&lt;/em&gt; sequence models that map sequence to function, without needing any model re-training or fine-tuning. Sampling is performed in sequence space to keep things as ‘‘black-box’’ as possible. Plug and play samplers have been successful in other domains, such as for controlled &lt;a href=&quot;https://openaccess.thecvf.com/content_cvpr_2017/html/Nguyen_Plug__Play_CVPR_2017_paper.html&quot;&gt;image&lt;/a&gt; and &lt;a href=&quot;https://arxiv.org/abs/1912.02164&quot;&gt;text&lt;/a&gt; generation.&lt;/p&gt;

&lt;p&gt;Searching through protein sequence space &lt;em&gt;efficiently&lt;/em&gt;, which is high-dimensional and discrete, is notoriously difficult. We address this in our MCMC-based sampler by using the &lt;em&gt;gradient&lt;/em&gt; of the (differentiable) target function to bias a mutation proposal distribution towards favorable mutations. We show that this approach outperforms classic random search.&lt;/p&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/img/PPDE/main.gif&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Impact&lt;/strong&gt;: Improving the quality of candidate protein variants reduces the time spent conducting costly experiments in the wet lab and accelerates the engineering of new proteins.&lt;/p&gt;

&lt;h2 id=&quot;checking-intuitions-with-a-toy-binary-mnist-experiment&quot;&gt;Checking intuitions with a toy binary MNIST experiment&lt;/h2&gt;

&lt;p&gt;The task is to evolve the MNIST digit on the right, initially a 1, to maximize the sum of the two digits &lt;em&gt;solely by flipping binary pixels&lt;/em&gt;. Since the digit on the left is a 9, the initial sum of the digits is 10. The maximum is 18 (9 + 9).&lt;/p&gt;

&lt;p&gt;Here’s our sampler applied to a product of experts distribution that combines an unsupervised energy based model with a supervised ensemble of ConvNets trained to regress the sum.&lt;/p&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/img/PPDE/PPDE_DAE_20fps.gif&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;p class=&quot;image-caption&quot;&gt;&lt;/p&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;If we remove the EBM from the product of experts, the search gets trapped in &lt;a href=&quot;https://arxiv.org/abs/1312.6199&quot;&gt;adversarial optima&lt;/a&gt;—white-noise images. This is because, in this case, gradient-based discrete MCMC is only using the gradient of the ConvNet ensemble to steer search. The EBM acts as a soft constraint that keeps search away from such optima.&lt;/p&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/img/PPDE/PPDE_None_20fps.gif&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;p class=&quot;image-caption&quot;&gt;&lt;/p&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;If we replace gradient-based discrete MCMC with random-search-based simulated annealing, nearly every randomly sampled mutation is rejected as it does not increase the predicted sum.&lt;/p&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/img/PPDE/simulated_annealing_20fps.gif&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;in-silico-directed-evolution-experiments&quot;&gt;In-silico directed evolution experiments&lt;/h2&gt;

&lt;p&gt;We conduct in-silico directed evolution experiments on 3 proteins with partially-characterized wide fitness landscapes (between 2-15 mutations from wild type): &lt;a href=&quot;https://www.uniprot.org/uniprot/P04147&quot;&gt;PABP_YEAST&lt;/a&gt;, &lt;a href=&quot;https://www.uniprot.org/uniprotkb/Q9ES00/entry&quot;&gt;UBE4B_MOUSE&lt;/a&gt;, and &lt;a href=&quot;https://www.uniprot.org/uniprotkb/P42212/entry&quot;&gt;GFP&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Compared to random-walk-based black-box samplers (simulated annealing, Metropolis-adjusted Langevin Algorithm (MALA)), random sampling, and an evolutionary method (CMA-ES), our sampler explores sequence space most efficiently (higher $\log p(x)$ is better).&lt;/p&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/img/PPDE/sampler_lineplots.png&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;We show that we can plug in different &lt;a href=&quot;https://www.biorxiv.org/content/10.1101/2022.07.20.500902v3&quot;&gt;protein language models&lt;/a&gt;: ESM2-35M, ESM2-150M, and ESM2-650M. We also combine ESM2-150M with a Potts model, which surprisingly achieved the best performance (red arrow).&lt;/p&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/img/PPDE/PPDE_priors.png&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;See the paper and code for more details and results.&lt;/p&gt;
</description>
        <pubDate>Thu, 05 Jan 2023 00:00:00 +0000</pubDate>
        <link>https://pemami4911.github.io/blog/2023/01/05/ppde.html</link>
        <guid isPermaLink="true">https://pemami4911.github.io/blog/2023/01/05/ppde.html</guid>
        
        
        <category>blog</category>
        
      </item>
    
      <item>
        <title>Part 1: Deploying a PyTorch MobileNetV2 Classifier on the Intel Neural Compute Stick 2</title>
        <description>&lt;script type=&quot;text/javascript&quot; async=&quot;&quot; src=&quot;https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML&quot;&gt;
&lt;/script&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
  TeX: { equationNumbers: { autoNumber: &quot;AMS&quot; } },
  tex2jax: {inlineMath: [[&apos;$&apos;,&apos;$&apos;], [&apos;\\(&apos;,&apos;\\)&apos;]]}
});
&lt;/script&gt;

&lt;hr /&gt;

&lt;p&gt;This is the first part of a three part tutorial on using the Intel Neural Compute Stick 2 (NCS2) for vehicle tracking at traffic intersections. The goal of the first part is to get familiar with the NCS2 by walking through how to convert and run a PyTorch MobileNetV2 model on the NCS2 via Windows 10. The following guide should also work for supported popular Linux distros like Ubuntu 18.04.x and 20.04.0 as well as macOS 10.15.x with minor modifications.&lt;/p&gt;

&lt;h3 id=&quot;getting-started&quot;&gt;Getting started&lt;/h3&gt;

&lt;p&gt;I bought my NCS2 off Amazon for about 80 USD.&lt;/p&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/img/NCS2/IMG_5455.png&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;We’ll start by setting it up on a Windows 10 PC. My PC has a 6-core Intel i5-9600K processor.&lt;/p&gt;

&lt;p&gt;To begin, plug the NCS2 into a USB port on your machine. I then followed the steps from the &lt;a href=&quot;https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_windows.html&quot;&gt;Intel Windows guide&lt;/a&gt; to install their OpenVINO toolkit.
As for the dependencies, using Anaconda for Windows to get Python 3.8 was easy and painless. Make sure to follow the steps to install Microsoft Visual Studio 2019 with MSBuild and CMake as well. The only optional step to follow in the guide is to add Python and CMake to your Path by updating the environment variable.&lt;/p&gt;

&lt;p&gt;Once you finish, to test the installation, run the following demo in the Windows CLI:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd &quot;C:\Program Files (x86)\Intel\openvino_2021\deployment_tools\demo&quot;
.\demo_squeezenet_download_convert_run.bat –d MYRIAD
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You should see predicted scores:&lt;/p&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/img/NCS2/squeezenet_demo.png&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;h3 id=&quot;the-pytorch-to-onnx-conversion&quot;&gt;The PyTorch to ONNX Conversion&lt;/h3&gt;

&lt;p&gt;Next, we’ll try to port a pre-trained MobileNetV2 PyTorch model to the ONNX format based on &lt;a href=&quot;https://pytorch.org/tutorials/advanced/super_resolution_with_onnxruntime.html&quot;&gt;this tutorial&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Install PyTorch (cpu-only is fine) following the instructions &lt;a href=&quot;https://pytorch.org/&quot;&gt;here&lt;/a&gt; and ONNX with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip install onnx onnxruntime&lt;/code&gt;. If you are using a clean Python 3.8 conda environment, you may also want to install jupyter at this time.&lt;/p&gt;

&lt;p&gt;You can run the code snippets shown throughout the remainder of this guide by downloading and launching &lt;a href=&quot;/notebooks/ncs2/NCS2_MobileNetV2_PyTorch_Demo.ipynb&quot;&gt;this&lt;/a&gt; Jupyter notebook. See the ONNX tutorial linked above for detailed explanations of each cell.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# Some standard imports
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;torch&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;torch.onnx&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;torchvision.models&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;onnx&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;onnxruntime&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We can grab a pre-trained MobileNetV2 model from the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torchvision&lt;/code&gt; model zoo.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;model&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mobilenet_v2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pretrained&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;eval&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Export the model to the ONNX format using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torch.onnx.export&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;batch_size&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Input to the model
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;randn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;batch_size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;224&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;224&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requires_grad&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;torch_out&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# Export the model
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;torch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;onnx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;export&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;                     &lt;span class=&quot;c1&quot;&gt;# model being run
&lt;/span&gt;                  &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;                         &lt;span class=&quot;c1&quot;&gt;# model input (or a tuple for multiple inputs)
&lt;/span&gt;                  &lt;span class=&quot;s&quot;&gt;&quot;mobilenet_v2.onnx&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;       &lt;span class=&quot;c1&quot;&gt;# where to save the model (can be a file or file-like object)
&lt;/span&gt;                  &lt;span class=&quot;n&quot;&gt;export_params&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;        &lt;span class=&quot;c1&quot;&gt;# store the trained parameter weights inside the model file
&lt;/span&gt;                  &lt;span class=&quot;n&quot;&gt;opset_version&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;          &lt;span class=&quot;c1&quot;&gt;# the ONNX version to export the model to
&lt;/span&gt;                  &lt;span class=&quot;n&quot;&gt;do_constant_folding&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# whether to execute constant folding for optimization
&lt;/span&gt;                  &lt;span class=&quot;n&quot;&gt;input_names&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;input&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# the model&apos;s input names
&lt;/span&gt;                  &lt;span class=&quot;n&quot;&gt;output_names&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;output&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# the model&apos;s output names
&lt;/span&gt;                  &lt;span class=&quot;n&quot;&gt;dynamic_axes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;input&apos;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;batch_size&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;# variable length axes
&lt;/span&gt;                                &lt;span class=&quot;s&quot;&gt;&apos;output&apos;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;batch_size&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This will create a 14MB file called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mobilenet_v2.onnx&lt;/code&gt;. Let’s check its validity using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onnx&lt;/code&gt; library.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;onnx_model&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;onnx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;mobilenet_v2.onnx&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;onnx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;checker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;check_model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;onnx_model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Finally, let’s run the model using the ONNX Runtime in an inference session to compare its results with the PyTorch results.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;ort_session&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;onnxruntime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;InferenceSession&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;mobilenet_v2.onnx&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;to_numpy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tensor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tensor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;detach&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cpu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tensor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;requires_grad&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tensor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cpu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;numpy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# compute ONNX Runtime output prediction
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ort_inputs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ort_session&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_inputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to_numpy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ort_outs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ort_session&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ort_inputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# compare ONNX Runtime and PyTorch results
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;testing&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assert_allclose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;to_numpy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;torch_out&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ort_outs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rtol&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1e-03&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;atol&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1e-05&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Exported model has been tested with ONNXRuntime, and the result looks good!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;the-onnx-to-openvino-conversion&quot;&gt;The ONNX to OpenVINO Conversion&lt;/h3&gt;

&lt;p&gt;Next we need to pass &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mobilenet_v2.onnx&lt;/code&gt; through the OpenVINO Model Optimizer to convert it into the proper intermediate representation (IR).&lt;/p&gt;

&lt;p&gt;I followed the steps listed &lt;a href=&quot;https://docs.openvinotoolkit.org/latest/openvino_docs_MO_DG_prepare_model_convert_model_Convert_Model_From_ONNX.html&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Go to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;OPENVINO_INSTALL_DIR&amp;gt;/deployment_tools/model_optimizer&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python mo.py --input_model &amp;lt;PATH_TO_INPUT_MODEL&amp;gt;.onnx --output_dir &amp;lt;OUTPUT_MODEL_DIR&amp;gt; --input_shape (1,3,224,224)&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This creates an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*.xml&lt;/code&gt; file, a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*.bin&lt;/code&gt; file, and a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*.mapping&lt;/code&gt; file, which altogether make up the IR for running on the NCS2.&lt;/p&gt;

&lt;h3 id=&quot;running-the-mobilenetv2-ir-on-the-ncs2&quot;&gt;Running the MobileNetV2 IR on the NCS2&lt;/h3&gt;

&lt;p&gt;Follow along again with &lt;a href=&quot;/notebooks/ncs2/NCS2_MobileNetV2_PyTorch_Demo.ipynb&quot;&gt;the same&lt;/a&gt; Jupyter notebook. Download the &lt;a href=&quot;/notebooks/ncs2/mobilenet_v2.labels&quot;&gt;ImageNet label file&lt;/a&gt; and this &lt;a href=&quot;/notebooks/ncs2/car.png&quot;&gt;test image&lt;/a&gt; and place them in the same directory as the notebook. In the Windows CLI, run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;call &amp;lt;OpenVINO_INSTALL_DIR&amp;gt;\bin\setupvars.bat&lt;/code&gt; to initialize the Inference Engine Python API, which is needed to import the OpenVINO python libraries (you may need to restart the notebook).&lt;/p&gt;

&lt;p&gt;I had to manually edit L38 of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;OPENVINO_INSTALL_DIR&amp;gt;\python\python3.8\ngraph\impl\__init__.py&lt;/code&gt; to read &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if (3, 8) &amp;gt; sys.version_info&lt;/code&gt; to fix an error. Similarly for L28 of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;OPENVINO_INSTALL_DIR&amp;gt;\python\python3.8\openvino\inference_engine\__init__.py&lt;/code&gt;. Note that this is seems to be because I am using Python 3.8 and that this may get fixed in a subsequent version of OpenVINO.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;__future__&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;print_function&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sys&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;cv2&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;logging&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# These are only available after running setupvars.bat
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;openvino.inference_engine&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IECore&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;ngraph&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ng&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then we set some variables and initialize the Inference Engine.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;model&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;lt;PATH_TO&amp;gt;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;mobilenet_v2.xml&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;device&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;MYRIAD&apos;&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# Intel NCS2 device name
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;basicConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;[ %(levelname)s ] %(message)s&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;INFO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stream&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Loading Inference Engine&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ie&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IECore&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# Inference Engine
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Read the model in OpenVINO Intermediate Representation (.xml).&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Loading network:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n\t&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ie&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read_network&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Load the plugin for inference engine and extensions library if specified.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Device info:&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;versions&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ie&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_versions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos; &apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos; &apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;MKLDNNPlugin version ......... &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;versions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;major&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;versions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;minor&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos; &apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Build ........... &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;versions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;build_number&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Read and preprocess input, following the preprocessing steps for torchvision pre-trained models.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;car.png&apos;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;input_key&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input_key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;layout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input_key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;
        
&lt;span class=&quot;n&quot;&gt;images&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ndarray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;images_hw&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;image&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imread&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ih&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iw&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;images_hw&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ih&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iw&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;File was added: &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;        &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ih&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iw&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;warning&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Image &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; is resized from &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; to &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;image&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;resize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# BGR to RGB
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;image&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cvtColor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cv2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;COLOR_BGR2RGB&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# Change data layout from HWC to CHW 
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;image&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;transpose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;  
    &lt;span class=&quot;c1&quot;&gt;# Change to (0,1)
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;image&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;image&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;255.&lt;/span&gt; 
    &lt;span class=&quot;c1&quot;&gt;# Subtract mean
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;image&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.485&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.456&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.406&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reshape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;# Divide by std 
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;image&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.229&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.224&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.225&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reshape&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;images&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;image&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Prepare input and output data. We use the default FP32 precision, but for future use, we could explore models that use lower precisions for faster runtimes.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Preparing input blobs&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Sample supports topologies only with 1 or 2 inputs&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;out_blob&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;iter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Just a single output, the class prediction
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;input_key&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;input_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;input_key&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input_key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;precision&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;FP32&apos;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;images&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Load the model to the NCS2 and do a single forward pass.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Loading model to the device&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;exec_net&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ie&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;load_network&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;network&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;device_name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;device&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Creating infer request and starting inference&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;res&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exec_net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;infer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inputs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Display the top 10 predictions.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Processing output blob&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Top 10 results: &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;labels_map&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;mobilenet_v2.labels&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;r&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;labels_map&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;classid_str&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;label&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;probability_str&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;probability&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;probs&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;enumerate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out_blob&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;probs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;squeeze&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;probs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;top_ind&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argsort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;probs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:][::&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Image &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;classid_str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;probability_str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;-&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;classid_str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;-&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;probability_str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;top_ind&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;det_label&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;labels_map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;labels_map&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;label_length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;det_label&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;space_num_before&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label_length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;//&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;space_num_after&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;space_num_before&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label_length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;det_label&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; ... &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;probs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; %&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/notebooks/ncs2/car.png&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;p class=&quot;image-caption&quot;&gt;car.png&lt;/p&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Result:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;label probability
----- -----------
convertible ... 11.8281250 %
beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon ... 11.5546875 %
sports car, sport car ... 11.4296875 %
pickup, pickup truck ... 11.2734375 %
car wheel ... 10.7968750 %
grille, radiator grille ... 10.3515625 %
Model T ... 8.8203125 %
minivan ... 8.7578125 %
cab, hack, taxi, taxicab ... 8.5625000 %
racer, race car, racing car ... 8.1250000 %
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Great! In part two of this tutorial, we’ll step through the process of running MobileNetV2-SSDLite for object detection on the NCS2 with a Raspberry Pi.&lt;/p&gt;

&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Sandler, Mark, Andrew Howard, Menglong Zhu, Andrey Zhmoginov, and Liang-Chieh Chen. “Mobilenetv2: Inverted residuals and linear bottlenecks.” In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 4510-4520. 2018.&lt;/li&gt;
&lt;/ol&gt;
</description>
        <pubDate>Fri, 09 Jul 2021 00:00:00 +0000</pubDate>
        <link>https://pemami4911.github.io/blog/2021/07/09/part-1-neural-compute-stick-2.html</link>
        <guid isPermaLink="true">https://pemami4911.github.io/blog/2021/07/09/part-1-neural-compute-stick-2.html</guid>
        
        
        <category>blog</category>
        
      </item>
    
      <item>
        <title>A Symmetric and Object-centric World Model for Stochastic Environments</title>
        <description>&lt;script type=&quot;text/javascript&quot; async=&quot;&quot; src=&quot;https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML&quot;&gt;
&lt;/script&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
  TeX: { equationNumbers: { autoNumber: &quot;AMS&quot; } },
  tex2jax: {inlineMath: [[&apos;$&apos;,&apos;$&apos;], [&apos;\\(&apos;,&apos;\\)&apos;]]}
});
&lt;/script&gt;

&lt;hr /&gt;
&lt;p&gt;&lt;strong&gt;Patrick Emami&lt;/strong&gt;, Pan He, Anand Rangarajan, Sanjay Ranka. &lt;br /&gt;
NeurIPS Object Representations for Learning and Reasoning Workshop. 2020. (&lt;em&gt;Spotlight presentation&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;&lt;span style=&quot;color:blue&quot;&gt;&lt;strong&gt;tl;dr&lt;/strong&gt;:&lt;/span&gt; We identify limitations of applying certain object-centric world models to stochastic environments and propose a state space model and training objective that achieves better stochastic future prediction.&lt;/p&gt;

&lt;h2 id=&quot;abstract&quot;&gt;Abstract&lt;/h2&gt;

&lt;p&gt;Object-centric world models learn useful representations for planning and control but have so far only been applied to synthetic and deterministic environments. We introduce a perceptual-grouping-based world model for the dual task of extracting object-centric representations and modeling stochastic dynamics in visually complex and noisy video environments. The world model is built upon a novel latent state space model that learns the variance for object discovery and dynamics separately. This design is motivated by the disparity in available information that exists between the discovery component, which takes a provided video frame and decomposes it into objects, and the dynamics component, which predicts representations for future video frames conditioned only on past frames. To learn the dynamics variance, we introduce a best-of-many-rollouts objective. We show that the world model successfully learns accurate and diverse rollouts in a real-world robotic manipulation environment with noisy actions while learning interpretable object-centric representations.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/orlrworkshop/orlrworkshop.github.io/blob/master/pdf/ORLR_3.pdf&quot;&gt;[paper]&lt;/a&gt; &lt;a href=&quot;https://github.com/pemami4911/symmetric-and-object-centric-world-models&quot;&gt;[code]&lt;/a&gt; &lt;a href=&quot;/pdfs/Workshop_poster_HD.pdf&quot;&gt;[poster]&lt;/a&gt;&lt;/p&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/img/orlr/orlr_main.png&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;demos---bair-towel-pick-30k-with-noisy-actions&quot;&gt;Demos - BAIR Towel Pick 30K with noisy actions&lt;/h2&gt;

&lt;!-- 

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot; &gt;
	
	&lt;img src=&quot;/img/orlr/BAIR_Ours-video-1-rollout-0.gif&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot;/&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;/div&gt;
&lt;/div&gt;



&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot; &gt;
	
	&lt;img src=&quot;/img/orlr/BAIR_VRNN-video-1-rollout-0.gif&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot;/&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;/div&gt;
&lt;/div&gt;
 --&gt;
&lt;p&gt;From left to right: ground truth, &lt;strong&gt;Ours&lt;/strong&gt;, OP3, VRNN:&lt;/p&gt;

&lt;div class=&quot;image-wrapper&quot;&gt;
    &lt;img src=&quot;/img/orlr/BAIR_gt-video-1-rollout-0.gif&quot; /&gt;
    &lt;img src=&quot;/img/orlr/BAIR_Ours-video-1-rollout-0.gif&quot; /&gt;
    &lt;img src=&quot;/img/orlr/BAIR_OP3-video-1-rollout-0.gif&quot; /&gt;
    &lt;img src=&quot;/img/orlr/BAIR_VRNN-video-1-rollout-0.gif&quot; /&gt;
&lt;/div&gt;

&lt;div class=&quot;image-wrapper&quot;&gt;
    &lt;img src=&quot;/img/orlr/BAIR_gt-video-2-rollout-0.gif&quot; /&gt;
    &lt;img src=&quot;/img/orlr/BAIR_Ours-video-2-rollout-0.gif&quot; /&gt;
    &lt;img src=&quot;/img/orlr/BAIR_OP3-video-2-rollout-0.gif&quot; /&gt;
    &lt;img src=&quot;/img/orlr/BAIR_VRNN-video-2-rollout-0.gif&quot; /&gt;
&lt;/div&gt;

&lt;div class=&quot;image-wrapper&quot;&gt;
    &lt;img src=&quot;/img/orlr/BAIR_gt-video-3-rollout-0.gif&quot; /&gt;
    &lt;img src=&quot;/img/orlr/BAIR_Ours-video-3-rollout-0.gif&quot; /&gt;
    &lt;img src=&quot;/img/orlr/BAIR_OP3-video-3-rollout-0.gif&quot; /&gt;
    &lt;img src=&quot;/img/orlr/BAIR_VRNN-video-3-rollout-0.gif&quot; /&gt;
&lt;/div&gt;

&lt;p&gt;Object decompositions, &lt;strong&gt;Ours&lt;/strong&gt;:&lt;/p&gt;

&lt;div class=&quot;image-wrapper&quot;&gt;
    &lt;img src=&quot;/img/orlr/BAIR_Ours-slot-video-1-rollout-0.gif&quot; /&gt;
    &lt;img src=&quot;/img/orlr/BAIR_Ours-slot-video-3-rollout-0.gif&quot; /&gt;
    &lt;img src=&quot;/img/orlr/BAIR_Ours-slot-video-4-rollout-0.gif&quot; /&gt;
    &lt;img src=&quot;/img/orlr/BAIR_Ours-slot-video-5-rollout-0.gif&quot; /&gt;
    &lt;img src=&quot;/img/orlr/BAIR_Ours-slot-video-9-rollout-0.gif&quot; /&gt;
&lt;/div&gt;
</description>
        <pubDate>Tue, 08 Dec 2020 00:00:00 +0000</pubDate>
        <link>https://pemami4911.github.io/blog/2020/12/08/symmetric-and-object-centric-world-models.html</link>
        <guid isPermaLink="true">https://pemami4911.github.io/blog/2020/12/08/symmetric-and-object-centric-world-models.html</guid>
        
        
        <category>blog</category>
        
      </item>
    
      <item>
        <title>What Can Neural Networks Reason About?</title>
        <description>&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
  TeX: { equationNumbers: { autoNumber: &quot;AMS&quot; } },
  tex2jax: {inlineMath: [[&apos;$&apos;,&apos;$&apos;], [&apos;\\(&apos;,&apos;\\)&apos;]]}
});
&lt;/script&gt;

&lt;script type=&quot;text/javascript&quot; async=&quot;&quot; src=&quot;https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML&quot;&gt;
&lt;/script&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;a href=&quot;https://openreview.net/forum?id=rJxbJeHFPS&quot;&gt;Xu, Li, Zhang, Du, Kawarabayashi, Jegelka, 2020&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;p&gt;This work proposes a theory they call “algorithmic alignment” to explain why some classes of neural net architectures generalize much better than others on certain reasoning problems. They use PAC learning to derive sample complexity bounds that show that the number of samples needed to achieve a desired amount of generalization increases when certain subproblems are “hard” to learn.&lt;/p&gt;

&lt;p&gt;For example, they empirically show that DeepSets can easily learn summary statistics for a set of numbers, like “max” or “min”. Since a single MLP has to learn the aggregation function (an easy subproblem) plus the for loop over all elements (a harder subproblem), their theory suggests that the number of samples required to acheive good generalization at test time is much higher for the MLP, which their experiments confirm. Interestingly, they explain why graph neural nets (GNNs) align well with dynamic programming (DP) problems (because of their iterative message-passing style updates), but then also explain why they do not align well with NP-Hard problems. They provide further experimental evidence on a shortest-paths DP problem and Subset-Sum NP-Hard problem to verify this.&lt;/p&gt;

&lt;h2 id=&quot;what-about-transformers&quot;&gt;What About Transformers?&lt;/h2&gt;

&lt;p&gt;The paper doesn’t discuss Transformers, so as a simple exercise, I thought about how it fits into their framework. &lt;a href=&quot;https://graphdeeplearning.github.io/post/transformers-are-gnns/&quot;&gt;Transformers map readily onto fully connected GNNs&lt;/a&gt;, which suggests that they should “align algorithmically” with DP problems but not NP-Hard problems. Note that for a set of $K$ objects, a multi-head attention Transformer/GNN performs an $O(K^2 d)$ operation. This highlights one limitation of Transformers; they can easily reason about object-object relations, but will struggle to generalize when faced with higher-order relations such as object-object-object. Relational reasoning over $k$-partite graphs, $k &amp;gt; 2$, shows up in certain NP-Hard problems like &lt;a href=&quot;https://pubsonline.informs.org/doi/pdf/10.1287/opre.16.2.422&quot;&gt;Multidimensional Assignment&lt;/a&gt;. It seems like algorithm alignment will certainly be useful for future research on designing neural net architectures for NP-Hard problems.&lt;/p&gt;
</description>
        <pubDate>Sun, 22 Mar 2020 00:00:00 +0000</pubDate>
        <link>https://pemami4911.github.io/paper-summaries/deep-learning-theory/2020/03/22/what-can-neural-nets-reason-about.html</link>
        <guid isPermaLink="true">https://pemami4911.github.io/paper-summaries/deep-learning-theory/2020/03/22/what-can-neural-nets-reason-about.html</guid>
        
        
        <category>paper-summaries</category>
        
        <category>deep-learning-theory</category>
        
      </item>
    
      <item>
        <title>MLSS 2019</title>
        <description>&lt;script type=&quot;text/javascript&quot; async=&quot;&quot; src=&quot;https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML&quot;&gt;
&lt;/script&gt;

&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
  TeX: { equationNumbers: { autoNumber: &quot;AMS&quot; } },
  tex2jax: {inlineMath: [[&apos;$&apos;,&apos;$&apos;], [&apos;\\(&apos;,&apos;\\)&apos;]]}
});
&lt;/script&gt;

&lt;hr /&gt;

&lt;p&gt;Now that the &lt;a href=&quot;https://sites.google.com/view/mlss-2019&quot;&gt;2019 London MLSS&lt;/a&gt; is over, I thought I’d share a couple things about my experience and summarize some of the fascinating technical content I learned over the 10 days of lectures. This will not only help improve my recall of the material, but will also make it easy to share some of what I learned with my lab and with others that weren’t able to attend. If you find any mistakes, please feel free to reach out so I can make corrections. :)&lt;/p&gt;

&lt;p&gt;First and foremost, however, let me send a huge thank you to the organizers, Arthur Gretton and Marc Deisenroth, for putting this amazing event together. It was an incredibly rewarding experience for me. Also, thank you to all the lecturers and volunteers as well!&lt;/p&gt;

&lt;p&gt;Before I jump into discussing technical highlights…&lt;/p&gt;

&lt;h2 id=&quot;wait-why-are-phd-students-going-to-summer-school&quot;&gt;Wait, why are PhD students going to summer school?&lt;/h2&gt;

&lt;p&gt;For those of you reading this that may not know what a summer school is, summer schools are typically focused on a specific topic, have daily lectures and practicals, and can last from a few days to two weeks. The location of the summer school is usually in an exciting place, so that students can explore the area together. Usually there’s also a poster session for students to share their ongoing work. At this MLSS, days were structured as two 2-hour lectures followed by a practical which involved writing code for some exercises.&lt;/p&gt;

&lt;p&gt;From what I’ve been told and from what I experienced, one of the best reason to attend a summer school is to make friends with other highly-motivated students from around the world. We were lucky enough that Arthur and Marc assembled an amazingly diverse cohort. Out of the ~200 students that attended, 53 nationalities were represented!&lt;/p&gt;

&lt;h2 id=&quot;it-wasnt-all-work&quot;&gt;It wasn’t all work&lt;/h2&gt;

&lt;p&gt;I was surrounded by a ton of brilliant people from the moment I arrived in London. Here are some highlights from the fun times we had:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Experienced the &lt;a href=&quot;https://www.bbc.com/news/uk-49157898&quot;&gt;hottest day in UK history&lt;/a&gt;. OK so this wasn’t “fun” but our joint suffering was a great bonding experience. I’m used to this type of heat back in Florida, but in London most buildings don’t have air conditioning.&lt;/li&gt;
  &lt;li&gt;On the Saturday afternoon we bought ~half the food at a local grocery store to feed a large group of us that were having a picnic in Green park near Buckingham Palace&lt;/li&gt;
  &lt;li&gt;A group of us saw A Midsummer’s Night Dream at the Open Air Theatre in Regent’s Park&lt;/li&gt;
&lt;/ul&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/img/MLSS/mlss2019.jpeg&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;p class=&quot;image-caption&quot;&gt;After our tour of the Tower of London&lt;/p&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;technical-highlights-from-mlss&quot;&gt;Technical highlights from MLSS&lt;/h2&gt;
&lt;p&gt;I’ll only be discussing some of the lectures in this post, but all of the slides and lectures are available at the &lt;a href=&quot;https://github.com/mlss-2019&quot;&gt;MLSS Github page&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;optimization&quot;&gt;Optimization&lt;/h2&gt;

&lt;p&gt;Lecturer: John Duchi [&lt;a href=&quot;https://github.com/mlss-2019/slides/tree/master/optimisation&quot;&gt;Slides&lt;/a&gt;] [&lt;a href=&quot;https://videoken.com/embed/d6i9-ZvjDmY&quot;&gt;Video 1&lt;/a&gt;] [&lt;a href=&quot;https://videoken.com/embed/iNrBhcEjZbc&quot;&gt;Video 2&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;John first introduced to us the main ideas in convex optimization and then covered some special topics. A big takeaway from his lecture is to stop and think about each particular optimization problem for a bit instead of just tossing SGD at it (supposedly we shouldn’t say “SGD” because the trajectory taken by stochastic gradient methods like “SGD” don’t strictly “descend”, rather they wander around quite a bit). His point is that we can do a lot better.&lt;/p&gt;

&lt;p&gt;The concepts of subgradients and a subdifferential were new to me. A vector $g$ is a &lt;strong&gt;subgradient&lt;/strong&gt; of a function $f$ at $x$ if 
\(f(y) \geq f(x) + &amp;lt;g, y - x&amp;gt;.\)&lt;/p&gt;

&lt;p&gt;In a picture:&lt;/p&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/img/MLSS/IMG_DD39FE1AF60A-1.jpeg&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;p class=&quot;image-caption&quot;&gt;A subgradient of the absolute value function&lt;/p&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The subdifferential is the set of all vectors $g$ that satisfy the above inequality. These are useful because they can be computed so long as $f$ can be evaluated, which means we can derive optimization algorithms in terms of subgradients to make them more broadly applicable.&lt;/p&gt;

&lt;p&gt;Another new concept was the notion of $\rho$-weakly convex functions. We learned that regularizing your function to make it sort-of convex by adding a large quadratic to it results in what is known as a $\rho$-weakly convex function.&lt;/p&gt;

&lt;p&gt;Ultimately, John gave us three steps to follow:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Make a local approximation to your function&lt;/li&gt;
  &lt;li&gt;Add regularization to “avoid bouncing around like an idiot”&lt;/li&gt;
  &lt;li&gt;Optimize approximately&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;additional-resources&quot;&gt;Additional Resources&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://web.stanford.edu/~boyd/cvxbook/&quot;&gt;Convex Optimization - Boyd and Vandenberghe&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://arxiv.org/abs/1810.05633&quot;&gt;Stochastic (Approximate) Proximal Point Methods: Convergence, Optimality, and Adaptivity - Asi, Duchi&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;interpretability&quot;&gt;Interpretability&lt;/h2&gt;

&lt;p&gt;Lecturer: Sanmi Koyejo [&lt;a href=&quot;https://github.com/mlss-2019/slides/tree/master/interpretability&quot;&gt;Slides&lt;/a&gt;] [&lt;a href=&quot;https://videoken.com/embed/dMzqU9aaTFQ&quot;&gt;Video 1&lt;/a&gt;] [&lt;a href=&quot;https://videoken.com/embed/KO8rdIaij8s&quot;&gt;Video 2&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;Key takeaways:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;When building an ML system for a task where the repercussions of false positives/false negatives are unknown, it is usually best to defer decision-making to someone downstream&lt;/li&gt;
  &lt;li&gt;Monotonicity as an interpretability criterion: if feature $X$ “increases”, the output should “increase” as well&lt;/li&gt;
  &lt;li&gt;A standard definition of what it means for a model to be “interpretable” is still missing&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;additional-resources-1&quot;&gt;Additional Resources&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/jphall663/awesome-machine-learning-interpretability&quot;&gt;Awesome-ML-Interpretability&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://distill.pub/2017/feature-visualization/&quot;&gt;Distill Pub’s Feature Viz article&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.oreilly.com/learning/introduction-to-local-interpretable-model-agnostic-explanations-lime&quot;&gt;Introduction to LIME&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;gaussian-processes&quot;&gt;Gaussian Processes&lt;/h2&gt;

&lt;p&gt;Lecturer: James Hensman [&lt;a href=&quot;https://github.com/mlss-2019/slides/tree/master/gaussian_processes&quot;&gt;Slides&lt;/a&gt;] [&lt;a href=&quot;https://videoken.com/embed/GxZWMgRydoM&quot;&gt;Video 1&lt;/a&gt;] [&lt;a href=&quot;https://videoken.com/embed/uuKyVS5K8F0&quot;&gt;Video 2&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;GPs have always been a bit mind-boggling to me. Good thing MLSS was held in the UK, where there seems to be a high concentration of GP/Bayesian ML researchers. Also, James’ slides contain amazing visuals.&lt;/p&gt;

&lt;p&gt;What’s a GP? As Mackay puts it, GPs are smoothing techniques that involve placing a Gaussian prior over the &lt;em&gt;functions&lt;/em&gt; in the hypothesis class.&lt;/p&gt;

&lt;p&gt;I highly recommend checking out Lab 0 and Lab 1 from the GP practical &lt;a href=&quot;https://github.com/mlss-2019/tutorials/tree/master/gaussian_processes&quot;&gt;here&lt;/a&gt; which were great for building the intuitions.&lt;/p&gt;

&lt;h3 id=&quot;multivariate-normals&quot;&gt;Multivariate normals&lt;/h3&gt;

&lt;p&gt;GPs heavily make use of &lt;a href=&quot;https://en.wikipedia.org/wiki/Multivariate_normal_distribution&quot;&gt;multivariate normal distributions&lt;/a&gt; (MVN).
In fact, GPs are based on infinite-dimensional MVNs… It took a while for me to wrap my head around this, but these plots from James’ slides really helped:&lt;/p&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/img/MLSS/GP-1.png&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;p class=&quot;image-caption&quot;&gt;samples from a 2D MVN. See slides for GIF versions.&lt;/p&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The plot on the RHS is the important one. The x-axis represents the two dimensions of this MVN; there are no units for the x-axis, it simply depicts each of the N dimensions of an MVN from 1 to N (the order matters!). The y-axis depicts the values of a random variate sampled from this MVN. A line is drawn connecting $f(x_1)$ to $f(x_2)$. For a 6D MVN, there would be 6 ticks on the x-axis and a line connecting all 6 function values. The trick with GPs is that we (theoretically) let the number of dimensions go to infinity, so the x-axis becomes a continuum. But in practice, we only have a finite number of data points, and we assume the $(x_i, f(x_i))$ pairs are observations of this unknown function.&lt;/p&gt;

&lt;p&gt;Confused? Let’s take a step back. In Lab 0, we build some intuition by looking at Linear Regression and then the extension to Bayesian Linear Regression. For GP regression, we make the usual assumption that some unknown target function generated our data, except now our hypothesis class is much more expressive. GPs place a prior over the functions in the hypothesis class. They do this by defining a (Gaussian) stochastic process indexed by the data points:&lt;/p&gt;

\[p\Biggl(\begin{bmatrix} f(x_1)\\ f(x_2) \\ \cdots \\ f(x_n) \end{bmatrix} \Biggr) = \mathscr{N} \Biggl( \begin{bmatrix} \mu(x_1)\\ \mu(x_2) \\ \cdots \\ \mu(x_n) \end{bmatrix}, \begin{bmatrix} k(x_1, x_1) &amp;amp; \cdots &amp;amp; k(x_1,x_n)\\
                                \vdots  &amp;amp; &amp;amp;  \vdots \\
                                k(x_n, x_1) &amp;amp;  \cdots &amp;amp; k(x_n, x_n)\end{bmatrix} \Biggr).\]

&lt;h3 id=&quot;covariance-functions&quot;&gt;Covariance functions&lt;/h3&gt;
&lt;p&gt;Note that we can usually transform our data to be zero-mean, so the mean function $\mathbf{\mu}$ is generally assumed to be $0$ and our main concern is the kernel matrix $K$, also known as the gram matrix. $K$  is the &lt;strong&gt;covariance function&lt;/strong&gt; of the GP. Unlike regular (Bayesian) Linear Regression, GPs have a certain useful structure that comes with formulating the problem as a (Gaussian) stochastic process. That is, the kernel matrix $K$ enables us to incorporate prior knowledge about how we expect the data points to interact. In the next section, I’ll take about kernels and the kernel matrix $K$ in more detail.&lt;/p&gt;

&lt;p&gt;Once we have the basic machinery of GPs down, we can do some cool stuff like compute the conditional distribution of the function that fits a test point $x^*$ given a training set of point pairs $(x_i, f(x_i))$.&lt;/p&gt;

&lt;p&gt;We also covered model selection using the marginal likelihood of a GP. Kernels are typically parameterized by a lengthscale and variance parameter, and the marginal likelihood objective for selecting these kernel parameters nicely trades off model complexity with data fit.&lt;/p&gt;

&lt;p&gt;Finally, I’ll briefly mention something we touched on at the end of the GP lecture that was interesting. Since GPs require inverting $K$ to do inference, &lt;em&gt;sparse&lt;/em&gt; GPs cleverly select a small set of “pseudo-inputs” that approximate the original GP well and allow for using GPs on much larger datasets.&lt;/p&gt;

&lt;p&gt;GPs are useful in modern ML because many problems are concerned with interpolating a function given noisy observations using a Bayesian approach.&lt;/p&gt;

&lt;h3 id=&quot;additional-resources-2&quot;&gt;Additional Resources&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.gaussianprocess.org/gpml/chapters/&quot;&gt;Gaussian Processes for Machine Learning - Rasmussen and Williams&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://papers.nips.cc/paper/6877-convolutional-gaussian-processes&quot;&gt;Convolutional Gaussian Processes - van der Wilk, Rasmussen, Hensman&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://proceedings.mlr.press/v97/burt19a.html&quot;&gt;Rates of Convergence for Sparse Variational Gaussian Process Regression - Burt, Rasmussen, van der Wilk&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;kernels&quot;&gt;Kernels&lt;/h2&gt;

&lt;p&gt;Lecturer: Lorenzo Rosasco [&lt;a href=&quot;https://github.com/mlss-2019/slides/tree/master/kernels&quot;&gt;Slides&lt;/a&gt;] [&lt;a href=&quot;https://videoken.com/embed/6bUEdtUmh_4&quot;&gt;Video 1&lt;/a&gt;] [&lt;a href=&quot;https://videoken.com/embed/uHPi7q0QuY0&quot;&gt;Video 2&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;You may have heard of the &lt;em&gt;kernel trick&lt;/em&gt;, which involves replacing all inner products of features in an algorithm with a kernel evaluation, e.g., as in &lt;a href=&quot;https://sites.google.com/site/dataclusteringalgorithms/kernel-k-means-clustering-algorithm&quot;&gt;Kernel K-Means&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&quot;more-than-just-a-trick&quot;&gt;More than just a trick&lt;/h4&gt;

&lt;p&gt;Lorenzo showed us some recent work he’s been doing on scaling up kernel methods to the sizes of datasets commonly consumed by deep learning. To do this type of research, it is important to understand the theory of kernel methods. We covered some of this during the lecture, like Reproducing Kernel Hilbert Spaces (RKHSs). I think this lecture was one of the most difficult to swallow in the time allotted from the entire MLSS.&lt;/p&gt;

&lt;h4 id=&quot;rkhs&quot;&gt;RKHS&lt;/h4&gt;

&lt;p&gt;Here is my attempt to summarize my understanding of RKHSs. Please see Arthur’s notes (linked below), especially Section 4.1, for a great explanation.&lt;/p&gt;

&lt;p&gt;An RKHS is an abstract mathematical space closely intertwined with the notion of kernels. An RKHS is an extension of a Hilbert space; that is, it has all of the properties of a Hilbert space (it’s a vector space, has an inner product, and is complete), plus two other key properties. Note that RKHSs are &lt;em&gt;function spaces&lt;/em&gt;; the primitive object that lives in an RKHS is a function.&lt;/p&gt;

&lt;p&gt;In fact, &lt;em&gt;evaluating&lt;/em&gt; a function in the RKHS maps points from $\mathscr{X} \rightarrow \mathbb{R}$, where $\mathscr{X}$ is the data. However, the “representation” of a function in the RKHS could be an infinite-dimensional vector, if the feature maps corresponding to a particular kernel are infinite dimensional. Since we care about the inner product (evaluation) of the functions in the RKHS, we never actually have to deal with these individual, potentially infinite-dimensional representations. This took me a long time to wrap my head around (see Lemma 9 in Arthur’s notes).&lt;/p&gt;

&lt;p&gt;To my understanding, the fact that certain kernels (e.g., the RBF kernel) are said to lift your original feature space to an “infinite-dimensional feature space” comes from the fact that such a kernel is defined as an &lt;em&gt;infinite series&lt;/em&gt; of inner products of the original features. This is valid when the series converges (the assumption here is that each feature map is in L2).&lt;/p&gt;

&lt;p&gt;If we are given an RKHS, then the key tool we can leverage, which comes for free with the RKHS, is the reproducing property of said RKHS. The reproducing property of the RKHS says that the evaluation of any &lt;em&gt;function&lt;/em&gt; in the RKHS at a point $x \in \mathscr{X}$ is the inner product of the &lt;em&gt;function&lt;/em&gt; with the corresponding &lt;em&gt;reproducing kernel&lt;/em&gt; of the RKHS at the point. The Riesz representation theorem guarantees for us that such a reproducing kernel exists.&lt;/p&gt;

&lt;p&gt;Lorenzo showed us how we can start with feature maps and arrive at RKHSs. That is, if you aren’t given an RKHS, you can instead start by defining a kernel as the inner product $k(x,y) := \langle \phi(x), \phi(y) \rangle$ between feature maps. Equivalently, we can define a kernel as a symmetric, positive definite function $k : \mathscr{X} \times \mathscr{X} \rightarrow \mathbb{R}$, and a theorem (Moore-Aronszajn) tells us that there’s a corresponding RKHS for which $k$ is a reproducing kernel. However, in the latter case, there are infinitely many feature maps corresponding to the symmetric, positive definite function we started with.&lt;/p&gt;

&lt;h3 id=&quot;additional-resources-3&quot;&gt;Additional Resources&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.gatsby.ucl.ac.uk/~gretton/coursefiles/lecture4_introToRKHS.pdf&quot;&gt;Arthur Gretton’s course notes on RKHS&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.cs.toronto.edu/~duvenaud/cookbook/&quot;&gt;David Duvenaud’s notes on kernels&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;mcmc&quot;&gt;MCMC&lt;/h2&gt;

&lt;p&gt;Lecturer: Michael Betancourt [&lt;a href=&quot;https://github.com/mlss-2019/slides/tree/master/mcmc&quot;&gt;Slides&lt;/a&gt;] [&lt;a href=&quot;https://videoken.com/embed/UzcLe-kpMDQ&quot;&gt;Video 1&lt;/a&gt;] [&lt;a href=&quot;https://videoken.com/embed/drCwg49Ba_U&quot;&gt;Video 2&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;What is Bayesian computation?&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Specify a model&lt;/li&gt;
  &lt;li&gt;Compute posterior expectation values&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first part of our MCMC lecture was all about having us update our mental priors about high-dimensional statistics. For example, although we may think that the mode of a probability density contributes most to an integral when integrating over parameter space, this falls apart quickly in higher dimensions. This is because the relative amount of volume the mode occupies in high dimensions rapidly disappears ($d\theta \approx 0$), so that wherever the majority of the probability mass is sitting and occupying a non-trivial amount of volume ($d\theta$ » $0$) contributes most to the integral. We learned that probability mass concentrates on a thin and hard to find hypersurface called the &lt;em&gt;typical set&lt;/em&gt; in higher dimensions.&lt;/p&gt;

&lt;h3 id=&quot;what-about-variational-methods&quot;&gt;What about variational methods?&lt;/h3&gt;

&lt;p&gt;Variational inference, which replaces integration with an optimization problem and makes simplistic assumptions about the variational posterior, underestimates the variance and favors solutions that land inside the target typical set. Yikes!&lt;/p&gt;

&lt;h3 id=&quot;markov-chains&quot;&gt;Markov chains&lt;/h3&gt;

&lt;p&gt;Monte carlo methods use samples from the exact target typical set. Markov chains are great because a Markov transition that targets a particular distribution will naturally concentrate towards its probability mass. In practice for MCMC, Michael showed us that the chain quickly converges onto the typical set. The main challenge of MCMC methods seem to be handling various failure modes that cause divergence or cases where the chain gets stuck somewhere within the typical set.&lt;/p&gt;

&lt;h3 id=&quot;diagnosing-your-mcmc&quot;&gt;Diagnosing your MCMC&lt;/h3&gt;

&lt;p&gt;From the law of large numbers, we get that Markov chains are asymptotically consistent estimators. However, due to various pathologies, we need more sophisticated diagnostic tools and algorithms to get good finite time behavior. One diagnostic tool is the effective sample size (ESS). The more anti-correlated the samples from the Markov chain are, the higher the ESS.&lt;/p&gt;

&lt;p&gt;A robust strategy is to run multiple chains from various initial states and compare the expectations. Another strategy is to check the potential scale reduction factor, or R-hat, which is similar to an ANOVA between multiple chains.&lt;/p&gt;

&lt;h3 id=&quot;hamiltonian-monte-carlo&quot;&gt;Hamiltonian Monte Carlo&lt;/h3&gt;

&lt;p&gt;HMC is an alternative to Metropolis-Hastings MCMC. One issue with MH is that a naive Normal proposal density will almost always jump outside of the typical set, because most of the volume lies outside. Lowering the std dev of the proposal to avoid this means convergence will be too slow.&lt;/p&gt;

&lt;p&gt;We want to efficiently explore the typical set without leaving it. Insight: align a vector field to the typical set and then integrate along the field. HMC is the formal procedure for adding just enough &lt;em&gt;momentum&lt;/em&gt; to the gradient vector field to align the gradient field with the typical set. The analogy Michael used is that we need to add the momentum needed for a satellite to enter orbit around the earth.&lt;/p&gt;

&lt;p&gt;How to do this? Use Hamiltonian measure-preserving flow, which is a scalar function $H(p,q)$ of the parameters $q$ and momentum $p$ such that $H(p,q) = -log (\pi(p|q)) -\log (\pi(q))$. Here, $\pi(q)$ is the target density, which is specified by the problem. $\pi(p|q)$ is a conditional density for the momentum, which we choose. According to Michael, this is the only way of producing the gradient vector field we want to integrate along that actually works (this is a magic, hand-wavy thing).&lt;/p&gt;

&lt;p&gt;The Markov transitions now consist of randomly sampling a &lt;em&gt;Hamiltonian trajectory&lt;/em&gt;. Motion is governed by the above Hamiltonian, which has a kinetic and potential energy term. From the current location on the typical set, we randomly sample the momentum and the trajectory length, and then use an ODE numerical integrator to compute where we end up. I picture this like a marble being released with some initial momentum inside a bowl-shaped surface; wherever the marble finally rests after rolling around for a while is analogous to the next sample from the posterior we draw and is the next state of the chain.&lt;/p&gt;

&lt;p&gt;Numerical integration introduces some errors, so we have to be careful about the type of integration we use and how we correct for the introduced bias in our estimator. Use &lt;a href=&quot;https://mc-stan.org/&quot;&gt;Stan&lt;/a&gt; in practice for your MCMC needs.&lt;/p&gt;

&lt;h3 id=&quot;additional-resources-4&quot;&gt;Additional Resources&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://arxiv.org/abs/1701.02434&quot;&gt;A Conceptual Introduction to Hamiltonian Monte Carlo - Betancourt&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://betanalpha.github.io/writing/&quot;&gt;Michael Betancourt’s blog&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;fairness&quot;&gt;Fairness&lt;/h2&gt;

&lt;p&gt;Lecturer: Timnit Gebru [&lt;a href=&quot;https://github.com/mlss-2019/slides/tree/master/fairness&quot;&gt;Slides&lt;/a&gt;] [&lt;a href=&quot;https://videoken.com/embed/7uV_VohAwnw&quot;&gt;Video&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;Timnit gave an incredibly engaging lecture, which also doubled as a nice break from brain-bending equations. Here are some key takeaways:&lt;/p&gt;

&lt;p&gt;Timnit talked about “Fairwashing”, which is also discussed by Zachary Lipton in his &lt;a href=&quot;https://twimlai.com/twiml-talk-285-fairwashing-and-the-folly-of-ml-solutionism-with-zachary-lipton/&quot;&gt;recent TWiML interview&lt;/a&gt;. Basically, it is not enough to take a contentious research topic and simply try to “make it fair”. The idea of “make X fair” misses the point: we need to step back and critically consider the implications of doing the research in the first place. Ask: should we even be building this technology? And then the follow-up questions: if we don’t, will someone else build it anyways? If so, what do we do?&lt;/p&gt;

&lt;p&gt;We learned about her PhD project where they took Google street view images and ran computer vision data mining on images of cars to extract patterns about the US population. Since I grew up in Jacksonville, FL, I thought I’d include this slide showing that it is the 10th most segregated city (measured by disparity in average car prices) in the US. Yikes!&lt;/p&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/img/MLSS/jacksonville.png&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;p class=&quot;image-caption&quot;&gt;The red in the center is San Marco/Riverside. Duuuval&lt;/p&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;When the data is biased (and data collected out in the real world reflects the current state of the society from which it was extracted from), model predictions will be biased. Some examples we saw: using ML to predict who to hire, placing current ML techniques in the hands of ICE, predictive policing, gender classification, and facial recognition.&lt;/p&gt;

&lt;p&gt;Science is inherently political. We all have a responsibility to be cognizant of the &lt;a href=&quot;https://openai.com/blog/preparing-for-malicious-uses-of-ai/&quot;&gt;dual-use nature&lt;/a&gt; of the technologies we create. Even people working on “theory” must adhere to this. The people working on the foundations of our modern statistics (&lt;a href=&quot;https://en.wikipedia.org/wiki/Ronald_Fisher#Eugenics&quot;&gt;like Fisher&lt;/a&gt;) were eugenicists!&lt;/p&gt;

&lt;h3 id=&quot;additional-resources-5&quot;&gt;Additional Resources&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;https://arxiv.org/abs/1803.09010&quot;&gt;Datasheets for Datasets - Gebru et al.&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://arxiv.org/abs/1810.03993&quot;&gt;Model Cards for Model Reporting - Mitchell et al.&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://mitpress.mit.edu/books/sorting-things-out&quot;&gt;Sorting Things Out: Classification and its Consequences - Bowker and Star&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://ali-alkhatib.com/blog/anthropological-intelligence&quot;&gt;Anthropological/AI &amp;amp; the HAI - Ali Alkhatib&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.americaunderwatch.com/&quot;&gt;America Under Watch - Garvie, Moy&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;submodularity&quot;&gt;Submodularity&lt;/h2&gt;

&lt;p&gt;Lecturer: Stefanie Jegelka [&lt;a href=&quot;https://github.com/mlss-2019/slides/tree/master/submodular&quot;&gt;Slides&lt;/a&gt;] [&lt;a href=&quot;https://videoken.com/embed/P2mcH0RoPD0&quot;&gt;Video&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;This was a fairly niche topic and most people hadn’t heard of it. Essentially, it is a technique in combinatorial optimization for optimal subset selection. Subset selection is clearly relevant to ML, e.g., for active learning, coordinate selection, compression, and so on. However, optimizing a &lt;em&gt;set function&lt;/em&gt; over subsets $F(s), s \subseteq S$ is non-trivial; sets are discrete objects, and for any set $S$ there are $2^S$ possible subsets!&lt;/p&gt;

&lt;p&gt;It turns out there are specific classes of functions called &lt;em&gt;submodular functions&lt;/em&gt; that can be optimized in a reasonable amount of time. These functions have a property called &lt;em&gt;submodularity&lt;/em&gt;. In words, this means that if you have a subset $T$ and a subset $S$, and $T \subseteq S$, adding a new element $a \notin S$ to the “smaller” subset $T$ should give you a higher value than adding it to $S$. This is also referred to as diminishing gains. Written out, it is&lt;/p&gt;

\[F(T \cup \{a\}) - F(T) \geq F(S \cup \{a\}) - F(S), T \subseteq S, a \notin T.\]

&lt;p&gt;You can also think about $F$ like a concave function, such that its “discrete derivative” is non-increasing.&lt;/p&gt;

&lt;p&gt;An example of a submodular function is the coverage function: given $A_1, …, A_n \subset U$,&lt;/p&gt;

\[F(S) = \Bigl | \bigcup_{j \in S} A_j \Bigr |.\]

&lt;p&gt;As your coverage $|S|$ increases, the increase in the number of subsets in the union achieved by adding another index $j’$ to $S$ will be smaller.&lt;/p&gt;

&lt;h3 id=&quot;convex-or-concave&quot;&gt;Convex or concave?&lt;/h3&gt;

&lt;p&gt;It is not obvious whether submodular functions are more like convex or concave functions, as they share similarities with both. The fact that there are similarities hints at the reason why they are interesting, since convex and concave functions are “nice” to optimize in continuous optimization. We already mentioned the non-increasing discrete derivative property, which is similar to concave functions. The similarity to convexity comes from the fact that it is easier to &lt;em&gt;minimize&lt;/em&gt; a submodular function than it is to maximize one (e.g., Max Cut; this is NP-Hard).&lt;/p&gt;

&lt;h3 id=&quot;greedy-algorithms&quot;&gt;Greedy algorithms&lt;/h3&gt;

&lt;p&gt;We discussed greedy algorithms for maximizing submodular functions during the lecture. The basic algorithm for finding&lt;/p&gt;

&lt;p&gt;\(\max_{S} F(S) \texttt{ s.t. } |S| \leq k\)
 is as follows:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;$S_0 = \emptyset$&lt;/li&gt;
  &lt;li&gt;$\texttt{for } i=1,…,k-1$
    &lt;ol&gt;
      &lt;li&gt;$e^* = \texttt{arg max}_{e \in \mathscr{V} \setminus S_i} F(S_i \cup {e})$&lt;/li&gt;
      &lt;li&gt;$S_{i+1} = S_i \cup {e^*}$&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This works because $F$ is submodular - the marginal improvement of adding a single item gives information about the global value. Furthemore, $F$ is monotonic in that adding items can never reduce $F$. Lots more on this in the slides.&lt;/p&gt;

&lt;h3 id=&quot;continuous-relaxation-for-minimization&quot;&gt;Continuous relaxation for minimization&lt;/h3&gt;

&lt;p&gt;What if we want to minimize a submodular function? We can consider a continuous relaxations of $F$ to a convex function. The Lovasz extension provides a method for relaxing a function defined on the Boolean hypercube to $[0,1]^N$. The result is a piece-wise, linear convex function $f(z)$ that can be optimized using subgradient methods, and a final result can be obtained by rounding.&lt;/p&gt;

&lt;h3 id=&quot;additional-resources-6&quot;&gt;Additional Resources&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;https://theory.stanford.edu/~jvondrak/data/submod-tutorial-1.pdf&quot;&gt;Other intro tutorial slides - Vondrak&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://theory.stanford.edu/~jvondrak/CS369P/lec17.pdf&quot;&gt;More on the Lovasz Extension - Vondrak&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://melodi.ee.washington.edu/~bilmes/mypubs/iyer2015-spps.pdf&quot;&gt;Submodular Point Processes with Applications to Machine Learning - Iyer, Bilmes&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://arxiv.org/abs/1701.08939&quot;&gt;Deep Submodular Functions - Bilmes, Bai&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</description>
        <pubDate>Thu, 15 Aug 2019 00:00:00 +0000</pubDate>
        <link>https://pemami4911.github.io/blog/2019/08/15/mlss-2019.html</link>
        <guid isPermaLink="true">https://pemami4911.github.io/blog/2019/08/15/mlss-2019.html</guid>
        
        
        <category>blog</category>
        
      </item>
    
      <item>
        <title>Learning From Demonstrations in the Wild</title>
        <description>&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
  TeX: { equationNumbers: { autoNumber: &quot;AMS&quot; } },
  tex2jax: {inlineMath: [[&apos;$&apos;,&apos;$&apos;], [&apos;\\(&apos;,&apos;\\)&apos;]]}
});
&lt;/script&gt;

&lt;script type=&quot;text/javascript&quot; async=&quot;&quot; src=&quot;https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML&quot;&gt;
&lt;/script&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;a href=&quot;https://arxiv.org/abs/1811.03516v1&quot;&gt;Behbahani et al., 2018&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;p&gt;The motivation behind this work is to develop an automated process for learning the behaviors of road users from large amounts of unlabeled video data. A generative model (trained policy) of road user behavior could be used within a larger traffic scene understanding pipeline. In this paper, they propose Horizon GAIL, an imitation-learning algorithm based on GAIL, that stabilizes learning from demonstration (LfD) over long horizons. Expert policy demonstrations are provided by a slightly improved Deep SORT tracker, and they use PPO as the “student” RL algorithm. The Unity game engine is used to build an RL env that mimcs the scene from the real-world environment to rollout their PPO Horizon-GAIL agent. Their experiments are on 850 minutes of traffic camera data of a large roundabout. By using a curriculum where the episode horizon is extended by 1 timestep each training epoch, they demonstrated how Horizon-GAIL can match the expert policy’s state/action distribution much more closely than GAIL, PS-GAIL, and behavior cloning while also improving on training stability.&lt;/p&gt;

&lt;h2 id=&quot;observations&quot;&gt;Observations&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;The ability to auto-generate the Unity env from Google Maps would be crucial to scaling this technique up. maps2sim?&lt;/li&gt;
  &lt;li&gt;They provided an empirical comparison of DeepSORT with ViBe’s vision tracker, and showed that running the Kalman Filter in 3D space improved Deep SORT’s performance in multiple multi-object tracking metrics by a few percentage points&lt;/li&gt;
  &lt;li&gt;Each road user is modeled independently, i.e., the policy does not account for other agents in the environment explicitly. It looks like the policy used for learning vehicle and pedestrian behavior is the same, although because of the Mask R-CNN detector, they are able to differentiate between the two classes. In scenarios where the behaviors exhibited by the road users can be highly unpredictable and diverse (a busy traffic intersection with heavy pedestrian presence), perhaps a hierarchical policy could be useful that conditions on the inferred object class.&lt;/li&gt;
  &lt;li&gt;Interesting future work might include incorporating multi-agent modeling in the RL framework for more complex traffic scenarios.&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Wed, 26 Dec 2018 00:00:00 +0000</pubDate>
        <link>https://pemami4911.github.io/paper-summaries/computer-vision/2018/12/26/LfD-in-the-wild.html</link>
        <guid isPermaLink="true">https://pemami4911.github.io/paper-summaries/computer-vision/2018/12/26/LfD-in-the-wild.html</guid>
        
        
        <category>paper-summaries</category>
        
        <category>computer-vision</category>
        
      </item>
    
      <item>
        <title>Addressing Function Approximation Error in Actor-Critic Methods &amp; Discriminator-Actor-Critic- Addressing Sample Inefficiency and Reward Bias in Adversarial Imitation Learning</title>
        <description>&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
  TeX: { equationNumbers: { autoNumber: &quot;AMS&quot; } },
  tex2jax: {inlineMath: [[&apos;$&apos;,&apos;$&apos;], [&apos;\\(&apos;,&apos;\\)&apos;]]}
});
&lt;/script&gt;

&lt;script type=&quot;text/javascript&quot; async=&quot;&quot; src=&quot;https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML&quot;&gt;
&lt;/script&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;a href=&quot;https://arxiv.org/abs/1802.09477&quot;&gt;Fujimoto et al., 2018&lt;/a&gt; and &lt;a href=&quot;https://arxiv.org/abs/1809.02925v2&quot;&gt;Kostrikov et al., 2018&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;p&gt;I discuss two recent related papers in the Deep RL literature in this post. The first paper, by Fujimoto et al., introduces techniques for reducing bias and variance in a popular actor-critic method, Deep Deterministic Policy Gradient (DDPG). The second paper, by Kostrikov et al., makes a similar contribution by evaluating and addressing bias and variance in inverse RL. Both of these papers take widely used Deep RL algorithms, empirically and theoretically demonstrate specific weaknesses, and suggest reasonable improvements. These are valuable studies that help develop a better understanding of Deep RL.&lt;/p&gt;

&lt;h3 id=&quot;addressing-function-approx-error-in-ac-methods&quot;&gt;Addressing Function Approx. Error in AC Methods&lt;/h3&gt;

&lt;p&gt;If you are unfamiliar with DDPG, you can check out &lt;a href=&quot;https://pemami4911.github.io/blog/2016/08/21/ddpg-rl.html&quot;&gt;my blog post&lt;/a&gt; on the algorithm. The most important thing to know is that the success of the whole algorithm relies on having a critic network that can accurately estimate $Q$-values. The only signal the actor network gets in its gradient to help it achieve higher rewards comes from the gradient of the critic wrt the actions selected by the actor. If the critic gradient is biased, then the actor will fail to learn anything!&lt;/p&gt;

&lt;p&gt;In Section 4, the authors begin by empirically demonstrating the overestimation bias present in the critic network (action-value estimator) in DDPG. They show that the overestimation bias essentially stems from the fact that DPG algorithms have to approximate both the policy and the value functions, and the approximate policy is maximized in the gradient direction provided by the approximate value function (rather than the true value function). Then, inspired by Double Q-Learning, they introduce a technique they call “clipped Double Q-Learning in AC” for achieving the same idea. Basically, the critic target becomes
\(y_1 = r + \gamma \min_{i=1,2} Q_{\theta&apos;_i} (s&apos;, \pi_{\theta_1}(s&apos;)).\)
This requires introducing a second critic. The min makes it so that it is possible to underestimate Q-values, but this is preferable to overestimation.&lt;/p&gt;

&lt;p&gt;Then, to help with variance reduction, they suggest:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Delay updating the actor network until the critic network has almost converged&lt;/li&gt;
  &lt;li&gt;Add some noise to the actions selected by the actor network when updating the critic to help regularize the critic, reminiscent of Expected SARSA&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Their experimental results on MuJoco (they call their algorithm TD3) suggest these improvements are very effective, outperforming PPO, TRPO, ACKTR, and others.&lt;/p&gt;

&lt;h3 id=&quot;discriminator-actor-critic-addressing-sample-inefficiency-and-reward-bias-in-adversarial-imitation-learning&quot;&gt;Discriminator-Actor-Critic: Addressing Sample Inefficiency and Reward Bias in Adversarial Imitation Learning&lt;/h3&gt;
&lt;p&gt;EDIT: The title of the paper was previously “Addressing Sample Inefficiency and Reward Bias in Inverse RL”&lt;/p&gt;

&lt;p&gt;Seemingly inspired by the former, this paper recently came out exploring inverse RL—specifically, generative adversarial imitation learning (GAIL) and behavioral cloning. In GAIL, the discriminator learns to distinguish between transitions sampled from an expert and those from a trained policy. The policy is rewarded for confusing the discrminiator. However, GAIL is typically quite sample inefficient.&lt;/p&gt;

&lt;p&gt;One way the authors suggest to help with the sample inefficiency of GAIL is by using off-policy RL instead of on-policy RL. They modify the GAIL objective to be 
\(\max_D \mathcal{E}_\mathscr{R} [\log(D(s,a))] + \mathcal{E}_{\pi_E}[\log(1 - D(s,a))] - \lambda H(\pi).\)
Basically, $\pi_E$ is the expert policy, from which trajectories are sampled, and $\mathscr{R}$ is the replay buffer, from which trajectories are sampled from ~all previous policies. They ignore the importance sampling term in practice. Since TD3 is technically a deterministic policy gradient algorithm, I’m assuming one way to implement this importance sampling would be to have the actor output the mean of a multivariate Gaussian—this Gaussian could then be used to define the entropy term of the policy and the importance sampling ratio. This is fairly common for continuous control tasks like MuJoco…the authors note that the importance sampling wasn’t used in practice, however.&lt;/p&gt;

&lt;p&gt;They further analyzed different reward functions for GAIL, and show that certain GAIL reward functions can actually &lt;em&gt;inhibit&lt;/em&gt; learning depending on the particular MDP (e.g., if the environment has a survival bonus or penalty). To create a more robust reward function that will learn the expert policies, &lt;em&gt;they suggest explicitly learning rewards for absorbing states of the MDP&lt;/em&gt;. They implement this by adding an indicator to these particular states so that the GAIL discriminator can identify whether reaching an absorbing state is desirable from the perspective of the expert. In the &lt;a href=&quot;https://openreview.net/pdf?id=Hk4fpoA5Km&quot;&gt;OpenReview thread&lt;/a&gt;, one reviewer makes sure to point out that the problems with inverse RL algorithms highlighted in the paper are due to incorrect implementations of the MDP, rather than shortcomings of the algorithms themselves (&lt;a href=&quot;https://openreview.net/forum?id=Hk4fpoA5Km&amp;amp;noteId=B1gGZfAq6Q&quot;&gt;see this comment in particular&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Very interestingly, they used VR to generate expert trajectories of gripping blocks with a Kuka arm. This environment has a per-step penalty, and the normal GAIL reward fails to learn the expert policy due to the the learning inhibition caused by the reward function bias. The proposed method learns to imitate the expert quickly due to its added reward for absorbing states.&lt;/p&gt;

&lt;p&gt;It would be great to investigate the effects of using off-policy samples in the objective more carefully (why exactly does importance sampling not matter? The absorbing state reward stuff being so useful is surprising, and should be helpful in future applications where GAIL is used for inverse RL.&lt;/p&gt;
</description>
        <pubDate>Thu, 13 Sep 2018 00:00:00 +0000</pubDate>
        <link>https://pemami4911.github.io/paper-summaries/deep-rl/2018/09/13/addressing-challenges-in-deep-rl.html</link>
        <guid isPermaLink="true">https://pemami4911.github.io/paper-summaries/deep-rl/2018/09/13/addressing-challenges-in-deep-rl.html</guid>
        
        
        <category>paper-summaries</category>
        
        <category>deep-RL</category>
        
      </item>
    
      <item>
        <title>RUDDER: Return Decomposition for Delayed Rewards</title>
        <description>&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
  TeX: { equationNumbers: { autoNumber: &quot;AMS&quot; } },
  tex2jax: {inlineMath: [[&apos;$&apos;,&apos;$&apos;], [&apos;\\(&apos;,&apos;\\)&apos;]]}
});
&lt;/script&gt;

&lt;script type=&quot;text/javascript&quot; async=&quot;&quot; src=&quot;https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML&quot;&gt;
&lt;/script&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;a href=&quot;https://arxiv.org/abs/1806.07857v1&quot;&gt;Arjona-Medina, Gillhofer, et al., 2018&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;/h2&gt;

&lt;p&gt;Delayed rewards is one of the fundamental challenges of reinforcement learning. This paper proposes an algorithm for converting an MDP with delayed rewards into a different MDP with equivalent optimal policies where the delayed reward is now converted into immediate rewards. They accomplish this with “reward redistribution”—a potential solution to the RL credit assignment problem.&lt;/p&gt;

&lt;p&gt;Basically, they argue that reward redistribution enables monte-carlo (MC) and temporal-difference (TD) methods to be applied under delayed rewards without high variance or biasing the Q-values. This is important, because TD methods are the most commonly used RL approach, and it is proven in this paper that with delayed rewards TD methods take time exponential in the length of the delay to remove the bias.&lt;/p&gt;

&lt;h3 id=&quot;some-details-about-rudder&quot;&gt;Some details about RUDDER&lt;/h3&gt;

&lt;p&gt;One of the main obstacles that is addressed in Section 3 is proving that the new MDP with redistributed rewards has the same optimal policies as the original MDP. I found that this section (and the previous) were unecessarily hard to read, but here is my take on what the key points are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Because the delayed reward MDP obeys the Markov property, the transformed MDP with equivalent optimal policies but immediate rewards needs to have an altered set of states. This altered set of states obey the Markov property for predicting the immediate rewards, but crucially, not for the delayed reward. This is accomplished by using differences between states $\triangle (s, s’)$ in the delayed reward MDP as the new set of states&lt;/li&gt;
  &lt;li&gt;The return of the delayed reward MDP at the end of an episode should be predicted by a function $g$ (the LSTM) that can be decomposed into a sum over the state, action pairs of the episode&lt;/li&gt;
  &lt;li&gt;It should hold that the partial sums that all together sum to $g$, $\sum_{\tau = 0}^{t} h(a_{\tau}, \triangle(s_{\tau}, s_{\tau+1}))$, equal the Q-values at time $t$ for the reward redistribution to be optimal&lt;/li&gt;
  &lt;li&gt;This approach requires strong exploration that can actually uncover the delayed reward. If a robot gets a +1 for doing the dishes correctly and +0 reward otherwise, it may &lt;em&gt;never&lt;/em&gt; even see the +1 in the first place!&lt;/li&gt;
  &lt;li&gt;To help with the above, they use a “lessons replay buffer” to store episodes where the delayed reward was observed, to sample from when computing gradients for improved data efficiency&lt;/li&gt;
  &lt;li&gt;An LSTM is used for the return prediction, and techniques for credit assignment in deep learning like layer-wise relevance propagation and integrated gradients are used for “backwards analysis” to accomplish the reward redistribution. This gets pretty complex, and the appendix goes into detail of how they modified the LSTM cell for this (something called a “monotonic LSTM”)&lt;/li&gt;
  &lt;li&gt;They have to introduce other auxiliary tasks to encourage the reward prediction LSTM network to learn the optimal reward redistribution and get around the Markov property problem mentioned earlier. These aux tasks are to predict the q-values, predict the reward in the next 10 steps, and predict the reward accumulated from time 0 so far&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;experimental-results&quot;&gt;Experimental results&lt;/h2&gt;

&lt;p&gt;The authors note that RUDDER is aimed at RL problems with (i) delayed rewards (ii) no distractions due to other rewards or changing characteristics of the environment (iii) no skills to be learned to receive the delayed reward. (iii) seems to imply that RUDDER could be combined with hierarchical RL. (ii) suggests that when there are sporadic rewards throughout an episode, the improvements from RUDDER might be minimized. Hence, the environments they experiment with all have heavily delayed rewards observed only at the end of the episode, and their results are naturally impressive. I understand the difficulty (high computational/$$$ cost) in evaluating on all 50-something Atari games, but it would be really nice to see how it fares on other games that aren’t perfectly set up for RUDDER.&lt;/p&gt;

&lt;p&gt;They also note that human demonstrations could be used to fill the lessons buffer, which might further improve recent &lt;a href=&quot;https://arxiv.org/abs/1805.11592&quot;&gt;impressive imitation learning results&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;grid-world&quot;&gt;Grid world&lt;/h3&gt;

&lt;p&gt;They compute an optimal policy for a simple grid world with a delayed reward MDP. Then, they compute the bias and variance from the mean square error (MSE) of the Q-values for MC and TD estimators with policy evaluation. They demonstrate the exponential dependency on the reward delay length for the MC and TD methods by varying the delay. RUDDER shows favorable reductions in the bias and variance of estimated vs. optimal Q-values at all delay lengths.&lt;/p&gt;

&lt;h3 id=&quot;charge-discharge&quot;&gt;Charge-discharge&lt;/h3&gt;

&lt;p&gt;Simple 2-state and 2-action MDP with episodes of variable length and delayed reward obtained only at the end of the episode. RUDDER augmenting a Q-learning agent is much more data efficient than pure Q-learning, MC agent, and MCTS.&lt;/p&gt;

&lt;h2 id=&quot;atari-evaluation&quot;&gt;Atari evaluation&lt;/h2&gt;

&lt;p&gt;The most impressive results of the paper are the scores for the Venture and Bowling Atari games. They set new SOTA on Venture.
They augment &lt;a href=&quot;https://arxiv.org/abs/1707.06347&quot;&gt;PPO&lt;/a&gt; with the return prediction network paired with integrated gradients for backwards analysis. The lessons buffer is used to train both the return prediction network and A2C (for PPO). I’m not sure about that because I thought PPO was an on-policy algorithm- using episodes from the lessons buffer would bias the policy gradient? They use the difference between two consecutive frames for $\triangle(s, s’)$ plus the current frame (for seeing static objects) as input.&lt;/p&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/img/rudder-arch.png&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;p class=&quot;image-caption&quot;&gt;NN architectures for RUDDER augmenting PPO&lt;/p&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/img/rudder.png&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;p class=&quot;image-caption&quot;&gt;Visual depiction of the reward redistribution&lt;/p&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;They show that RUDDER is much more data efficient than APE-X, DDQN, Noisy-DQN, Rainbow, and other SOTA Deep RL approaches on these two games. &lt;a href=&quot;https://goo.gl/EQerZV&quot;&gt;Video&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;closing-thoughts&quot;&gt;Closing thoughts&lt;/h2&gt;

&lt;p&gt;I think this is an exciting RL paper that will have a major impact. Mainly because I can see lots of future research refining the ideas from this paper and then applying it to a variety of domains, especially in robotics. This paper could use polishing (some parts are not easy to read) and some more experiments showing how it performs on MDPs with both delayed rewards and also some other “distractor” rewards. I think this setting is most common, as it’s usually possible to do a little reward hacking to augment sparse/delayed reward MDPs. In the appendix, they go into the engineering details on how they got this to work, and it seems like that process + how the hyperparameters/auxiliary tasks/choice of method for backwards analysis will need to change for different environments will need to get cleaned up before making this approach widely useful.&lt;/p&gt;
</description>
        <pubDate>Fri, 22 Jun 2018 00:00:00 +0000</pubDate>
        <link>https://pemami4911.github.io/paper-summaries/reinforcement-learning-theory/2018/06/22/rudder.html</link>
        <guid isPermaLink="true">https://pemami4911.github.io/paper-summaries/reinforcement-learning-theory/2018/06/22/rudder.html</guid>
        
        
        <category>paper-summaries</category>
        
        <category>reinforcement-learning-theory</category>
        
      </item>
    
      <item>
        <title>Z-Forcing: Training Stochastic Recurrent Networks</title>
        <description>&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
  TeX: { equationNumbers: { autoNumber: &quot;AMS&quot; } },
  tex2jax: {inlineMath: [[&apos;$&apos;,&apos;$&apos;], [&apos;\\(&apos;,&apos;\\)&apos;]]}
});
&lt;/script&gt;

&lt;script type=&quot;text/javascript&quot; async=&quot;&quot; src=&quot;https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML&quot;&gt;
&lt;/script&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;a href=&quot;http://papers.nips.cc/paper/7248-z-forcing-training-stochastic-recurrent-networks&quot;&gt;Goyal, et al., 2017&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;/h2&gt;

&lt;p&gt;A new training procedure for recurrent VAEs is proposed. Recall that for VAEs, we model a joint distribution over observations $x$ and latent variables $z$, and assume that $z$ is involved in the generation of $x$. This distribution is parameterized by $\theta$. Maximizing the marginal log-likelihood $p_{\theta}(x)$ wrt $\theta$ is intractable bc it requires integrating over $z$. Instead, introduce a variational distribution $q_{\phi}(z|x)$ and maximize a lower bound on the marginal log-likelihood–the ELBO.&lt;/p&gt;

&lt;h3 id=&quot;stochastic-recurrent-networks&quot;&gt;Stochastic recurrent networks&lt;/h3&gt;

&lt;p&gt;When applying VAEs to sequences, it has been proposed to use recurrent networks for the recognition network (aka inference network aka variation posterior) and the generation network (aka decoder aka conditional probability of the next observation given previous observations and latents). These probabilistic models can be autoregressive (in this paper, they use LSTMs with MLPs for predicting the parameters of Gaussian distributions). It is common to model these conditional distributions with Gaussians for continuous variables or categoricals for discrete variables.&lt;/p&gt;

&lt;p&gt;Usually, the prior over latent variables is also learned with a parametric model.&lt;/p&gt;

&lt;p&gt;If I’m not mistaken, learning the parameters of these parametric models with a training data set, and the using them at test time for fast inference is referred to as &lt;em&gt;amortized variational inference&lt;/em&gt;, which appears to have &lt;a href=&quot;http://gershmanlab.webfactional.com/pubs/GershmanGoodman14.pdf&quot;&gt;correlaries in our cognition&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;z-forcing&quot;&gt;Z-forcing&lt;/h3&gt;

&lt;p&gt;Strong autoregressive decoders overpower the latent variables $z$, preventing the CPD from learning complex multi-modal distributions. To mitigate this, they introduce an auxiliary cost to the training objective. An extra parametric model is introduced, $p_{\eta}(b | z)$, that “forces” the latents to be predictive of the hidden states $b$ of the “backward network” (the inference network).&lt;/p&gt;

&lt;h2 id=&quot;experiments&quot;&gt;Experiments&lt;/h2&gt;

&lt;p&gt;They validate the approach on speech modeling (TIMIT, Blizzard) and language modeling. The metric is average LL. On Seqeuential MNIST, z-forcing is competitive with “deeper” recurrent generative models like PixelRNN.&lt;/p&gt;

&lt;div&gt;
	&lt;div class=&quot;image-wrapper&quot;&gt;
	
	&lt;img src=&quot;/img/z-forcing-interp.png&quot; alt=&quot;&quot; width=&quot;&quot; height=&quot;&quot; /&gt;
	
	&lt;/div&gt;
	&lt;div&gt;
	
	&lt;p class=&quot;image-caption&quot;&gt;Some fun language modeling results interpolating the latent space&lt;/p&gt;
	
	&lt;/div&gt;
&lt;/div&gt;

&lt;h2 id=&quot;takeaways&quot;&gt;Takeaways&lt;/h2&gt;

&lt;p&gt;It’s always a consideration as to whether increasing the complexity of an approach (adding an extra network and auxiliary cost) is worth the effort vs. simpler approaches that can get almost the same performance. The results on TIMIT and Blizzard are pretty convincing. The authors also suggest incorporating the auxiliary loss with PixelRNN/CNN in future work.&lt;/p&gt;

</description>
        <pubDate>Fri, 22 Jun 2018 00:00:00 +0000</pubDate>
        <link>https://pemami4911.github.io/paper-summaries/natural-language-processing/2018/06/22/z-forcing.html</link>
        <guid isPermaLink="true">https://pemami4911.github.io/paper-summaries/natural-language-processing/2018/06/22/z-forcing.html</guid>
        
        
        <category>paper-summaries</category>
        
        <category>natural-language-processing</category>
        
      </item>
    
      <item>
        <title>Tracking Occluded Objects and Recovering Incomplete Trajectories by Reasoning about Containment Relations and Human Actions</title>
        <description>&lt;script type=&quot;text/x-mathjax-config&quot;&gt;
MathJax.Hub.Config({
  TeX: { equationNumbers: { autoNumber: &quot;AMS&quot; } },
  tex2jax: {inlineMath: [[&apos;$&apos;,&apos;$&apos;], [&apos;\\(&apos;,&apos;\\)&apos;]]}
});
&lt;/script&gt;

&lt;script type=&quot;text/javascript&quot; async=&quot;&quot; src=&quot;https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML&quot;&gt;
&lt;/script&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;a href=&quot;https://pdfs.semanticscholar.org/4170/0dc1e60f5c8eaef409ef014f37c8b9e1b8cd.pdf&quot;&gt;Liang, Zhu, Zhu, 2018&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;p&gt;This paper looks at tracking severely occluded objects in long video sequences.&lt;/p&gt;

&lt;p&gt;I like this passage:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Although some recent work adopted deep neural networks
to extract contexts for object detection and tracking, these
data-driven feedforward methods have well-known problems:
i) They are black-box models that cannot be explained
and only applicable with supervised training by fitting the
typical context of the object, thus difficult to generalize
to new tasks. ii) Lacking explicit representation to handle
occlusions, low resolution, and lighting variations—there
are millions of ways to occlude an object in a given image
 (Wang et al. 2017), making it impossible to have enough
data for training and testing such black box models. In this
paper, we go beyond passive recognition by reasoning about
time-varying containment relations.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;They look at &lt;em&gt;containment relations&lt;/em&gt; induced by human activity. A containment relation occurs when an object contains or holds another object, obscuring it from view. Contained objects have the same trajectories as the container.&lt;/p&gt;

&lt;p&gt;They use an idea that I have thought about as well and think is powerful; rather than only relying on detections for next state hypotheses, they suggest alternative hypotheses based on occlusion reasoning. The other hypotheses come from containment relations and blocked relations; if an object is contained, it inherits the track state of its container. If an object is blocked, its track state is considered stationary (not always true!).&lt;/p&gt;

&lt;p&gt;This tracking scenario is unique because they only consider human action as the source of state change (i.e., this approach doesn’t apply to general ped or vehicle tracking).&lt;/p&gt;

&lt;p&gt;They use state-of-the-art detection and activity recognition to carry out object tracking. They use the network flow approach for occlusion-aware data association in a sliding window. I think their algorithm has to decide between containment and blocked occlusion events via the activity recognition.&lt;/p&gt;

&lt;p&gt;They note that their approach is limited by how good object detection is. I think an important direction to consider is when external forces other than people can act on the object. This requires a lot more complex modeling of what an occluded object might be doing. Also, we need better object detection!&lt;/p&gt;

&lt;h2 id=&quot;interesting-related-works&quot;&gt;Interesting related works&lt;/h2&gt;

&lt;p&gt;In &lt;a href=&quot;https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&amp;amp;arnumber=4587584&quot;&gt;Zhang, Li, and Nevatia 2008&lt;/a&gt;, they use an Explicit Occlusion Model (EOM) in the network flow data association model. Good potential baseline.&lt;/p&gt;
</description>
        <pubDate>Sun, 03 Jun 2018 00:00:00 +0000</pubDate>
        <link>https://pemami4911.github.io/paper-summaries/computer-vision/2018/06/03/tracking-occluded-objects-by-reasoning-about-containment.html</link>
        <guid isPermaLink="true">https://pemami4911.github.io/paper-summaries/computer-vision/2018/06/03/tracking-occluded-objects-by-reasoning-about-containment.html</guid>
        
        
        <category>paper-summaries</category>
        
        <category>computer-vision</category>
        
      </item>
    
  </channel>
</rss>
