ClipCap-Chinese
ClipCap-Chinese copied to clipboard
AttributeError: type object 'GPT2LMHeadModel' has no attribute 'from_config'
raceback (most recent call last):
File "ClipCap-Chinese-master/models/model.py", line 75, in init
self.gpt2 = GPT2LMHeadModel.from_pretrained(gpt2_path)
File "/root/miniconda3/lib/python3.8/site-packages/transformers/modeling_utils.py", line 1222, in from_pretrained
raise EnvironmentError(
OSError: Error no file named ['pytorch_model.bin', 'tf_model.h5', 'model.ckpt.index', 'flax_model.msgpack'] found in directory pretrain_models/gpt2 or from_tf
and from_flax
set to False.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/ClipCap-Chinese-master/train.py", line 150, in
可直接修改为加载GPT2LMHeadModel.from_pretrained("uer/gpt2-chinese-cluecorpussmall") 然后下载对应的模型文件 https://huggingface.co/uer/gpt2-chinese-cluecorpussmall/tree/main
一般就是数据和模型一个在cpu,一个在GPU RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu 方法一: args.device = torch.device("cpu")
方法二: 将数据加载到GPU上 images = images.to(args.device) clip_embeds = clip_model.encode_image(images) # clip_embeds = clip_embeds.unsqueeze(1).repeat(1, args.num_generate, 1).view(-1, clip_embeds.size(-1)) clip_embeds = clip_embeds.unsqueeze(1).repeat(1, args.num_generate, 1).view(-1, clip_embeds.size(-1)).float()
顶,好帖子,谢谢楼主