当前位置: 首页 > 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.mrgr.cn/news/9648.html

相关文章:

  • 第134天:内网安全-横向移动NTLM-Relay重放Responder中继攻击LdapEws
  • 示波器输出的csv文件如何转换为频谱图及其excel表格(频率与幅值)
  • msxml*.dll 错误 ‘80072f7d‘ 安全频道支持出错 解决方案
  • MySQL 用户与权限管理详解
  • LVS+Keepalived集群(主、备)
  • 您的多个密码是否被泄露有没有解决方法?
  • 《系统架构设计师教程(第2版)》第15章-面向服务架构设计理论与实践-04-SOA设计
  • XML CSS:结构和样式的完美结合
  • Leetcode-day28-贪心算法
  • iPhone 16系列详细参数曝光
  • 【代码随想录训练营第42期 Day37打卡 - 动态规划Part5 - 完全背包问题
  • HDU1753——大明A+B,HDU1115——Lifting the Stone,HDU1140——War on Weather
  • 【单片机】PIC16F1719 单片机,UART,串口发送
  • 汽车冷却液温度传感器
  • “我王多鱼投了!”疯狂烧钱的AI大模型公司如何赚钱?
  • 【CSS】使用 CSS 自定义属性(变量)-- var()
  • “论软件体系结构的演化”写作框架,软考高级,系统架构设计师
  • Mac常用快捷键
  • Docker 学习
  • 数据库,SQL语句