Last active
March 19, 2021 18:17
-
-
Save fdovila/d680163df93d6fec8b6fcba5d5b93097 to your computer and use it in GitHub Desktop.
emotion_detector_withFEAT.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.8.5" | |
}, | |
"colab": { | |
"name": "installation.ipynb", | |
"provenance": [], | |
"include_colab_link": true | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/fdovila/d680163df93d6fec8b6fcba5d5b93097/installation.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "WlDxih5HjhGh" | |
}, | |
"source": [ | |
"# Installation example\n", | |
"\n", | |
"*Written by Jin Hyun Cheong*\n", | |
"\n", | |
"Open the current notebook in [Google Colab](http://colab.research.google.com/) and run the cell below to install Py-Feat. Make sure to `Restart Runtime` so that the installation is recognized. " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "xhwTaU-_jhGn", | |
"outputId": "eec113da-aff9-42a7-944a-84e18ed067e0" | |
}, | |
"source": [ | |
"# Install Py-Feat from source.\n", | |
"!git clone https://github.com/cosanlab/feat.git \n", | |
"!cd feat && pip install -q -r requirements.txt\n", | |
"!cd feat && pip install -q -e . \n", | |
"!cd feat && python bin/download_models.py\n", | |
"# Click Runtime from top menu and Restart Runtime! " | |
], | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Cloning into 'feat'...\n", | |
"remote: Enumerating objects: 459, done.\u001b[K\n", | |
"remote: Counting objects: 100% (459/459), done.\u001b[K\n", | |
"remote: Compressing objects: 100% (186/186), done.\u001b[K\n", | |
"remote: Total 3099 (delta 274), reused 452 (delta 271), pack-reused 2640\u001b[K\n", | |
"Receiving objects: 100% (3099/3099), 222.26 MiB | 27.59 MiB/s, done.\n", | |
"Resolving deltas: 100% (1683/1683), done.\n", | |
"\u001b[K |████████████████████████████████| 3.4MB 6.6MB/s \n", | |
"\u001b[K |████████████████████████████████| 56.4MB 68kB/s \n", | |
"\u001b[K |████████████████████████████████| 3.1MB 47.7MB/s \n", | |
"\u001b[?25h Building wheel for wget (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
"/usr/local/lib/python3.7/dist-packages/statsmodels/tools/_testing.py:19: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.\n", | |
" import pandas.util.testing as tm\n", | |
"/usr/local/lib/python3.7/dist-packages/nilearn/datasets/__init__.py:90: FutureWarning: Fetchers from the nilearn.datasets module will be updated in version 0.9 to return python strings instead of bytes and Pandas dataframes instead of Numpy arrays.\n", | |
" \"Numpy arrays.\", FutureWarning)\n", | |
"Downloading FEX emotion model.\n", | |
"\n", | |
"FEX emotion model downloaded successfully.\n", | |
"\n", | |
"Downloading landmark detection model.\n", | |
"Downloading JAA Net AU Occurence model.\n", | |
"\n", | |
"AU Detection Model Parameters downloaded successfully.\n", | |
"\n", | |
"\n", | |
"Landmark detection model downloaded successfully.\n", | |
"\n", | |
"\n", | |
"FaceBox model downloaded successfully.\n", | |
"\n", | |
"Downloading MTCNN pnet model.\n", | |
"\n", | |
"MTCNN pnet model downloaded successfully.\n", | |
"\n", | |
"Downloading MTCNN rnet model.\n", | |
"\n", | |
"MTCNN rnet model downloaded successfully.\n", | |
"\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "JStZrHY0jhGo" | |
}, | |
"source": [ | |
"```{warning}\n", | |
"Make sure you `Restart Runtime` from the `Runtime` top menu bar to refresh your session. \n", | |
"In Kaggle, click `Restart & clear outputs` from the `Run` top menu bar. NOT `Restart session`\n", | |
"```" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2021-03-03T04:45:31.237098Z", | |
"start_time": "2021-03-03T04:45:29.343540Z" | |
}, | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "8xtLindcjhGo", | |
"outputId": "9ba1bbed-ac6f-4801-9fef-f38fb4510e9f" | |
}, | |
"source": [ | |
"# Check Fex class installation\n", | |
"from feat import Fex\n", | |
"fex = Fex()" | |
], | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"/usr/local/lib/python3.7/dist-packages/statsmodels/tools/_testing.py:19: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead.\n", | |
" import pandas.util.testing as tm\n", | |
"/usr/local/lib/python3.7/dist-packages/nilearn/datasets/__init__.py:90: FutureWarning: Fetchers from the nilearn.datasets module will be updated in version 0.9 to return python strings instead of bytes and Pandas dataframes instead of Numpy arrays.\n", | |
" \"Numpy arrays.\", FutureWarning)\n" | |
], | |
"name": "stderr" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2021-03-03T04:45:52.062640Z", | |
"start_time": "2021-03-03T04:45:49.265000Z" | |
}, | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "sZeIaiJOjhGo", | |
"outputId": "b4dc5267-100f-401e-9c88-b85d241d99b7" | |
}, | |
"source": [ | |
"# Check Detector class installation\n", | |
"from feat import Detector\n", | |
"detector = Detector()" | |
], | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Loading Face Detection model: retinaface\n", | |
"Loading Face Landmark model: MobileNet\n", | |
"Loading au occurence model: jaanet\n", | |
"Loading emotion model: fer\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "W-isPm4MkMtf", | |
"outputId": "4bd00e08-1a9b-4413-d816-eaaa6e84f779" | |
}, | |
"source": [ | |
"from feat.detector import Detector\n", | |
"detector = Detector() " | |
], | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Loading Face Detection model: retinaface\n", | |
"Loading Face Landmark model: MobileNet\n", | |
"Loading au occurence model: jaanet\n", | |
"Loading emotion model: fer\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 180 | |
}, | |
"id": "zjUdKuYclKZI", | |
"outputId": "79dd985f-57e6-480c-ab7c-07302d26db1f" | |
}, | |
"source": [ | |
"from PIL import Image\n", | |
"img = Image.open('/face.png').convert('LA')\n", | |
"img.save('/faceGS.png')\n", | |
"\n", | |
"# Detect FEX from image\n", | |
"out = detector.detect_image(\"/faceGS.png\")\n", | |
"out" | |
], | |
"execution_count": 24, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"/content/feat/feat/emo_detectors/ferNet/ferNet_test.py:148: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.\n", | |
" pred_emo).cpu().float().data.numpy()\n" | |
], | |
"name": "stderr" | |
}, | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>frame</th>\n", | |
" <th>FaceRectX</th>\n", | |
" <th>FaceRectY</th>\n", | |
" <th>FaceRectWidth</th>\n", | |
" <th>FaceRectHeight</th>\n", | |
" <th>FaceScore</th>\n", | |
" <th>x_0</th>\n", | |
" <th>x_1</th>\n", | |
" <th>x_2</th>\n", | |
" <th>x_3</th>\n", | |
" <th>x_4</th>\n", | |
" <th>x_5</th>\n", | |
" <th>x_6</th>\n", | |
" <th>x_7</th>\n", | |
" <th>x_8</th>\n", | |
" <th>x_9</th>\n", | |
" <th>x_10</th>\n", | |
" <th>x_11</th>\n", | |
" <th>x_12</th>\n", | |
" <th>x_13</th>\n", | |
" <th>x_14</th>\n", | |
" <th>x_15</th>\n", | |
" <th>x_16</th>\n", | |
" <th>x_17</th>\n", | |
" <th>x_18</th>\n", | |
" <th>x_19</th>\n", | |
" <th>x_20</th>\n", | |
" <th>x_21</th>\n", | |
" <th>x_22</th>\n", | |
" <th>x_23</th>\n", | |
" <th>x_24</th>\n", | |
" <th>x_25</th>\n", | |
" <th>x_26</th>\n", | |
" <th>x_27</th>\n", | |
" <th>x_28</th>\n", | |
" <th>x_29</th>\n", | |
" <th>x_30</th>\n", | |
" <th>x_31</th>\n", | |
" <th>x_32</th>\n", | |
" <th>x_33</th>\n", | |
" <th>...</th>\n", | |
" <th>y_48</th>\n", | |
" <th>y_49</th>\n", | |
" <th>y_50</th>\n", | |
" <th>y_51</th>\n", | |
" <th>y_52</th>\n", | |
" <th>y_53</th>\n", | |
" <th>y_54</th>\n", | |
" <th>y_55</th>\n", | |
" <th>y_56</th>\n", | |
" <th>y_57</th>\n", | |
" <th>y_58</th>\n", | |
" <th>y_59</th>\n", | |
" <th>y_60</th>\n", | |
" <th>y_61</th>\n", | |
" <th>y_62</th>\n", | |
" <th>y_63</th>\n", | |
" <th>y_64</th>\n", | |
" <th>y_65</th>\n", | |
" <th>y_66</th>\n", | |
" <th>y_67</th>\n", | |
" <th>AU01</th>\n", | |
" <th>AU02</th>\n", | |
" <th>AU04</th>\n", | |
" <th>AU06</th>\n", | |
" <th>AU07</th>\n", | |
" <th>AU10</th>\n", | |
" <th>AU12</th>\n", | |
" <th>AU14</th>\n", | |
" <th>AU15</th>\n", | |
" <th>AU17</th>\n", | |
" <th>AU23</th>\n", | |
" <th>AU24</th>\n", | |
" <th>anger</th>\n", | |
" <th>disgust</th>\n", | |
" <th>fear</th>\n", | |
" <th>happiness</th>\n", | |
" <th>sadness</th>\n", | |
" <th>surprise</th>\n", | |
" <th>neutral</th>\n", | |
" <th>input</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>0</td>\n", | |
" <td>31.62466</td>\n", | |
" <td>55.929249</td>\n", | |
" <td>297.637939</td>\n", | |
" <td>427.164581</td>\n", | |
" <td>0.993177</td>\n", | |
" <td>29.270412</td>\n", | |
" <td>31.170122</td>\n", | |
" <td>38.374414</td>\n", | |
" <td>47.776637</td>\n", | |
" <td>60.085441</td>\n", | |
" <td>76.876149</td>\n", | |
" <td>95.360945</td>\n", | |
" <td>117.715481</td>\n", | |
" <td>149.088836</td>\n", | |
" <td>185.573671</td>\n", | |
" <td>220.082275</td>\n", | |
" <td>254.113773</td>\n", | |
" <td>283.022547</td>\n", | |
" <td>304.356102</td>\n", | |
" <td>316.1953</td>\n", | |
" <td>322.528342</td>\n", | |
" <td>324.914686</td>\n", | |
" <td>36.487109</td>\n", | |
" <td>47.483542</td>\n", | |
" <td>68.55553</td>\n", | |
" <td>92.02506</td>\n", | |
" <td>114.118723</td>\n", | |
" <td>156.787167</td>\n", | |
" <td>181.475853</td>\n", | |
" <td>207.456734</td>\n", | |
" <td>234.162055</td>\n", | |
" <td>256.204751</td>\n", | |
" <td>134.078348</td>\n", | |
" <td>131.872132</td>\n", | |
" <td>129.4195</td>\n", | |
" <td>126.894306</td>\n", | |
" <td>102.56753</td>\n", | |
" <td>115.880853</td>\n", | |
" <td>133.132094</td>\n", | |
" <td>...</td>\n", | |
" <td>377.995865</td>\n", | |
" <td>377.047904</td>\n", | |
" <td>377.705278</td>\n", | |
" <td>382.305872</td>\n", | |
" <td>378.677373</td>\n", | |
" <td>380.226012</td>\n", | |
" <td>381.439616</td>\n", | |
" <td>393.886597</td>\n", | |
" <td>400.656374</td>\n", | |
" <td>401.474362</td>\n", | |
" <td>398.805326</td>\n", | |
" <td>390.699186</td>\n", | |
" <td>379.347657</td>\n", | |
" <td>384.482459</td>\n", | |
" <td>387.652202</td>\n", | |
" <td>385.86581</td>\n", | |
" <td>382.376246</td>\n", | |
" <td>386.654203</td>\n", | |
" <td>388.130803</td>\n", | |
" <td>384.861046</td>\n", | |
" <td>0.203693</td>\n", | |
" <td>0.999936</td>\n", | |
" <td>0.000027</td>\n", | |
" <td>0.702135</td>\n", | |
" <td>0.630595</td>\n", | |
" <td>0.054488</td>\n", | |
" <td>0.99962</td>\n", | |
" <td>0.090063</td>\n", | |
" <td>0.755996</td>\n", | |
" <td>0.00012</td>\n", | |
" <td>0.000481</td>\n", | |
" <td>9.575105e-08</td>\n", | |
" <td>0.029304</td>\n", | |
" <td>0.039329</td>\n", | |
" <td>0.001063</td>\n", | |
" <td>0.175259</td>\n", | |
" <td>0.053924</td>\n", | |
" <td>0.01458</td>\n", | |
" <td>0.686542</td>\n", | |
" <td>/faceGS.png</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>1 rows × 162 columns</p>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" frame FaceRectX FaceRectY ... surprise neutral input\n", | |
"0 0 31.62466 55.929249 ... 0.01458 0.686542 /faceGS.png\n", | |
"\n", | |
"[1 rows x 162 columns]" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 24 | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
face.png could be any image you upload to the workspace in the collab