当前位置: 首页 > news >正文

【脏数据 bug 解决】ValueError: mean must have 1 elements if it is an iterable, got 3

问题描述:

  1. 在训练模型的过程中,出现 clip_image_processor 无法处理数据的问题,说明数据集中很可能出现了脏数据。
  2. 本文使用的数据为 LAION-Aesthetics-V2-6.5plus,从 https://dagshub.com/DagsHub-Datasets/LAION-Aesthetics-V2-6.5plus 上下载的。
Traceback (most recent call last):
...File "/xxx/check_train_data.py", line 69, in __getitem__raise e  # Re-raise the exception to halt the training process^^^^^^^File "/xxx/check_train_data.py", line 64, in __getitem__clip_image = self.clip_image_processor(images=raw_image, return_tensors="pt").pixel_values^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "/xxx/lib/python3.12/site-packages/transformers/image_processing_utils.py", line 41, in __call__return self.preprocess(images, **kwargs)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "/xxx/lib/python3.12/site-packages/transformers/models/clip/image_processing_clip.py", line 341, in preprocessself.normalize(image=image, mean=image_mean, std=image_std, input_data_format=input_data_format)File "/xxx/lib/python3.12/site-packages/transformers/image_processing_utils.py", line 111, in normalizereturn normalize(^^^^^^^^^^File "/xxx/lib/python3.12/site-packages/transformers/image_transforms.py", line 392, in normalizeraise ValueError(f"mean must have {num_channels} elements if it is an iterable, got {len(mean)}")
ValueError: mean must have 1 elements if it is an iterable, got 3

解决方案:

  1. 将原代码的 clip_image = self.clip_image_processor 修改为 try、except 来找到导致报错的图片。
  2. 将加载数据的代码部分拎出,并遍历一遍。
 # read imageraw_image = Image.open(os.path.join(self.image_root_path, image_file))image = self.transform(raw_image.convert("RGB"))# clip_image = self.clip_image_processor(images=raw_image, return_tensors="pt").pixel_valuestry:clip_image = self.clip_image_processor(images=raw_image, return_tensors="pt").pixel_valuesprint(f'image_file_{idx} processed with clip_image_processor: {image_file}')except Exception as e:print(f'Error processing image_file_{idx}: {image_file}')print(e)raise e  # Re-raise the exception to halt the training process
  1. 最终卡在 4235 附近的图片,通过肉眼观察,发现 4236 是图片空的😂
  2. 手动删除 4236 图片以及对应的 json 文本后便可正常训练!🏋️
    在这里插入图片描述
http://www.lryc.cn/news/429489.html

相关文章:

  • 【Vue3】集成 Ant Design Vue
  • 如何处理前端项目中的SEO优化:从SPA到SSR与SSG
  • 【UE5】Groom毛发系统的基本使用——给小白人添加头发
  • DataWorks函数
  • 设计模式学习优质网站分享:refactoring.guru
  • JVM-Java的四种引用
  • 探索《黑神话:悟空》品质保障的背后:ISO体系认证
  • ArcGIS Pro 实现人口分布栅格TIFF数据的网格提取与可视化
  • select的缺点;poll ;poll的缺点;epoll
  • keli5_报错 Cannot Load Device Description问题
  • 算法的学习笔记—把二叉树打印成多行(牛客JZ78)
  • FreeRTOS 时间管理
  • F. Valuable Cards D. Smithing Skill
  • 【电子通识】IPC-A-600中对验收标准的定义
  • MyBatis(初阶)
  • KDP数据平台:以实战案例验证技术领先力
  • [Linux] 什么是 Shell?
  • 大模型学习应用 2:快速上手大模型基于langchain实现RAG检索应用
  • python环境安装之后,cmd输入python回车会打开微软商店
  • USB Type-C如何取9V、12V、15V、20V电压-PD快充协议芯片ECP5701
  • Go 语言 Map 17
  • 移植bash到openharmony
  • git stash详细教程
  • UDP网络攻击
  • 漏洞扫描的重要性,如何做好漏洞扫描服务
  • unity程序简易框架
  • Go小技巧易错点100例(十六)
  • 通过Golang实现中间人攻击,查看和修改https流量包
  • MySQL 安装与配置指南
  • android13布局查看工具 无源码查看布局 在线查找ui布局id