зеркало из
				https://github.com/ssciwr/AMMICO.git
				synced 2025-10-31 22:16:05 +02:00 
			
		
		
		
	
		
			
				
	
	
		
			356 строки
		
	
	
		
			17 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			356 строки
		
	
	
		
			17 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| <!DOCTYPE html>
 | |
| <html class="writer-html5" lang="en" >
 | |
| <head>
 | |
|   <meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
 | |
| 
 | |
|   <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 | |
|   <title>Objects Expression recognition — AMMICO 0.0.1 documentation</title>
 | |
|       <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
 | |
|       <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
 | |
|       <link rel="stylesheet" href="../_static/nbsphinx-code-cells.css" type="text/css" />
 | |
|   <!--[if lt IE 9]>
 | |
|     <script src="../_static/js/html5shiv.min.js"></script>
 | |
|   <![endif]-->
 | |
|   
 | |
|         <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
 | |
|         <script src="../_static/doctools.js"></script>
 | |
|         <script src="../_static/sphinx_highlight.js"></script>
 | |
|         <script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
 | |
|         <script src="https://cdn.jsdelivr.net/npm/@jupyter-widgets/html-manager@^1.0.1/dist/embed-amd.js"></script>
 | |
|         <script>window.MathJax = {"tex": {"inlineMath": [["$", "$"], ["\\(", "\\)"]], "processEscapes": true}, "options": {"ignoreHtmlClass": "tex2jax_ignore|mathjax_ignore|document", "processHtmlClass": "tex2jax_process|mathjax_process|math|output_area"}}</script>
 | |
|         <script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
 | |
|     <script src="../_static/js/theme.js"></script>
 | |
|     <link rel="index" title="Index" href="../genindex.html" />
 | |
|     <link rel="search" title="Search" href="../search.html" />
 | |
|     <link rel="next" title="AMMICO package modules" href="../modules.html" />
 | |
|     <link rel="prev" title="Image Multimodal Search" href="Example%20multimodal.html" /> 
 | |
| </head>
 | |
| 
 | |
| <body class="wy-body-for-nav"> 
 | |
|   <div class="wy-grid-for-nav">
 | |
|     <nav data-toggle="wy-nav-shift" class="wy-nav-side">
 | |
|       <div class="wy-side-scroll">
 | |
|         <div class="wy-side-nav-search" >
 | |
| 
 | |
|           
 | |
|           
 | |
|           <a href="../index.html" class="icon icon-home">
 | |
|             AMMICO
 | |
|           </a>
 | |
| <div role="search">
 | |
|   <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
 | |
|     <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
 | |
|     <input type="hidden" name="check_keywords" value="yes" />
 | |
|     <input type="hidden" name="area" value="default" />
 | |
|   </form>
 | |
| </div>
 | |
|         </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
 | |
|               <p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
 | |
| <ul class="current">
 | |
| <li class="toctree-l1"><a class="reference internal" href="../readme_link.html">AMMICO - AI Media and Misinformation Content Analysis Tool</a></li>
 | |
| <li class="toctree-l1"><a class="reference internal" href="Example%20faces.html">Facial Expression recognition with DeepFace</a></li>
 | |
| <li class="toctree-l1"><a class="reference internal" href="Example%20text.html">Text extraction on image</a></li>
 | |
| <li class="toctree-l1"><a class="reference internal" href="Example%20summary.html">Image summary and visual question answering</a></li>
 | |
| <li class="toctree-l1"><a class="reference internal" href="Example%20multimodal.html">Image Multimodal Search</a></li>
 | |
| <li class="toctree-l1 current"><a class="current reference internal" href="#">Objects Expression recognition</a><ul>
 | |
| <li class="toctree-l2"><a class="reference internal" href="#Manually-inspect-what-was-detected">Manually inspect what was detected</a></li>
 | |
| <li class="toctree-l2"><a class="reference internal" href="#Detect-objects-and-directly-write-to-csv">Detect objects and directly write to csv</a></li>
 | |
| </ul>
 | |
| </li>
 | |
| <li class="toctree-l1"><a class="reference internal" href="../modules.html">AMMICO package modules</a></li>
 | |
| <li class="toctree-l1"><a class="reference internal" href="../license_link.html">License</a></li>
 | |
| </ul>
 | |
| 
 | |
|         </div>
 | |
|       </div>
 | |
|     </nav>
 | |
| 
 | |
|     <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
 | |
|           <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
 | |
|           <a href="../index.html">AMMICO</a>
 | |
|       </nav>
 | |
| 
 | |
|       <div class="wy-nav-content">
 | |
|         <div class="rst-content">
 | |
|           <div role="navigation" aria-label="Page navigation">
 | |
|   <ul class="wy-breadcrumbs">
 | |
|       <li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
 | |
|       <li class="breadcrumb-item active">Objects Expression recognition</li>
 | |
|       <li class="wy-breadcrumbs-aside">
 | |
|             <a href="../_sources/notebooks/Example objects.ipynb.txt" rel="nofollow"> View page source</a>
 | |
|       </li>
 | |
|   </ul>
 | |
|   <hr/>
 | |
| </div>
 | |
|           <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
 | |
|            <div itemprop="articleBody">
 | |
|              
 | |
|   <section id="Objects-Expression-recognition">
 | |
| <h1>Objects Expression recognition<a class="headerlink" href="#Objects-Expression-recognition" title="Permalink to this heading"></a></h1>
 | |
| <p>This notebooks shows some preliminary work on detecting objects expressions with cvlib. It is mainly meant to explore its capabilities and to decide on future research directions. We package our code into a <code class="docutils literal notranslate"><span class="pre">ammico</span></code> package that is imported here:</p>
 | |
| <div class="nbinput nblast docutils container">
 | |
| <div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[1]:
 | |
| </pre></div>
 | |
| </div>
 | |
| <div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">ammico</span>
 | |
| <span class="kn">from</span> <span class="nn">ammico</span> <span class="kn">import</span> <span class="n">utils</span> <span class="k">as</span> <span class="n">mutils</span>
 | |
| <span class="kn">from</span> <span class="nn">ammico</span> <span class="kn">import</span> <span class="n">display</span> <span class="k">as</span> <span class="n">mdisplay</span>
 | |
| <span class="kn">import</span> <span class="nn">ammico.objects</span> <span class="k">as</span> <span class="nn">ob</span>
 | |
| </pre></div>
 | |
| </div>
 | |
| </div>
 | |
| <p>Set an image path as input file path.</p>
 | |
| <div class="nbinput nblast docutils container">
 | |
| <div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[2]:
 | |
| </pre></div>
 | |
| </div>
 | |
| <div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">images</span> <span class="o">=</span> <span class="n">mutils</span><span class="o">.</span><span class="n">find_files</span><span class="p">(</span>
 | |
|     <span class="n">path</span><span class="o">=</span><span class="s2">"data/"</span><span class="p">,</span>
 | |
|     <span class="n">limit</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span>
 | |
| <span class="p">)</span>
 | |
| </pre></div>
 | |
| </div>
 | |
| </div>
 | |
| <div class="nbinput nblast docutils container">
 | |
| <div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[3]:
 | |
| </pre></div>
 | |
| </div>
 | |
| <div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">mydict</span> <span class="o">=</span> <span class="n">mutils</span><span class="o">.</span><span class="n">initialize_dict</span><span class="p">(</span><span class="n">images</span><span class="p">)</span>
 | |
| </pre></div>
 | |
| </div>
 | |
| </div>
 | |
| <section id="Manually-inspect-what-was-detected">
 | |
| <h2>Manually inspect what was detected<a class="headerlink" href="#Manually-inspect-what-was-detected" title="Permalink to this heading"></a></h2>
 | |
| <p>To check the analysis, you can inspect the analyzed elements here. Loading the results takes a moment, so please be patient. If you are sure of what you are doing.</p>
 | |
| <div class="nbinput docutils container">
 | |
| <div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[4]:
 | |
| </pre></div>
 | |
| </div>
 | |
| <div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">mdisplay</span><span class="o">.</span><span class="n">explore_analysis</span><span class="p">(</span><span class="n">mydict</span><span class="p">,</span> <span class="n">identify</span><span class="o">=</span><span class="s2">"objects"</span><span class="p">)</span>
 | |
| </pre></div>
 | |
| </div>
 | |
| </div>
 | |
| <div class="nboutput nblast docutils container">
 | |
| <div class="prompt empty docutils container">
 | |
| </div>
 | |
| <div class="output_area docutils container">
 | |
| <div class="highlight"><pre>
 | |
| <span class="ansi-red-fg">---------------------------------------------------------------------------</span>
 | |
| <span class="ansi-red-fg">AttributeError</span>                            Traceback (most recent call last)
 | |
| Cell <span class="ansi-green-fg">In[4], line 1</span>
 | |
| <span class="ansi-green-fg">----> 1</span> <span class="ansi-yellow-bg">mdisplay</span><span class="ansi-yellow-bg" style="color: rgb(98,98,98)">.</span><span class="ansi-yellow-bg">explore_analysis</span>(mydict, identify<span style="color: rgb(98,98,98)">=</span><span style="color: rgb(175,0,0)">"</span><span style="color: rgb(175,0,0)">objects</span><span style="color: rgb(175,0,0)">"</span>)
 | |
| 
 | |
| <span class="ansi-red-fg">AttributeError</span>: module 'ammico.display' has no attribute 'explore_analysis'
 | |
| </pre></div></div>
 | |
| </div>
 | |
| </section>
 | |
| <section id="Detect-objects-and-directly-write-to-csv">
 | |
| <h2>Detect objects and directly write to csv<a class="headerlink" href="#Detect-objects-and-directly-write-to-csv" title="Permalink to this heading"></a></h2>
 | |
| <div class="nbinput docutils container">
 | |
| <div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[5]:
 | |
| </pre></div>
 | |
| </div>
 | |
| <div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">mydict</span><span class="p">:</span>
 | |
|     <span class="n">mydict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">ob</span><span class="o">.</span><span class="n">ObjectDetector</span><span class="p">(</span><span class="n">mydict</span><span class="p">[</span><span class="n">key</span><span class="p">])</span><span class="o">.</span><span class="n">analyse_image</span><span class="p">()</span>
 | |
| </pre></div>
 | |
| </div>
 | |
| </div>
 | |
| <div class="nboutput docutils container">
 | |
| <div class="prompt empty docutils container">
 | |
| </div>
 | |
| <div class="output_area stderr docutils container">
 | |
| <div class="highlight"><pre>
 | |
|   0% |                                                                        |
 | |
| </pre></div></div>
 | |
| </div>
 | |
| <div class="nboutput docutils container">
 | |
| <div class="prompt empty docutils container">
 | |
| </div>
 | |
| <div class="output_area docutils container">
 | |
| <div class="highlight"><pre>
 | |
| Downloading yolov4.cfg from https://raw.githubusercontent.com/AlexeyAB/darknet/master/cfg/yolov4.cfg
 | |
| Downloading yolov4.weights from https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights
 | |
| </pre></div></div>
 | |
| </div>
 | |
| <div class="nboutput docutils container">
 | |
| <div class="prompt empty docutils container">
 | |
| </div>
 | |
| <div class="output_area stderr docutils container">
 | |
| <div class="highlight"><pre>
 | |
|  99% |####################################################################### |
 | |
| </pre></div></div>
 | |
| </div>
 | |
| <div class="nboutput docutils container">
 | |
| <div class="prompt empty docutils container">
 | |
| </div>
 | |
| <div class="output_area docutils container">
 | |
| <div class="highlight"><pre>
 | |
| Downloading yolov3_classes.txt from https://github.com/arunponnusamy/object-detection-opencv/raw/master/yolov3.txt
 | |
| </pre></div></div>
 | |
| </div>
 | |
| <div class="nboutput nblast docutils container">
 | |
| <div class="prompt empty docutils container">
 | |
| </div>
 | |
| <div class="output_area stderr docutils container">
 | |
| <div class="highlight"><pre>
 | |
| 100% |                                                                        |
 | |
| </pre></div></div>
 | |
| </div>
 | |
| <p>Convert the dictionary of dictionarys into a dictionary with lists:</p>
 | |
| <div class="nbinput nblast docutils container">
 | |
| <div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[6]:
 | |
| </pre></div>
 | |
| </div>
 | |
| <div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">outdict</span> <span class="o">=</span> <span class="n">mutils</span><span class="o">.</span><span class="n">append_data_to_dict</span><span class="p">(</span><span class="n">mydict</span><span class="p">)</span>
 | |
| <span class="n">df</span> <span class="o">=</span> <span class="n">mutils</span><span class="o">.</span><span class="n">dump_df</span><span class="p">(</span><span class="n">outdict</span><span class="p">)</span>
 | |
| </pre></div>
 | |
| </div>
 | |
| </div>
 | |
| <p>Check the dataframe:</p>
 | |
| <div class="nbinput docutils container">
 | |
| <div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[7]:
 | |
| </pre></div>
 | |
| </div>
 | |
| <div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">df</span><span class="o">.</span><span class="n">head</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
 | |
| </pre></div>
 | |
| </div>
 | |
| </div>
 | |
| <div class="nboutput nblast docutils container">
 | |
| <div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[7]:
 | |
| </pre></div>
 | |
| </div>
 | |
| <div class="output_area rendered_html docutils container">
 | |
| <div>
 | |
| <style scoped>
 | |
|     .dataframe tbody tr th:only-of-type {
 | |
|         vertical-align: middle;
 | |
|     }
 | |
| 
 | |
|     .dataframe tbody tr th {
 | |
|         vertical-align: top;
 | |
|     }
 | |
| 
 | |
|     .dataframe thead th {
 | |
|         text-align: right;
 | |
|     }
 | |
| </style>
 | |
| <table border="1" class="dataframe">
 | |
|   <thead>
 | |
|     <tr style="text-align: right;">
 | |
|       <th></th>
 | |
|       <th>filename</th>
 | |
|       <th>person</th>
 | |
|       <th>bicycle</th>
 | |
|       <th>car</th>
 | |
|       <th>motorcycle</th>
 | |
|       <th>airplane</th>
 | |
|       <th>bus</th>
 | |
|       <th>train</th>
 | |
|       <th>truck</th>
 | |
|       <th>boat</th>
 | |
|       <th>traffic light</th>
 | |
|       <th>cell phone</th>
 | |
|     </tr>
 | |
|   </thead>
 | |
|   <tbody>
 | |
|     <tr>
 | |
|       <th>0</th>
 | |
|       <td>data/102730_eng.png</td>
 | |
|       <td>yes</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>yes</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|     </tr>
 | |
|     <tr>
 | |
|       <th>1</th>
 | |
|       <td>data/102141_2_eng.png</td>
 | |
|       <td>yes</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|     </tr>
 | |
|     <tr>
 | |
|       <th>2</th>
 | |
|       <td>data/106349S_por.png</td>
 | |
|       <td>yes</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>no</td>
 | |
|       <td>yes</td>
 | |
|     </tr>
 | |
|   </tbody>
 | |
| </table>
 | |
| </div></div>
 | |
| </div>
 | |
| <p>Write the csv file:</p>
 | |
| <div class="nbinput nblast docutils container">
 | |
| <div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[8]:
 | |
| </pre></div>
 | |
| </div>
 | |
| <div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">df</span><span class="o">.</span><span class="n">to_csv</span><span class="p">(</span><span class="s2">"./data_out.csv"</span><span class="p">)</span>
 | |
| </pre></div>
 | |
| </div>
 | |
| </div>
 | |
| <div class="nbinput nblast docutils container">
 | |
| <div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[ ]:
 | |
| </pre></div>
 | |
| </div>
 | |
| <div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>
 | |
| </pre></div>
 | |
| </div>
 | |
| </div>
 | |
| </section>
 | |
| </section>
 | |
| 
 | |
| 
 | |
|            </div>
 | |
|           </div>
 | |
|           <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
 | |
|         <a href="Example%20multimodal.html" class="btn btn-neutral float-left" title="Image Multimodal Search" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
 | |
|         <a href="../modules.html" class="btn btn-neutral float-right" title="AMMICO package modules" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
 | |
|     </div>
 | |
| 
 | |
|   <hr/>
 | |
| 
 | |
|   <div role="contentinfo">
 | |
|     <p>© Copyright 2022, Scientific Software Center, Heidelberg University.</p>
 | |
|   </div>
 | |
| 
 | |
|   Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
 | |
|     <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
 | |
|     provided by <a href="https://readthedocs.org">Read the Docs</a>.
 | |
|    
 | |
| 
 | |
| </footer>
 | |
|         </div>
 | |
|       </div>
 | |
|     </section>
 | |
|   </div>
 | |
|   <script>
 | |
|       jQuery(function () {
 | |
|           SphinxRtdTheme.Navigation.enable(true);
 | |
|       });
 | |
|   </script> 
 | |
| 
 | |
| </body>
 | |
| </html> | 
