程序源码如下:
from transformers import Blip2ForConditionalGeneration, AutoTokenizer, AutoProcessor
model_name='model/Salesforce_blip2-opt-2.7b'
model = Blip2ForConditionalGeneration.from_pretrained(model_name)
processor = AutoProcessor.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
model.eval()
# 评估循环
for batch in dataloader:
images, reports, _ = batch
images = images.to(device)
# 使用processor处理输入
inputs = processor(images=images, text=reports, padding=True, truncation=True, return_tensors="pt").to(device)
# 前向传播
with torch.no_grad():
outputs = model.generate(**inputs)
以上程序执行后错误如下:
outputs = model.generate(**inputs)
File "D:\anaconda3\envs\llava\lib\site-packages\peft\peft_model.py", line 647, in generate
return self.get_base_model().generate(args, **kwargs)
File "D:\anaconda3\envs\llava\lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context
return func(args, **kwargs)
File "D:\anaconda3\envs\llava\lib\site-packages\transformers\models\blip_2\modeling_blip_2.py", line 2316, in generate
inputs_embeds[special_image_mask] = language_model_inputs.flatten()
RuntimeError: shape mismatch: value tensor of shape [2621440] cannot be broadcast to indexing result of shape [0]
哪位大牛能给解释一下这是怎么回事呀?谢谢!
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。