Skip to main content

人脸表情实验室 · Expression Lab Classroom

面向高中课堂的 Python 3.12 人脸点位、AU 动作特征与表情规则可视化工具。

1.4.2 更新

  • 学生入口使用 face = FaceCamera()、face.show(expression),默认结果为“自然”“真笑”“假笑”。
  • 新增 get_grade(au[6]) 等可读写法:读取原始0~5连续模型强度,线性换算为0~20整数g值。
  • 默认只显示AU6和AU12,可展开全部AU;表格以AU为行,“g值”列只显示数字。
  • 修复Mac图片、视频和CSV文件窗口提前关闭的问题,使用异步文件选择。

安装

Windows 10/11 x64(Python 3.12):

py -3.12 -m pip install expression-lab-classroom

中国大陆可使用国内 PyPI 镜像,镜像同步新版本可能有延迟:

py -3.12 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple expression-lab-classroom

Mac Apple Silicon、macOS 14+ 使用 python3.12 -m pip 安装;建议使用虚拟环境。本项目wheel不含平台二进制,底层依赖由pip按操作系统选择。目前支持范围为上述两个平台。

学生代码(按约定计8行)

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)

保存为 学生主程序.py,执行 py -3.12 学生主程序.py 自动打开原生桌面窗口。若Windows的 py -3 默认指向Python3.12,也可用 py -3 学生主程序.py。Mac使用 python3.12 学生主程序.py。不需要浏览器。

启动后有人脸即可显示模型强度,无需先采集基准。默认表格显示AU6和AU12两行,可展开所有12个AU。“g值”列只显示数字,折线图写“AU6 · g值”,不绑定学生变量名。示例用g6对应AU6、g12对应AU12,学生也可写g999=get_grade(au[6])。默认迭代器按AU编号返回原始0~5强度。g6 = get_grade(au[6])、g12 = get_grade(au[12])显式转换,再比较变量。物理11行,排除import、if/elif语法后计8行,学生最多修改两行条件和两行结果文字。

本地示例阈值g12≥6且g6≥5表示眼周参与微笑,仅g12≥6表示嘴角微笑。阈值来自两张同一虚构成年人的合成演示图,不能证明内心是否真诚,不是通用真假微笑标准。“采集基准”仅用于可选点位箭头观察,不参与强度计算。

模型从国内BOS下载,之后离线运行

代码包不包含模型权重。首次运行缺少模型时,在后台从百度BOS下载约47MB模型,界面显示进度。每个文件使用安装包内固定的SHA256核验,完成后原子写入本机用户缓存。已有完整缓存时不访问网络。失败后重新打开程序,只下载缺少或损坏的文件。

缓存目录:Windows %LOCALAPPDATA%/expression-lab/models/libreface-v1;Mac ~/Library/Caches/expression-lab/models/libreface-v1。教师可设置 EXPRESSION_LAB_CACHE_DIR 指定缓存根目录,底下仍保留 models/libreface-v1。BOS访问不需要学生的账户或密钥。

教师可在课前联网执行以下命令,再断网使用:

py -3.12 -m expression_lab.download_models
py -3.12 -m expression_lab.download_models --check

--check只检查本地文件和SHA256,不联网。也可把已经准备好的 models/libreface-v1 目录复制到离线电脑的缓存根目录。显式 FaceCamera(model_dir="本地目录") 或 --model-dir 始终只使用指定目录,不自动下载。完整离线ZIP保持原有本地模型读取方式。

无摄像头可执行 py -3.12 -m expression_lab --sample,使用随包的虚构成年人人脸样例。

特征含义与模型

MediaPipe离线提供478个人脸点;LibreFace ONNX提供12个AU强度输出。原始0~5连续模型强度乘4后四舍五入为g值(0~20),保留0表示无动作。ONNX输出本身是归一化0~1,等价公式为floor(20×clip(output,0,1)+0.5)。不使用旧版Lien位移映射,不做基准相减或时间平滑;显示换刻度不增加模型精度,也不产生新的人工FACS等级。

AU6正式名称Cheek Raiser(面颊抬起),眼轮匝肌眶部收缩可使眼裂变窄、外眼角纹理变化,因此界面写为“眼周收缩(面颊上提)”。橙色代表点不是模型输入边界,模型使用整张对齐人脸。

参考:LibreFace输出后处理、微笑眼周与情绪研究、MediaPipe。

许可证

随包保留各上游许可证。LibreFace模型及相关实现的USC授权允许教育、研究和非营利用途;商业用途需要另行取得许可。模型来源和SHA256保留在包内清单中。

Metadata

Release files for expression-lab-classroom 1.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for expression-lab-classroom 1.4.2
File Size Uploaded Provenance Actions
expression_lab_classroom-1.4.2.tar.gz 2.0 MB Without provenance Details for expression_lab_classroom-1.4.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for expression-lab-classroom 1.4.2
File Interpreter ABI Platform Actions
expression_lab_classroom-1.4.2-py3-none-any.whl Python 3 none any Details for expression_lab_classroom-1.4.2-py3-none-any.whl

Total release size: 4.1 MB

Release files / expression_lab_classroom-1.4.2.tar.gz

Download URL expression_lab_classroom-1.4.2.tar.gz
Size 2.0 MB
Tags Source
SHA-256 checksum
How to use checksums
095e3d3db82f29661f35fe4e16acb9f908f679f30f260e1e115cda573ee84387
BLAKE2b-256 checksum
How to use checksums
cd839bdf3bd70ec5e913c64a2f2edc5dcaffab366839f64f8b5f460180f33cc3
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.4.2-py3-none-any.whl

Download URL expression_lab_classroom-1.4.2-py3-none-any.whl
Size 2.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
7630369f40064683de2a2f8b592a26bad9fd8e7fd2361354c49fa60f137cefa0
BLAKE2b-256 checksum
How to use checksums
dfdb532b4f62725194627f8a4f3b73be0b4058749d403c9688286bf4053f96c6
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.4.2

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page