Namespace(weights='weights/last.pt', source='C:/Users/lieweiai/Desktop/26321934-1-192.mp4', output='../inference/output', img_size=640, conf_thres=0.3, iou_thres=0.5, fourcc='mp4v', device='', view_img=False, save_txt=False, classes=None, agnostic_nms=False, augment=False) Using CPU /home/book/anaconda3/envs/yolov5face/lib/python3.9/site-packages/torch/serialization.py:1580: SourceChangeWarning: source code of class 'torch.nn.modules.container.Sequential' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/book/anaconda3/envs/yolov5face/lib/python3.9/site-packages/torch/serialization.py:1580: SourceChangeWarning: source code of class 'torch.nn.modules.conv.Conv2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/book/anaconda3/envs/yolov5face/lib/python3.9/site-packages/torch/serialization.py:1580: SourceChangeWarning: source code of class 'torch.nn.modules.batchnorm.BatchNorm2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/book/anaconda3/envs/yolov5face/lib/python3.9/site-packages/torch/serialization.py:1580: SourceChangeWarning: source code of class 'torch.nn.modules.activation.LeakyReLU' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/book/anaconda3/envs/yolov5face/lib/python3.9/site-packages/torch/serialization.py:1580: SourceChangeWarning: source code of class 'torch.nn.modules.container.ModuleList' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/book/anaconda3/envs/yolov5face/lib/python3.9/site-packages/torch/serialization.py:1580: SourceChangeWarning: source code of class 'torch.nn.modules.pooling.MaxPool2d' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) /home/book/anaconda3/envs/yolov5face/lib/python3.9/site-packages/torch/serialization.py:1580: SourceChangeWarning: source code of class 'torch.nn.modules.upsampling.Upsample' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes. warnings.warn(msg, SourceChangeWarning) Traceback (most recent call last): File "/home/book/rk3566/ai_tools/FaceRecognition-master/detect.py", line 166, in <module> print(detect()) File "/home/book/rk3566/ai_tools/FaceRecognition-master/detect.py", line 50, in detect dataset = LoadImages(source, img_size=imgsz) File "/home/book/rk3566/ai_tools/FaceRecognition-master/utils/datasets.py", line 66, in __init__ assert self.nF > 0, 'No images or videos found in %s. Supported formats are:\nimages: %s\nvideos: %s' % \ AssertionError: No images or videos found in C:/Users/lieweiai/Desktop/26321934-1-192.mp4. Supported formats are: images: ['.bmp', '.jpg', '.jpeg', '.png', '.tif', '.dng'] videos: ['.mov', '.avi', '.mp4', '.mpg', '.mpeg', '.m4v', '.wmv', '.mkv'] 有新错误
时间: 2025-07-08 21:31:01 浏览: 6
<think>嗯,用户遇到了一个错误,需要我来帮忙分析解决。首先,看看用户提供的错误信息。主要的问题出现在运行一个基于YOLOv5的人脸检测程序时,程序抛出了一个AssertionError,指出在指定的路径下找不到支持的图像或视频文件。具体来说,路径是C:/Users/lieweiai/Desktop/26321934-1-192.mp4,而程序支持的格式包括常见的图片和视频扩展名。
首先,我需要理解这个错误的原因。用户使用的是YOLOv5的代码,可能是YOLOv5-face或者其他变种,用于处理视频文件进行推理。错误信息显示在加载数据时,程序检查了source参数指定的路径,但发现没有符合支持格式的文件。AssertionError触发的条件是self.nF(文件数量)大于0,但显然这里没有找到文件,所以抛出了错误。
接下来,我需要考虑可能的原因。首先,检查文件路径是否正确。用户提供的路径是C:/Users/lieweiai/Desktop/26321934-1-192.mp4,可能存在以下几个问题:
1. 文件路径中的斜杠是否正确。虽然Windows通常使用反斜杠,但在Python中正斜杠也是可以接受的,但需要确认路径是否存在。
2. 文件名是否正确,是否有拼写错误,比如扩展名是否正确,比如.mp4是否正确,或者是否有隐藏的额外扩展名,比如.mp4.txt。
3. 文件是否确实存在于该路径下,可能被移动或删除。
4. 文件权限问题,导致程序无法读取该文件。
另外,用户的环境是在Anaconda下的yolov5face环境,使用的是CPU。程序运行时出现了一些关于PyTorch的警告,提示某些类的源代码发生了变化,但这些警告通常不会导致程序崩溃,可能只是提示信息。主要的错误还是AssertionError。
接下来,我需要考虑用户可能的操作步骤是否正确。用户是否正确地调用了detect.py脚本,并传递了正确的参数?从代码中的Namespace参数来看,source参数指定的是视频文件路径,output是输出目录,其他参数如img_size、conf_thres等是模型推理时的参数设置。
可能的解决步骤包括:
1. 确认文件路径是否正确。用户需要检查路径C:/Users/lieweiai/Desktop/26321934-1-192.mp4是否存在,特别是注意用户名是否正确,比如lieweiai是否是当前用户的正确用户名。有时候,路径中的用户名可能有拼写错误,比如大小写问题,或者在Windows系统中路径中的用户目录是否实际存在。
2. 检查文件扩展名是否正确。虽然用户提供的文件名是.mp4,但需要确认实际文件的扩展名是否确实是.mp4,而不是其他类似.mov、.avi等,或者是否有多个扩展名,比如26321934-1-192.mp4.mkv。例如,某些情况下,下载的文件可能会带有多余的扩展名。
3. 验证文件是否损坏。用户可以尝试用其他视频播放器(如VLC、Windows Media Player)打开该文件,确认视频是否可以正常播放。如果无法播放,说明文件可能已损坏,需要重新获取。
4. 检查程序支持的视频编解码器。尽管.mp4在支持列表中,但不同的.mp4文件可能使用不同的编码方式。例如,某些H.265编码的视频可能不被OpenCV的VideoCapture支持,而程序可能依赖OpenCV来读取视频。用户可以尝试用OpenCV单独读取该视频文件,测试是否能够打开。
5. 路径中的转义字符问题。虽然用户提供的路径中使用的是正斜杠,这在Python中是允许的,但有时路径中包含特殊字符或空格可能导致问题。不过在这个例子中,路径似乎没有空格或特殊字符,但可以尝试将路径用双引号包裹,或者在代码中使用原始字符串(r'')来避免转义问题。
6. 检查文件权限。确保当前运行程序的用户有权限读取该文件。特别是在某些系统上,桌面文件夹可能有权限限制,需要确认是否有读取权限。
7. 检查源代码中的文件加载逻辑。用户使用的LoadImages类(来自utils/datasets.py)可能存在一些问题,比如对于某些特殊路径的处理不完善。例如,如果路径中包含中文字符或其他特殊字符,可能导致文件无法被正确识别。不过用户提供的路径中没有中文字符,所以这个问题可能性较低。
8. 确认使用的库版本是否兼容。例如,OpenCV的版本是否支持.mp4文件的解码,可能需要安装正确的视频编码器,比如ffmpeg。用户可以尝试安装或重新安装ffmpeg,或者使用其他视频格式进行测试。
此外,用户还提到了使用CPU,而PyTorch的警告信息可能表明环境中某些模块的版本不匹配,或者模型加载时出现了问题。但根据错误信息,主要问题还是文件未找到,所以优先解决路径和文件问题。
总结可能的解决方案步骤:
1. 用户应首先确认文件路径是否正确无误,文件确实存在。
2. 检查文件扩展名是否正确,与支持列表中的匹配。
3. 确保文件没有损坏,能够被其他软件正常读取。
4. 检查程序是否有权限访问该文件。
5. 尝试使用绝对路径或相对路径的不同写法,排除路径格式问题。
6. 如果视频编码问题,尝试转换视频格式或使用其他编码方式。
7. 检查OpenCV是否安装了正确的编解码器支持,可能需要重新安装或安装额外的包。
最后,用户可能需要根据上述步骤逐一排查,找到导致AssertionError的具体原因,并进行相应的修复。</think>让我们逐步分析并解决你遇到的错误:
---
### **错误核心分析**
主要报错信息:
```python
AssertionError: 在路径 C:/Users/lieweiai/Desktop/26321934-1-192.mp4 中未找到支持的图像或视频文件。
支持格式:
图片: ['.bmp', '.jpg', '.jpeg', '.png', '.tif', '.dng']
视频: ['.mov', '.avi', '.mp4', '.mpg', '.mpeg', '.m4v', '.wmv', '.mkv']
```
---
### **逐步解决方案**
#### **1. 验证文件路径是否正确**
- 🔍 **检查点**:
- 确认文件 `26321934-1-192.mp4` 确实存在于 `C:/Users/lieweiai/Desktop/` 路径下。
- 右键文件 > 属性 > 查看完整文件名,确保扩展名是 `.mp4`(而非隐藏的 `.mp4.txt` 等)。
- 💻 **验证方法**(Python代码):
```python
import os
path = r'C:/Users/lieweiai/Desktop/26321934-1-192.mp4'
print("文件存在:", os.path.exists(path))
print("是文件:", os.path.isfile(path))
```
#### **2. 检查文件扩展名兼容性**
- ⚠️ **注意**:
- 即使扩展名是 `.mp4`,实际编码格式可能不被OpenCV支持(比如H.265编码)。
- 尝试用其他播放器(如VLC)打开该视频,确认是否可正常播放。
#### **3. 排除路径格式问题**
- 🔧 **修改建议**:
- 使用原始字符串或双反斜杠避免转义:
```python
source = r'C:\Users\lieweiai\Desktop\26321934-1-192.mp4' # Windows路径格式
```
#### **4. 检查OpenCV的视频解码能力**
- 📦 **安装编解码器**:
```bash
pip install opencv-contrib-python-headless # 安装完整版OpenCV
```
#### **5. 尝试其他视频文件**
- 🧪 **验证步骤**:
- 准备一个简单的测试视频(如手机拍摄的MP4文件)替换原文件,排除文件损坏问题。
#### **6. 检查文件权限**
- 🔐 **操作步骤**:
- 右键文件 > 属性 > 安全 > 检查当前用户是否有读取权限。
---
### **补充说明**
- **警告信息**(`SourceChangeWarning`)是PyTorch加载模型时的非致命警告,通常不影响运行,可通过以下方式隐藏:
```python
import warnings
warnings.filterwarnings("ignore", category=SourceChangeWarning)
```
---
### **最终验证**
若上述步骤均未解决,请提供以下信息:
1. 执行路径验证代码的输出结果
2. 视频文件的详细编码信息(可通过MediaInfo工具获取)
3. 操作系统和Python环境版本
请按步骤排查后反馈结果,我会进一步协助! 🚀
阅读全文
相关推荐



















