Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用llava论文提供的数据集进行训练报错“The number of images does not match the number of image tokens” #5883

Closed
1 task done
wwwbq opened this issue Oct 31, 2024 · 2 comments · Fixed by #5909
Labels
solved This problem has been already solved

Comments

@wwwbq
Copy link

wwwbq commented Oct 31, 2024

Reminder

  • I have read the README and searched the existing issues.

System Info

llamafactory 0.9.1.dev0

Reproduction

使用llava官方提供的数据集去sft llava模型

Expected behavior

看了一下相关代码,问题应该是出在数据集格式,llava论文里使用的数据集中,image的路径是按字符串给的,例如在json中,image字段可能是"test1.jpg",因此在处理图片数据时,读取到的图片路径是字符串,而我使用的llamafactory版本中,提供的mllm demo数据集里的image字段是列表,例如“[test1.jpg]”,因此读取到的图片路径是列表。最终在LlavaPlugin.process_messages方法中进行 “if len(images) != num_image_tokens” 判断时,如果只有一张图片,num_image_tokens为1,而image字段是list时,len(images)也为1,若image字段是字符串,则len(images)为 “test1.jpg”这个字符串的长度,最终报错。

不知道是否需要更新llamafactory最新版本

Others

No response

@github-actions github-actions bot added the pending This problem is yet to be addressed label Oct 31, 2024
@wwwbq
Copy link
Author

wwwbq commented Oct 31, 2024

改的话应该还蛮简单的,检查一下image是不是字符串,是的话就转成列表。
其实可以的话我还想建议一下,能不能在data_args里加一个image_foder字段,用来读取数据集中图片的路径。因为有时候图片可能占用空间比较多,会和json文件分离而单独放在另外的盘里,但是数据集中image字段里图片路径都是相对路径,如果就在这个函数这里,处理图片的时候把图片的路径改成data_args.image_foder + json["image"][i]这样会稍微方便一点
test

@Dr-jw
Copy link

Dr-jw commented Nov 1, 2024

我也遇到了这个问题,请问有解决方法了吗?

@hiyouga hiyouga added the enhancement New feature or request label Nov 1, 2024
@hiyouga hiyouga added solved This problem has been already solved and removed enhancement New feature or request pending This problem is yet to be addressed labels Nov 2, 2024
@hiyouga hiyouga closed this as completed in 24da9f5 Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solved This problem has been already solved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants