{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":11142861,"sourceType":"datasetVersion","datasetId":6950850},{"sourceId":619812,"sourceType":"modelInstanceVersion","isSourceIdPinned":true,"modelInstanceId":466220,"modelId":482044}],"dockerImageVersionId":31153,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Video Dataset\n\nVideo Emotion :- https://www.kaggle.com/datasets/thnhthngchu/video-emotion","metadata":{}},{"cell_type":"code","source":"import kagglehub\n\n# Download latest version\npath = kagglehub.dataset_download(\"thnhthngchu/video-emotion\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-26T12:43:30.345473Z","iopub.execute_input":"2025-10-26T12:43:30.345743Z","iopub.status.idle":"2025-10-26T12:43:30.913576Z","shell.execute_reply.started":"2025-10-26T12:43:30.345721Z","shell.execute_reply":"2025-10-26T12:43:30.912462Z"}},"outputs":[],"execution_count":1},{"cell_type":"markdown","source":"# Load Modules","metadata":{}},{"cell_type":"code","source":"!pip install torch numpy pandas scikit-learn opencv-python\n!pip install mediapipe","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-26T12:43:30.915690Z","iopub.execute_input":"2025-10-26T12:43:30.915960Z","iopub.status.idle":"2025-10-26T12:45:36.025360Z","shell.execute_reply.started":"2025-10-26T12:43:30.915936Z","shell.execute_reply":"2025-10-26T12:45:36.024318Z"}},"outputs":[{"name":"stdout","text":"Requirement already satisfied: torch in /usr/local/lib/python3.11/dist-packages (2.6.0+cu124)\nRequirement already satisfied: numpy in /usr/local/lib/python3.11/dist-packages (1.26.4)\nRequirement already satisfied: pandas in /usr/local/lib/python3.11/dist-packages (2.2.3)\nRequirement already satisfied: scikit-learn in /usr/local/lib/python3.11/dist-packages (1.2.2)\nRequirement already satisfied: opencv-python in /usr/local/lib/python3.11/dist-packages (4.12.0.88)\nRequirement already satisfied: filelock in /usr/local/lib/python3.11/dist-packages (from torch) (3.19.1)\nRequirement already satisfied: typing-extensions>=4.10.0 in /usr/local/lib/python3.11/dist-packages (from torch) (4.15.0)\nRequirement already satisfied: networkx in /usr/local/lib/python3.11/dist-packages (from torch) (3.5)\nRequirement already satisfied: jinja2 in /usr/local/lib/python3.11/dist-packages (from torch) (3.1.6)\nRequirement already satisfied: fsspec in /usr/local/lib/python3.11/dist-packages (from torch) (2025.9.0)\nCollecting nvidia-cuda-nvrtc-cu12==12.4.127 (from torch)\n Downloading nvidia_cuda_nvrtc_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)\nCollecting nvidia-cuda-runtime-cu12==12.4.127 (from torch)\n Downloading nvidia_cuda_runtime_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)\nCollecting nvidia-cuda-cupti-cu12==12.4.127 (from torch)\n Downloading nvidia_cuda_cupti_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl.metadata (1.6 kB)\nCollecting nvidia-cudnn-cu12==9.1.0.70 (from torch)\n Downloading nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl.metadata (1.6 kB)\nCollecting nvidia-cublas-cu12==12.4.5.8 (from torch)\n Downloading nvidia_cublas_cu12-12.4.5.8-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)\nCollecting nvidia-cufft-cu12==11.2.1.3 (from torch)\n Downloading nvidia_cufft_cu12-11.2.1.3-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)\nCollecting nvidia-curand-cu12==10.3.5.147 (from torch)\n Downloading nvidia_curand_cu12-10.3.5.147-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)\nCollecting nvidia-cusolver-cu12==11.6.1.9 (from torch)\n Downloading nvidia_cusolver_cu12-11.6.1.9-py3-none-manylinux2014_x86_64.whl.metadata (1.6 kB)\nCollecting nvidia-cusparse-cu12==12.3.1.170 (from torch)\n Downloading nvidia_cusparse_cu12-12.3.1.170-py3-none-manylinux2014_x86_64.whl.metadata (1.6 kB)\nRequirement already satisfied: nvidia-cusparselt-cu12==0.6.2 in /usr/local/lib/python3.11/dist-packages (from torch) (0.6.2)\nRequirement already satisfied: nvidia-nccl-cu12==2.21.5 in /usr/local/lib/python3.11/dist-packages (from torch) (2.21.5)\nRequirement already satisfied: nvidia-nvtx-cu12==12.4.127 in /usr/local/lib/python3.11/dist-packages (from torch) (12.4.127)\nCollecting nvidia-nvjitlink-cu12==12.4.127 (from torch)\n Downloading nvidia_nvjitlink_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)\nRequirement already satisfied: triton==3.2.0 in /usr/local/lib/python3.11/dist-packages (from torch) (3.2.0)\nRequirement already satisfied: sympy==1.13.1 in /usr/local/lib/python3.11/dist-packages (from torch) (1.13.1)\nRequirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.11/dist-packages (from sympy==1.13.1->torch) (1.3.0)\nRequirement already satisfied: mkl_fft in /usr/local/lib/python3.11/dist-packages (from numpy) (1.3.8)\nRequirement already satisfied: mkl_random in /usr/local/lib/python3.11/dist-packages (from numpy) (1.2.4)\nRequirement already satisfied: mkl_umath in /usr/local/lib/python3.11/dist-packages (from numpy) (0.1.1)\nRequirement already satisfied: mkl in /usr/local/lib/python3.11/dist-packages (from numpy) (2025.2.0)\nRequirement already satisfied: tbb4py in /usr/local/lib/python3.11/dist-packages (from numpy) (2022.2.0)\nRequirement already satisfied: mkl-service in /usr/local/lib/python3.11/dist-packages (from numpy) (2.4.1)\nRequirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.11/dist-packages (from pandas) (2.9.0.post0)\nRequirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-packages (from pandas) (2025.2)\nRequirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas) (2025.2)\nRequirement already satisfied: scipy>=1.3.2 in /usr/local/lib/python3.11/dist-packages (from scikit-learn) (1.15.3)\nRequirement already satisfied: joblib>=1.1.1 in /usr/local/lib/python3.11/dist-packages (from scikit-learn) (1.5.2)\nRequirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn) (3.6.0)\nCollecting numpy\n Downloading numpy-2.2.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (62 kB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.0/62.0 kB\u001b[0m \u001b[31m1.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n\u001b[?25hRequirement already satisfied: six>=1.5 in /usr/local/lib/python3.11/dist-packages (from python-dateutil>=2.8.2->pandas) (1.17.0)\nRequirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.11/dist-packages (from jinja2->torch) (3.0.2)\nRequirement already satisfied: intel-openmp<2026,>=2024 in /usr/local/lib/python3.11/dist-packages (from mkl->numpy) (2024.2.0)\nRequirement already satisfied: tbb==2022.* in /usr/local/lib/python3.11/dist-packages (from mkl->numpy) (2022.2.0)\nRequirement already satisfied: tcmlib==1.* in /usr/local/lib/python3.11/dist-packages (from tbb==2022.*->mkl->numpy) (1.4.0)\nRequirement already satisfied: intel-cmplr-lib-ur==2024.2.0 in /usr/local/lib/python3.11/dist-packages (from intel-openmp<2026,>=2024->mkl->numpy) (2024.2.0)\nINFO: pip is looking at multiple versions of mkl-fft to determine which version is compatible with other requirements. This could take a while.\nCollecting mkl_fft (from numpy)\n Downloading mkl_fft-2.0.0-22-cp311-cp311-manylinux_2_28_x86_64.whl.metadata (7.1 kB)\nINFO: pip is looking at multiple versions of mkl-random to determine which version is compatible with other requirements. This could take a while.\nCollecting mkl_random (from numpy)\n Downloading mkl_random-1.2.11-22-cp311-cp311-manylinux_2_28_x86_64.whl.metadata (4.1 kB)\nINFO: pip is looking at multiple versions of mkl-umath to determine which version is compatible with other requirements. This could take a while.\nCollecting mkl_umath (from numpy)\n Downloading mkl_umath-0.2.0-21-cp311-cp311-manylinux_2_28_x86_64.whl.metadata (4.2 kB)\nRequirement already satisfied: intel-cmplr-lib-rt in /usr/local/lib/python3.11/dist-packages (from mkl_umath->numpy) (2024.2.0)\nDownloading nvidia_cublas_cu12-12.4.5.8-py3-none-manylinux2014_x86_64.whl (363.4 MB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m363.4/363.4 MB\u001b[0m \u001b[31m4.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m00:01\u001b[0m\n\u001b[?25hDownloading nvidia_cuda_cupti_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl (13.8 MB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m13.8/13.8 MB\u001b[0m \u001b[31m86.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m00:01\u001b[0m\n\u001b[?25hDownloading nvidia_cuda_nvrtc_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl (24.6 MB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m24.6/24.6 MB\u001b[0m \u001b[31m67.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m00:01\u001b[0m\n\u001b[?25hDownloading nvidia_cuda_runtime_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl (883 kB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m883.7/883.7 kB\u001b[0m \u001b[31m35.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n\u001b[?25hDownloading nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl (664.8 MB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m664.8/664.8 MB\u001b[0m \u001b[31m2.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m00:01\u001b[0m\n\u001b[?25hDownloading nvidia_cufft_cu12-11.2.1.3-py3-none-manylinux2014_x86_64.whl (211.5 MB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m211.5/211.5 MB\u001b[0m \u001b[31m6.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m00:01\u001b[0m\n\u001b[?25hDownloading nvidia_curand_cu12-10.3.5.147-py3-none-manylinux2014_x86_64.whl (56.3 MB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m56.3/56.3 MB\u001b[0m \u001b[31m28.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m00:01\u001b[0m\n\u001b[?25hDownloading nvidia_cusolver_cu12-11.6.1.9-py3-none-manylinux2014_x86_64.whl (127.9 MB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m127.9/127.9 MB\u001b[0m \u001b[31m10.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n\u001b[?25hDownloading nvidia_cusparse_cu12-12.3.1.170-py3-none-manylinux2014_x86_64.whl (207.5 MB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m207.5/207.5 MB\u001b[0m \u001b[31m1.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m00:01\u001b[0m\n\u001b[?25hDownloading nvidia_nvjitlink_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl (21.1 MB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m21.1/21.1 MB\u001b[0m \u001b[31m73.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m00:01\u001b[0m\n\u001b[?25hDownloading numpy-2.2.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.8 MB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m16.8/16.8 MB\u001b[0m \u001b[31m74.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m00:01\u001b[0m\n\u001b[?25hInstalling collected packages: nvidia-nvjitlink-cu12, nvidia-curand-cu12, nvidia-cufft-cu12, nvidia-cuda-runtime-cu12, nvidia-cuda-nvrtc-cu12, nvidia-cuda-cupti-cu12, nvidia-cublas-cu12, numpy, nvidia-cusparse-cu12, nvidia-cudnn-cu12, nvidia-cusolver-cu12\n Attempting uninstall: nvidia-nvjitlink-cu12\n Found existing installation: nvidia-nvjitlink-cu12 12.5.82\n Uninstalling nvidia-nvjitlink-cu12-12.5.82:\n Successfully uninstalled nvidia-nvjitlink-cu12-12.5.82\n Attempting uninstall: nvidia-curand-cu12\n Found existing installation: nvidia-curand-cu12 10.3.6.82\n Uninstalling nvidia-curand-cu12-10.3.6.82:\n Successfully uninstalled nvidia-curand-cu12-10.3.6.82\n Attempting uninstall: nvidia-cufft-cu12\n Found existing installation: nvidia-cufft-cu12 11.2.3.61\n Uninstalling nvidia-cufft-cu12-11.2.3.61:\n Successfully uninstalled nvidia-cufft-cu12-11.2.3.61\n Attempting uninstall: nvidia-cuda-runtime-cu12\n Found existing installation: nvidia-cuda-runtime-cu12 12.5.82\n Uninstalling nvidia-cuda-runtime-cu12-12.5.82:\n Successfully uninstalled nvidia-cuda-runtime-cu12-12.5.82\n Attempting uninstall: nvidia-cuda-nvrtc-cu12\n Found existing installation: nvidia-cuda-nvrtc-cu12 12.5.82\n Uninstalling nvidia-cuda-nvrtc-cu12-12.5.82:\n Successfully uninstalled nvidia-cuda-nvrtc-cu12-12.5.82\n Attempting uninstall: nvidia-cuda-cupti-cu12\n Found existing installation: nvidia-cuda-cupti-cu12 12.5.82\n Uninstalling nvidia-cuda-cupti-cu12-12.5.82:\n Successfully uninstalled nvidia-cuda-cupti-cu12-12.5.82\n Attempting uninstall: nvidia-cublas-cu12\n Found existing installation: nvidia-cublas-cu12 12.5.3.2\n Uninstalling nvidia-cublas-cu12-12.5.3.2:\n Successfully uninstalled nvidia-cublas-cu12-12.5.3.2\n Attempting uninstall: numpy\n Found existing installation: numpy 1.26.4\n Uninstalling numpy-1.26.4:\n Successfully uninstalled numpy-1.26.4\n Attempting uninstall: nvidia-cusparse-cu12\n Found existing installation: nvidia-cusparse-cu12 12.5.1.3\n Uninstalling nvidia-cusparse-cu12-12.5.1.3:\n Successfully uninstalled nvidia-cusparse-cu12-12.5.1.3\n Attempting uninstall: nvidia-cudnn-cu12\n Found existing installation: nvidia-cudnn-cu12 9.3.0.75\n Uninstalling nvidia-cudnn-cu12-9.3.0.75:\n Successfully uninstalled nvidia-cudnn-cu12-9.3.0.75\n Attempting uninstall: nvidia-cusolver-cu12\n Found existing installation: nvidia-cusolver-cu12 11.6.3.83\n Uninstalling nvidia-cusolver-cu12-11.6.3.83:\n Successfully uninstalled nvidia-cusolver-cu12-11.6.3.83\n\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\nbigframes 2.12.0 requires google-cloud-bigquery-storage<3.0.0,>=2.30.0, which is not installed.\ngensim 4.3.3 requires numpy<2.0,>=1.18.5, but you have numpy 2.2.6 which is incompatible.\ngensim 4.3.3 requires scipy<1.14.0,>=1.7.0, but you have scipy 1.15.3 which is incompatible.\nmkl-umath 0.1.1 requires numpy<1.27.0,>=1.26.4, but you have numpy 2.2.6 which is incompatible.\nmkl-random 1.2.4 requires numpy<1.27.0,>=1.26.4, but you have numpy 2.2.6 which is incompatible.\nmkl-fft 1.3.8 requires numpy<1.27.0,>=1.26.4, but you have numpy 2.2.6 which is incompatible.\nnumba 0.60.0 requires numpy<2.1,>=1.22, but you have numpy 2.2.6 which is incompatible.\ndatasets 4.1.1 requires pyarrow>=21.0.0, but you have pyarrow 19.0.1 which is incompatible.\nonnx 1.18.0 requires protobuf>=4.25.1, but you have protobuf 3.20.3 which is incompatible.\nydata-profiling 4.17.0 requires numpy<2.2,>=1.16.0, but you have numpy 2.2.6 which is incompatible.\ngoogle-colab 1.0.0 requires google-auth==2.38.0, but you have google-auth 2.40.3 which is incompatible.\ngoogle-colab 1.0.0 requires notebook==6.5.7, but you have notebook 6.5.4 which is incompatible.\ngoogle-colab 1.0.0 requires pandas==2.2.2, but you have pandas 2.2.3 which is incompatible.\ngoogle-colab 1.0.0 requires requests==2.32.3, but you have requests 2.32.5 which is incompatible.\ngoogle-colab 1.0.0 requires tornado==6.4.2, but you have tornado 6.5.2 which is incompatible.\ndopamine-rl 4.1.2 requires gymnasium>=1.0.0, but you have gymnasium 0.29.0 which is incompatible.\nbigframes 2.12.0 requires google-cloud-bigquery[bqstorage,pandas]>=3.31.0, but you have google-cloud-bigquery 3.25.0 which is incompatible.\nbigframes 2.12.0 requires rich<14,>=12.4.4, but you have rich 14.1.0 which is incompatible.\nlibcugraph-cu12 25.6.0 requires libraft-cu12==25.6.*, but you have libraft-cu12 25.2.0 which is incompatible.\ngradio 5.38.1 requires pydantic<2.12,>=2.0, but you have pydantic 2.12.0a1 which is incompatible.\nimbalanced-learn 0.13.0 requires scikit-learn<2,>=1.3.2, but you have scikit-learn 1.2.2 which is incompatible.\npandas-gbq 0.29.2 requires google-api-core<3.0.0,>=2.10.2, but you have google-api-core 1.34.1 which is incompatible.\ntransformers 4.53.3 requires huggingface-hub<1.0,>=0.30.0, but you have huggingface-hub 1.0.0rc2 which is incompatible.\nplotnine 0.14.5 requires matplotlib>=3.8.0, but you have matplotlib 3.7.2 which is incompatible.\ntensorflow 2.18.0 requires numpy<2.1.0,>=1.26.0, but you have numpy 2.2.6 which is incompatible.\npylibcugraph-cu12 25.6.0 requires pylibraft-cu12==25.6.*, but you have pylibraft-cu12 25.2.0 which is incompatible.\npylibcugraph-cu12 25.6.0 requires rmm-cu12==25.6.*, but you have rmm-cu12 25.2.0 which is incompatible.\numap-learn 0.5.9.post2 requires scikit-learn>=1.6, but you have scikit-learn 1.2.2 which is incompatible.\nmlxtend 0.23.4 requires scikit-learn>=1.3.1, but you have scikit-learn 1.2.2 which is incompatible.\u001b[0m\u001b[31m\n\u001b[0mSuccessfully installed numpy-2.2.6 nvidia-cublas-cu12-12.4.5.8 nvidia-cuda-cupti-cu12-12.4.127 nvidia-cuda-nvrtc-cu12-12.4.127 nvidia-cuda-runtime-cu12-12.4.127 nvidia-cudnn-cu12-9.1.0.70 nvidia-cufft-cu12-11.2.1.3 nvidia-curand-cu12-10.3.5.147 nvidia-cusolver-cu12-11.6.1.9 nvidia-cusparse-cu12-12.3.1.170 nvidia-nvjitlink-cu12-12.4.127\nCollecting mediapipe\n Downloading mediapipe-0.10.21-cp311-cp311-manylinux_2_28_x86_64.whl.metadata (9.7 kB)\nRequirement already satisfied: absl-py in /usr/local/lib/python3.11/dist-packages (from mediapipe) (1.4.0)\nRequirement already satisfied: attrs>=19.1.0 in /usr/local/lib/python3.11/dist-packages (from mediapipe) (25.3.0)\nRequirement already satisfied: flatbuffers>=2.0 in /usr/local/lib/python3.11/dist-packages (from mediapipe) (25.2.10)\nRequirement already satisfied: jax in /usr/local/lib/python3.11/dist-packages (from mediapipe) (0.5.2)\nRequirement already satisfied: jaxlib in /usr/local/lib/python3.11/dist-packages (from mediapipe) (0.5.1)\nRequirement already satisfied: matplotlib in /usr/local/lib/python3.11/dist-packages (from mediapipe) (3.7.2)\nCollecting numpy<2 (from mediapipe)\n Downloading numpy-1.26.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (61 kB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m61.0/61.0 kB\u001b[0m \u001b[31m1.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n\u001b[?25hRequirement already satisfied: opencv-contrib-python in /usr/local/lib/python3.11/dist-packages (from mediapipe) (4.12.0.88)\nCollecting protobuf<5,>=4.25.3 (from mediapipe)\n Downloading protobuf-4.25.8-cp37-abi3-manylinux2014_x86_64.whl.metadata (541 bytes)\nCollecting sounddevice>=0.4.4 (from mediapipe)\n Downloading sounddevice-0.5.3-py3-none-any.whl.metadata (1.6 kB)\nRequirement already satisfied: sentencepiece in /usr/local/lib/python3.11/dist-packages (from mediapipe) (0.2.0)\nRequirement already satisfied: CFFI>=1.0 in /usr/local/lib/python3.11/dist-packages (from sounddevice>=0.4.4->mediapipe) (2.0.0)\nRequirement already satisfied: ml_dtypes>=0.4.0 in /usr/local/lib/python3.11/dist-packages (from jax->mediapipe) (0.4.1)\nRequirement already satisfied: opt_einsum in /usr/local/lib/python3.11/dist-packages (from jax->mediapipe) (3.4.0)\nRequirement already satisfied: scipy>=1.11.1 in /usr/local/lib/python3.11/dist-packages (from jax->mediapipe) (1.15.3)\nRequirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib->mediapipe) (1.3.2)\nRequirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.11/dist-packages (from matplotlib->mediapipe) (0.12.1)\nRequirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.11/dist-packages (from matplotlib->mediapipe) (4.59.0)\nRequirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib->mediapipe) (1.4.8)\nRequirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.11/dist-packages (from matplotlib->mediapipe) (25.0)\nRequirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.11/dist-packages (from matplotlib->mediapipe) (11.3.0)\nRequirement already satisfied: pyparsing<3.1,>=2.3.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib->mediapipe) (3.0.9)\nRequirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.11/dist-packages (from matplotlib->mediapipe) (2.9.0.post0)\nINFO: pip is looking at multiple versions of opencv-contrib-python to determine which version is compatible with other requirements. This could take a while.\nCollecting opencv-contrib-python (from mediapipe)\n Downloading opencv_contrib_python-4.11.0.86-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (20 kB)\nRequirement already satisfied: pycparser in /usr/local/lib/python3.11/dist-packages (from CFFI>=1.0->sounddevice>=0.4.4->mediapipe) (2.23)\nRequirement already satisfied: six>=1.5 in /usr/local/lib/python3.11/dist-packages (from python-dateutil>=2.7->matplotlib->mediapipe) (1.17.0)\nDownloading mediapipe-0.10.21-cp311-cp311-manylinux_2_28_x86_64.whl (35.6 MB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m35.6/35.6 MB\u001b[0m \u001b[31m45.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m00:01\u001b[0m\n\u001b[?25hDownloading numpy-1.26.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.3 MB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m18.3/18.3 MB\u001b[0m \u001b[31m79.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m00:01\u001b[0m\n\u001b[?25hDownloading protobuf-4.25.8-cp37-abi3-manylinux2014_x86_64.whl (294 kB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m294.9/294.9 kB\u001b[0m \u001b[31m14.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n\u001b[?25hDownloading sounddevice-0.5.3-py3-none-any.whl (32 kB)\nDownloading opencv_contrib_python-4.11.0.86-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (69.1 MB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m69.1/69.1 MB\u001b[0m \u001b[31m25.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m00:01\u001b[0m\n\u001b[?25hInstalling collected packages: protobuf, numpy, sounddevice, opencv-contrib-python, mediapipe\n Attempting uninstall: protobuf\n Found existing installation: protobuf 3.20.3\n Uninstalling protobuf-3.20.3:\n Successfully uninstalled protobuf-3.20.3\n Attempting uninstall: numpy\n Found existing installation: numpy 2.2.6\n Uninstalling numpy-2.2.6:\n Successfully uninstalled numpy-2.2.6\n Attempting uninstall: opencv-contrib-python\n Found existing installation: opencv-contrib-python 4.12.0.88\n Uninstalling opencv-contrib-python-4.12.0.88:\n Successfully uninstalled opencv-contrib-python-4.12.0.88\n\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\nbigframes 2.12.0 requires google-cloud-bigquery-storage<3.0.0,>=2.30.0, which is not installed.\ngensim 4.3.3 requires scipy<1.14.0,>=1.7.0, but you have scipy 1.15.3 which is incompatible.\ndatasets 4.1.1 requires pyarrow>=21.0.0, but you have pyarrow 19.0.1 which is incompatible.\ngoogle-api-core 1.34.1 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<4.0.0dev,>=3.19.5, but you have protobuf 4.25.8 which is incompatible.\ngoogle-cloud-bigtable 2.32.0 requires google-api-core[grpc]<3.0.0,>=2.17.0, but you have google-api-core 1.34.1 which is incompatible.\ncesium 0.12.4 requires numpy<3.0,>=2.0, but you have numpy 1.26.4 which is incompatible.\ngoogle-colab 1.0.0 requires google-auth==2.38.0, but you have google-auth 2.40.3 which is incompatible.\ngoogle-colab 1.0.0 requires notebook==6.5.7, but you have notebook 6.5.4 which is incompatible.\ngoogle-colab 1.0.0 requires pandas==2.2.2, but you have pandas 2.2.3 which is incompatible.\ngoogle-colab 1.0.0 requires requests==2.32.3, but you have requests 2.32.5 which is incompatible.\ngoogle-colab 1.0.0 requires tornado==6.4.2, but you have tornado 6.5.2 which is incompatible.\ndopamine-rl 4.1.2 requires gymnasium>=1.0.0, but you have gymnasium 0.29.0 which is incompatible.\nbigframes 2.12.0 requires google-cloud-bigquery[bqstorage,pandas]>=3.31.0, but you have google-cloud-bigquery 3.25.0 which is incompatible.\nbigframes 2.12.0 requires rich<14,>=12.4.4, but you have rich 14.1.0 which is incompatible.\nthinc 8.3.6 requires numpy<3.0.0,>=2.0.0, but you have numpy 1.26.4 which is incompatible.\nopencv-python 4.12.0.88 requires numpy<2.3.0,>=2; python_version >= \"3.9\", but you have numpy 1.26.4 which is incompatible.\ngradio 5.38.1 requires pydantic<2.12,>=2.0, but you have pydantic 2.12.0a1 which is incompatible.\npydrive2 1.21.3 requires cryptography<44, but you have cryptography 46.0.1 which is incompatible.\npydrive2 1.21.3 requires pyOpenSSL<=24.2.1,>=19.1.0, but you have pyopenssl 25.3.0 which is incompatible.\nimbalanced-learn 0.13.0 requires scikit-learn<2,>=1.3.2, but you have scikit-learn 1.2.2 which is incompatible.\npandas-gbq 0.29.2 requires google-api-core<3.0.0,>=2.10.2, but you have google-api-core 1.34.1 which is incompatible.\ngoogle-cloud-storage 2.19.0 requires google-api-core<3.0.0dev,>=2.15.0, but you have google-api-core 1.34.1 which is incompatible.\ntransformers 4.53.3 requires huggingface-hub<1.0,>=0.30.0, but you have huggingface-hub 1.0.0rc2 which is incompatible.\nopencv-python-headless 4.12.0.88 requires numpy<2.3.0,>=2; python_version >= \"3.9\", but you have numpy 1.26.4 which is incompatible.\nplotnine 0.14.5 requires matplotlib>=3.8.0, but you have matplotlib 3.7.2 which is incompatible.\npylibcugraph-cu12 25.6.0 requires pylibraft-cu12==25.6.*, but you have pylibraft-cu12 25.2.0 which is incompatible.\npylibcugraph-cu12 25.6.0 requires rmm-cu12==25.6.*, but you have rmm-cu12 25.2.0 which is incompatible.\numap-learn 0.5.9.post2 requires scikit-learn>=1.6, but you have scikit-learn 1.2.2 which is incompatible.\ndataproc-spark-connect 0.8.3 requires google-api-core>=2.19, but you have google-api-core 1.34.1 which is incompatible.\ngcsfs 2025.3.0 requires fsspec==2025.3.0, but you have fsspec 2025.9.0 which is incompatible.\nmlxtend 0.23.4 requires scikit-learn>=1.3.1, but you have scikit-learn 1.2.2 which is incompatible.\u001b[0m\u001b[31m\n\u001b[0mSuccessfully installed mediapipe-0.10.21 numpy-1.26.4 opencv-contrib-python-4.11.0.86 protobuf-4.25.8 sounddevice-0.5.3\n","output_type":"stream"}],"execution_count":2},{"cell_type":"code","source":"from torch.nn.utils.rnn import pad_sequence\nfrom IPython.display import display, HTML\nfrom base64 import b64encode\n\nimport mediapipe as mp\nimport torch.nn as nn\nimport numpy as np\nimport logging\nimport random\nimport joblib\nimport torch\nimport cv2\nimport os","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-26T12:45:44.057549Z","iopub.execute_input":"2025-10-26T12:45:44.057878Z","iopub.status.idle":"2025-10-26T12:46:04.944756Z","shell.execute_reply.started":"2025-10-26T12:45:44.057845Z","shell.execute_reply":"2025-10-26T12:46:04.943563Z"}},"outputs":[{"name":"stderr","text":"2025-10-26 12:45:50.016110: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:477] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\nWARNING: All log messages before absl::InitializeLog() is called are written to STDERR\nE0000 00:00:1761482750.257503 37 cuda_dnn.cc:8310] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\nE0000 00:00:1761482750.325488 37 cuda_blas.cc:1418] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n","output_type":"stream"}],"execution_count":3},{"cell_type":"markdown","source":"# Configuration","metadata":{}},{"cell_type":"code","source":"mp_face_mesh = mp.solutions.face_mesh","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-26T12:46:14.207907Z","iopub.execute_input":"2025-10-26T12:46:14.208296Z","iopub.status.idle":"2025-10-26T12:46:14.213368Z","shell.execute_reply.started":"2025-10-26T12:46:14.208269Z","shell.execute_reply":"2025-10-26T12:46:14.212370Z"}},"outputs":[],"execution_count":5},{"cell_type":"code","source":"NUM_LANDMARKS = 478\nMODEL_PATH = '/kaggle/input/emotion-sequence-transformer-bilstm/pytorch/default/1/emotion_sequence_transformer_mp478_seq256.pt'\nGLOBAL_MEAN_PATH = '/kaggle/input/emotion-sequence-transformer-bilstm/pytorch/default/1/global_mean_tensor.pt' \nGLOBAL_STD_PATH = '/kaggle/input/emotion-sequence-transformer-bilstm/pytorch/default/1/global_std_tensor.pt' \nENCODER_PATH = '/kaggle/input/emotion-sequence-transformer-bilstm/pytorch/default/1/emotion_label_encoder.joblib' \n\n# Directory containing the video files\nVIDEO_ROOT_DIR = path + '/VideoFlash'\n\nN_SAMPLES = 5 # Number of random videos to test\n\nDEVICE = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n\n# Emotion mapping\nEMOTIONS_MAP = {'ANG': 'Angry', 'DIS': 'Disgust', 'FEA': 'Fear', \n 'HAP': 'Happy', 'NEU': 'Neutral', 'SAD': 'Sad'}","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-26T12:46:18.796241Z","iopub.execute_input":"2025-10-26T12:46:18.796571Z","iopub.status.idle":"2025-10-26T12:46:18.803792Z","shell.execute_reply.started":"2025-10-26T12:46:18.796548Z","shell.execute_reply":"2025-10-26T12:46:18.802882Z"}},"outputs":[],"execution_count":6},{"cell_type":"markdown","source":"# Model Definition","metadata":{}},{"cell_type":"code","source":"class LandmarkSequenceTransformer(nn.Module):\n def __init__(self, num_classes=6, feature_dim=478*3, embed_dim=768, hidden_dim=384, \n num_layers=6, num_heads=8, use_bilstm=True, max_seq_len=200, pre_embed_dim=256):\n \n super().__init__()\n self.use_bilstm = use_bilstm\n\n # Preliminary Feature Reduction (PCA-like)\n self.feature_reducer = nn.Sequential(\n nn.Linear(feature_dim, pre_embed_dim),\n nn.GELU(),\n nn.LayerNorm(pre_embed_dim),\n nn.Dropout(0.3)\n )\n \n # Custom Embedding: Transforms the 1434 features into the model's latent space\n self.embed = nn.Sequential(\n nn.Linear(pre_embed_dim, embed_dim), # Input size is now pre_embed_dim\n nn.LayerNorm(embed_dim),\n nn.GELU(),\n nn.Dropout(0.3)\n )\n \n # Positional Encoding: Essential for sequence transformers (learnable)\n self.pos_encoder = nn.Embedding(max_seq_len, embed_dim)\n \n # Transformer Encoder Stack\n encoder_layer = nn.TransformerEncoderLayer(\n d_model=embed_dim, \n nhead=num_heads, \n dim_feedforward=embed_dim * 4, # Standard practice\n dropout=0.3, \n batch_first=True\n )\n self.transformer_encoder = nn.TransformerEncoder(encoder_layer, num_layers=num_layers)\n \n # Sequential layers (optional BiLSTM for temporal refinement)\n if use_bilstm:\n self.bilstm = nn.LSTM(\n input_size=embed_dim, hidden_size=hidden_dim,\n num_layers=2, batch_first=True, bidirectional=True,\n dropout=0.3\n )\n fc_input_dim = hidden_dim * 2\n else:\n fc_input_dim = embed_dim\n\n self.fc = nn.Sequential(\n nn.LayerNorm(fc_input_dim),\n nn.ReLU(),\n nn.Dropout(0.1),\n nn.Linear(fc_input_dim, num_classes)\n )\n\n def forward(self, X: torch.Tensor, sequence_lengths: torch.Tensor):\n target_device = X.device\n \n B, T, D_in = X.shape\n\n # Reduce the 1434 features to 256\n X = self.feature_reducer(X)\n \n # Embedding + Positional Encoding\n X = self.embed(X)\n \n positions = torch.arange(T, device=target_device).unsqueeze(0).expand(B, T)\n positions = positions.clamp(max=self.pos_encoder.num_embeddings - 1) \n \n X = X + self.pos_encoder(positions)\n \n # Padding Mask\n # mask is True for padding elements\n mask = torch.arange(T, device=target_device).unsqueeze(0).expand(B, T) >= sequence_lengths.unsqueeze(1)\n \n # Pass through the Transformer ENCODER\n transformer_out = self.transformer_encoder(X, src_key_padding_mask=mask) \n\n # BiLSTM / Output Sequence Selection\n if self.use_bilstm:\n # Sort lengths and data for packed sequence compatibility\n sequence_lengths_sorted, perm_idx = sequence_lengths.sort(0, descending=True)\n transformer_out_sorted = transformer_out[perm_idx]\n \n # Pack the sequence to exclude padding from the LSTM calculation\n packed_input = nn.utils.rnn.pack_padded_sequence(\n transformer_out_sorted, \n sequence_lengths_sorted.cpu(), # LSTM requires lengths on CPU\n batch_first=True\n )\n\n # Pass through LSTM\n packed_output, _ = self.bilstm(packed_input)\n \n # Unpack the sequence to get the full padded tensor back\n lstm_out_sorted, _ = nn.utils.rnn.pad_packed_sequence(\n packed_output, \n batch_first=True, \n total_length=T # Restore to original max length T\n )\n \n # Unsort the output to restore original batch order\n sequence_output = torch.empty_like(lstm_out_sorted).scatter_(\n 0, perm_idx.unsqueeze(-1).unsqueeze(-1).expand_as(lstm_out_sorted), lstm_out_sorted\n )\n\n else:\n sequence_output = transformer_out\n \n # 5. MASKED MEAN POOLING\n real_tokens_mask = (~mask).unsqueeze(-1).float() \n masked_output = sequence_output * real_tokens_mask\n summed_output = masked_output.sum(1) \n \n num_real_tokens = sequence_lengths.unsqueeze(-1).float() \n pooled = summed_output / num_real_tokens.clamp(min=1e-8)\n \n out = self.fc(pooled) \n \n return out","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-26T12:46:23.110078Z","iopub.execute_input":"2025-10-26T12:46:23.110465Z","iopub.status.idle":"2025-10-26T12:46:23.125937Z","shell.execute_reply.started":"2025-10-26T12:46:23.110437Z","shell.execute_reply":"2025-10-26T12:46:23.124636Z"}},"outputs":[],"execution_count":7},{"cell_type":"markdown","source":"# Load Assets and Discover Videos","metadata":{}},{"cell_type":"code","source":"# Load Standardization Tensors\nGLOBAL_MEAN_TENSOR = torch.load(GLOBAL_MEAN_PATH).to(DEVICE)\nGLOBAL_STD_TENSOR = torch.load(GLOBAL_STD_PATH).to(DEVICE)\nINPUT_FEATURE_DIM = GLOBAL_MEAN_TENSOR.shape[0]\n\n# Load Label Encoder and define Class Names/Output Dimension\nDEPLOY_LE = joblib.load(ENCODER_PATH)\nCLASS_NAMES = DEPLOY_LE.classes_.tolist() \nOUTPUT_DIM = len(CLASS_NAMES)\n\n# Load the ENTIRE Model Object\nmodel = torch.load(MODEL_PATH, map_location=DEVICE, weights_only=False)\nmodel.eval()\n\n# Discover all video files in the root directory\nvideo_extensions = ('.flv', '.mp4', '.avi', '.mov')\nall_video_files = [f for f in os.listdir(VIDEO_ROOT_DIR) if f.lower().endswith(video_extensions)]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-26T12:46:27.202343Z","iopub.execute_input":"2025-10-26T12:46:27.202650Z","iopub.status.idle":"2025-10-26T12:46:28.663526Z","shell.execute_reply.started":"2025-10-26T12:46:27.202629Z","shell.execute_reply":"2025-10-26T12:46:28.662484Z"}},"outputs":[],"execution_count":8},{"cell_type":"markdown","source":"# Core Prediction and Extraction Functions","metadata":{}},{"cell_type":"code","source":"def get_actual_emotion_from_filename(filename, emotions_map):\n \"\"\"\n Extracts the emotion code from the filename and maps it to the full name.\n e.g., '1031_IWW_HAP_XX.flv' -> 'HAP' -> 'Happy'\n \"\"\"\n try:\n # Remove extension\n name_without_ext = os.path.splitext(filename)[0]\n # Split by underscore and get the 3rd part (index 2)\n emotion_code = name_without_ext.split('_')[2]\n # Map code to full name\n return emotions_map.get(emotion_code, 'Unknown')\n except (IndexError, KeyError):\n return 'Error: Invalid Filename Format'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-26T12:46:31.747782Z","iopub.execute_input":"2025-10-26T12:46:31.748221Z","iopub.status.idle":"2025-10-26T12:46:31.753811Z","shell.execute_reply.started":"2025-10-26T12:46:31.748166Z","shell.execute_reply":"2025-10-26T12:46:31.752852Z"}},"outputs":[],"execution_count":9},{"cell_type":"code","source":"def extract_and_standardize_landmarks_live(video_path, mean_tensor, std_tensor):\n \"\"\"\n Processes the raw video file using MediaPipe, extracts and flattens\n normalized (x, y, z) landmarks, and applies standardization.\n \"\"\"\n all_frame_features = []\n \n with mp_face_mesh.FaceMesh(\n max_num_faces=1, refine_landmarks=True, min_detection_confidence=0.5, \n min_tracking_confidence=0.5) as face_mesh:\n \n cap = cv2.VideoCapture(video_path)\n if not cap.isOpened():\n return None\n \n while cap.isOpened():\n success, image = cap.read()\n if not success:\n break\n\n image.flags.writeable = False\n image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n results = face_mesh.process(image)\n\n if results.multi_face_landmarks:\n landmarks = results.multi_face_landmarks[0].landmark\n features = []\n for landmark in landmarks:\n features.extend([landmark.x, landmark.y, landmark.z])\n \n if len(features) == INPUT_FEATURE_DIM:\n all_frame_features.append(features)\n\n cap.release()\n\n if not all_frame_features:\n return None\n \n X_raw = np.array(all_frame_features, dtype=np.float32)\n X_tensor = torch.tensor(X_raw, dtype=torch.float32).to(DEVICE) \n \n X_standardized = (X_tensor - mean_tensor) / std_tensor\n \n return X_standardized","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-26T12:46:32.880830Z","iopub.execute_input":"2025-10-26T12:46:32.881284Z","iopub.status.idle":"2025-10-26T12:46:32.889422Z","shell.execute_reply.started":"2025-10-26T12:46:32.881256Z","shell.execute_reply":"2025-10-26T12:46:32.888426Z"}},"outputs":[],"execution_count":10},{"cell_type":"code","source":"def predict_video_emotion(X_standardized, model):\n \"\"\"Feeds the standardized sequence through the model to get probabilities.\"\"\"\n # Add batch dimension: (T, D) -> (1, T, D)\n features = X_standardized.unsqueeze(0) \n # Get sequence length\n lengths = torch.tensor([X_standardized.size(0)], dtype=torch.long)\n \n with torch.no_grad():\n logits = model(features, lengths)\n probabilities = torch.softmax(logits, dim=1).squeeze(0).cpu().numpy()\n \n return probabilities","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-10-26T12:46:36.349835Z","iopub.execute_input":"2025-10-26T12:46:36.350162Z","iopub.status.idle":"2025-10-26T12:46:36.356011Z","shell.execute_reply.started":"2025-10-26T12:46:36.350139Z","shell.execute_reply":"2025-10-26T12:46:36.355060Z"}},"outputs":[],"execution_count":11},{"cell_type":"markdown","source":"# Visualization Utilities","metadata":{}},{"cell_type":"code","source":"def visualize_prediction(probabilities, class_names, actual_emotion, deploy_le):\n \"\"\"Generates and displays the prediction results using HTML bar charts.\"\"\"\n \n predicted_index = np.argmax(probabilities)\n predicted_emotion = deploy_le.inverse_transform([predicted_index])[0] \n \n html_content = \"
\n Ground Truth: {actual_emotion} | \n Predicted: {predicted_emotion}\n
\n \"\"\"\n \n html_content += \"| {name} | \n\n \n {prob_percent:.2f}%\n \n | \n
\n Ground Truth: Angry | \n Predicted: Angry\n
\n| Angry | \n\n \n 91.74%\n \n | \n
| Disgust | \n\n \n 1.79%\n \n | \n
| Fear | \n\n \n 1.78%\n \n | \n
| Happy | \n\n \n 1.59%\n \n | \n
| Neutral | \n\n \n 1.48%\n \n | \n
| Sad | \n\n \n 1.62%\n \n | \n
\n Ground Truth: Angry | \n Predicted: Angry\n
\n| Angry | \n\n \n 91.31%\n \n | \n
| Disgust | \n\n \n 2.06%\n \n | \n
| Fear | \n\n \n 1.75%\n \n | \n
| Happy | \n\n \n 1.67%\n \n | \n
| Neutral | \n\n \n 1.48%\n \n | \n
| Sad | \n\n \n 1.73%\n \n | \n
\n Ground Truth: Angry | \n Predicted: Angry\n
\n| Angry | \n\n \n 91.52%\n \n | \n
| Disgust | \n\n \n 1.65%\n \n | \n
| Fear | \n\n \n 1.54%\n \n | \n
| Happy | \n\n \n 1.95%\n \n | \n
| Neutral | \n\n \n 1.73%\n \n | \n
| Sad | \n\n \n 1.61%\n \n | \n
\n Ground Truth: Happy | \n Predicted: Happy\n
\n| Angry | \n\n \n 2.20%\n \n | \n
| Disgust | \n\n \n 4.01%\n \n | \n
| Fear | \n\n \n 1.43%\n \n | \n
| Happy | \n\n \n 86.81%\n \n | \n
| Neutral | \n\n \n 2.13%\n \n | \n
| Sad | \n\n \n 3.43%\n \n | \n
\n Ground Truth: Fear | \n Predicted: Fear\n
\n| Angry | \n\n \n 1.22%\n \n | \n
| Disgust | \n\n \n 1.76%\n \n | \n
| Fear | \n\n \n 93.25%\n \n | \n
| Happy | \n\n \n 1.50%\n \n | \n
| Neutral | \n\n \n 1.28%\n \n | \n
| Sad | \n\n \n 1.00%\n \n | \n