Expression Lab Classroom · 人脸表情实验室
Expression Lab Classroom 是一个 Python 人脸关键点与面部动作单元(AU)可视化工具。软件支持读取模型强度或测量相对基准的面部位移,通过 Python 编写表情分类规则,并在桌面窗口中实时展示结果。
主要功能
- 两种识别模式。默认模式提供 12 个 AU 的模型强度。位移模式测量选定的面部关键点相对基准照片沿 AU 动作方向的位移。
- 多种输入方式。可使用摄像头、本地图片和视频文件。界面支持暂停,查看 478 个人脸关键点、参考点和位移箭头。
- 结果导出。可导出 CSV 数据,也可保存 PNG。PNG 保留点击时的画面和所选叠加项,画面下方显示该帧的表情结果。
运行环境
- Python:CPython 3.9~3.14,推荐使用 Python 3.12。
- Windows:Windows 10 / 11,x64。
- macOS:macOS 14 或更新版本,Apple Silicon。
- 推理设备:CPU。
安装
pip install expression-lab-classroom
使用指定的 Python 环境安装:
| 系统 | 安装命令 |
|---|---|
| Windows | py -3 -m pip install expression-lab-classroom |
| macOS | python3 -m pip install expression-lab-classroom |
也可通过中国 PyPI 镜像源安装,例如清华大学镜像源:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple expression-lab-classroom
升级已安装的版本时,在安装命令中添加 --upgrade。
快速开始
将以下代码保存为 example.py:
from expression_lab import FaceCamera, get_grade
face = FaceCamera()
for au in face:
g6 = get_grade(au[6])
g12 = get_grade(au[12])
expression = "自然"
if g12 >= 6 and g6 >= 5:
expression = "真笑"
elif g12 >= 6:
expression = "假笑"
face.show(expression)
使用安装该库的 Python 运行脚本。Windows 执行 py -3 example.py,macOS 执行 python3 example.py,程序会自动打开桌面窗口。
示例使用 AU6(眼周收缩)与 AU12(嘴角上提)组合表情分类规则。可调整条件阈值和结果文字,也可使用其他 AU 构建规则。
核心 API
| API | 功能 |
|---|---|
FaceCamera() |
创建检测窗口,逐帧提供按 AU 编号索引的强度数据。 |
au[6] |
读取 AU6 的原始连续强度,取值范围为 0~5。 |
get_grade(value) |
将原始强度换算为 1~20 的整数 g 值。 |
face.show(expression) |
在窗口中显示表情分类结果。 |
支持的动作单元为 AU1、AU2、AU4、AU5、AU6、AU9、AU12、AU15、AU17、AU20、AU25、AU26。界面默认显示 AU6 和 AU12,可展开查看完整表格。
将 0~5 的原始强度 I 乘以 4 后四舍五入,最低等级取 1,即 g = max(1, floor(4 × I + 0.5))。
基准位移模式
用 FaceCamera(mode=1) 创建位移实验。get_eye_distance(face) 打开基准采集窗口,拍下自然表情后关闭窗口,并返回基准照片中两侧外眼角的距离(像素)。之后 au[n] 返回相对基准、沿指定动作方向的位移,单位也是基准照片像素。位移除以眼外距得到无量纲比例 f。
from expression_lab import FaceCamera, get_eye_distance
with FaceCamera(mode=1) as face:
while (eye_distance := get_eye_distance(face)) is not None:
for au in face:
f6 = au[6] / eye_distance
f12 = au[12] / eye_distance
expression = "自然"
if f12 >= 0.07 and f6 >= 0.02:
expression = "真笑"
elif f12 >= 0.07:
expression = "假笑"
face.show(expression)
这些阈值用于课堂对比眼周收缩和嘴角上提。重采基准后,外层循环会获取新眼外距。使用视频时,可以暂停在自然表情帧采集基准,再继续播放。
命令行使用
直接启动默认的模型强度模式:
expression-lab
也可通过 Python 模块选择输入:
python -m expression_lab
python -m expression_lab --sample
python -m expression_lab --image "image.jpg"
python -m expression_lab --video "video.mp4"
--sample 使用内置人脸样例,--image 和 --video 分别打开本地图片与视频。以上 python 指向安装该库的解释器,Windows 可使用 py -3,macOS 可使用 python3。
模型下载与离线使用
首次启动时,程序从百度智能云 BOS 自动下载模型,完成 SHA256 校验后保存到本地缓存。默认模式需要约 47 MB 的模型文件,位移模式需要约 3.6 MiB 的人脸关键点模型。模型准备完成后,两个模式均可离线运行。
预下载模型
python -m expression_lab.download_models
python -m expression_lab.download_models --check
第一条命令下载并准备模型,--check 检查本地模型文件与 SHA256 校验值。
只使用基准位移模式时,可运行 python -m expression_lab.download_models --mode 1。
模型目录
| 系统 | 默认缓存位置 |
|---|---|
| Windows | %LOCALAPPDATA%/expression-lab/models/libreface-v1 |
| macOS | ~/Library/Caches/expression-lab/models/libreface-v1 |
环境变量 EXPRESSION_LAB_CACHE_DIR 可设置缓存根目录,模型保存在其下的 models/libreface-v1 子目录。
如需加载已有模型目录,可在代码中指定:
face = FaceCamera(model_dir="path/to/models/libreface-v1")
命令行对应参数为 --model-dir "path/to/models/libreface-v1"。
第三方组件与授权
- MediaPipe:人脸关键点检测,采用 Apache License 2.0。
- LibreFace:AU 强度分析,采用 USC 软件授权,适用于教育、研究和非营利用途。授权详情见 LibreFace 项目。
上游许可证、模型来源和 SHA256 清单随软件包提供。
Metadata
Release files for expression-lab-classroom 1.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| expression_lab_classroom-1.6.1.tar.gz | 2.0 MB | Without provenance | Details for expression_lab_classroom-1.6.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| expression_lab_classroom-1.6.1-py3-none-any.whl | Python 3 | none | any | Details for expression_lab_classroom-1.6.1-py3-none-any.whl |
Total release size: 4.1 MB
Release files / expression_lab_classroom-1.6.1.tar.gz
| Download URL | expression_lab_classroom-1.6.1.tar.gz |
|---|---|
| Size | 2.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
31e27a4bff02d3ec2428a84ee0be7a62e180669973e12f89583d22b731bce982
|
|
BLAKE2b-256 checksum How to use checksums |
3ed308d6b3db5db2366845b596c99551d9087a8d3e54b907fe72c03878ec96b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / expression_lab_classroom-1.6.1-py3-none-any.whl
| Download URL | expression_lab_classroom-1.6.1-py3-none-any.whl |
|---|---|
| Size | 2.1 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ab4ab98b0120aeaae6e76ebe9b55f851ed990f7f86427affc3491f93899d3b8f
|
|
BLAKE2b-256 checksum How to use checksums |
b277159d57df54f85834a981f83bc78989c65caf9b682bfd6194efc06c0ed4b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Security for expression-lab-classroom 1.6.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.