PyTorch MPIIGaze 演示项目教程
1. 项目的目录结构及介绍
pytorch_mpiigaze_demo/
├── figures/
├── ptgaze/
│ ├── data/
│ │ ├── configs/
│ │ └── models/
│ ├── __init__.py
│ ├── gaze_estimator.py
│ ├── main.py
│ └── utils.py
├── .gitignore
├── LICENSE
├── MANIFEST.in
├── README.md
├── requirements.txt
└── setup.py
figures/
: 存放项目相关的图表文件。ptgaze/
: 项目的主要代码目录。data/
: 存放数据文件,包括配置文件和模型文件。configs/
: 配置文件目录。models/
: 模型文件目录。
__init__.py
: 模块初始化文件。gaze_estimator.py
: 视线估计的主要逻辑文件。main.py
: 项目的启动文件。utils.py
: 工具函数文件。
.gitignore
: Git 忽略文件配置。LICENSE
: 项目许可证文件。MANIFEST.in
: 打包清单文件。README.md
: 项目说明文档。requirements.txt
: 项目依赖文件。setup.py
: 项目安装文件。
2. 项目的启动文件介绍
项目的启动文件是 ptgaze/main.py
。该文件包含了项目的主要执行逻辑,可以通过命令行参数来运行不同的模式(如 mpiigaze
、mpiifacegaze
或 eth-xgaze
)。
# ptgaze/main.py
import argparse
from ptgaze import GazeEstimator
def main():
parser = argparse.ArgumentParser(description="Gaze estimation using MPIIGaze and MPIIFaceGaze")
parser.add_argument("--config", type=str, help="Config file")
parser.add_argument("--mode", type=str, choices=["mpiigaze", "mpiifacegaze", "eth-xgaze"], help="Mode selection")
parser.add_argument("--face-detector", type=str, choices=["dlib", "face_alignment_dlib", "face_alignment_sfd", "mediapipe"], help="Face detector selection")
parser.add_argument("--device", type=str, choices=["cpu", "cuda"], help="Device selection")
parser.add_argument("--image", type=str, help="Input image file")
parser.add_argument("--video", type=str, help="Input video file")
parser.add_argument("--camera", type=int, help="Camera index")
parser.add_argument("--output-dir", type=str, help="Output directory")
parser.add_argument("--ext", type=str, choices=["avi", "mp4"], help="Output file extension")
parser.add_argument("--no-screen", action="store_true", help="Disable screen output")
parser.add_argument("--debug", action="store_true", help="Enable debug mode")
args = parser.parse_args()
gaze_estimator = GazeEstimator(args)
gaze_estimator.run()
if __name__ == "__main__":
main()
3. 项目的配置文件介绍
项目的配置文件位于 ptgaze/data/configs/
目录下。配置文件用于定义项目的各种参数,如模型选择、设备选择、输入输出设置等。
例如,eth-xgaze.yaml
配置文件内容如下:
model:
name: eth-xgaze
device: cuda
input:
type: video
source: 0
output:
directory: outputs
extension: mp4
face_detector:
type: mediapipe
debug: false
model
: 定义使用的模型名称和设备。input
: 定义输入类型和源(如视频文件或摄像头索引)。output
: 定义输出目录和文件扩展名。face_detector
: 定义使用的面部检测器类型。debug
: 是否启用调试模式。
通过配置文件,用户可以灵活地调整项目的运行参数,