teowu commited on
Commit
45d5056
1 Parent(s): 3d347a9

Upload modeling_mplug_owl2.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. modeling_mplug_owl2.py +2 -1
modeling_mplug_owl2.py CHANGED
@@ -261,7 +261,6 @@ class MPLUGOwl2LlamaForCausalLM(LlamaForCausalLM, MPLUGOwl2MetaForCausalLM):
261
  # Initialize weights and apply final processing
262
  self.post_init()
263
 
264
- self.weight_tensor = torch.Tensor([5.,4.,3.,2.,1.]).half().to(self.device)
265
 
266
  def get_model(self):
267
  return self.model
@@ -270,6 +269,8 @@ class MPLUGOwl2LlamaForCausalLM(LlamaForCausalLM, MPLUGOwl2MetaForCausalLM):
270
  task_: str = "quality",
271
  input_: str = "image",
272
  ):
 
 
273
  prompt = "USER: How would you rate the {} of this {}?\n<|image|>\nASSISTANT: The {} of the {} is".format(task_, input_, input_, task_)
274
  if input_ == "image":
275
  images = [expand2square(img, tuple(int(x*255) for x in self.image_processor.image_mean)) for img in images]
 
261
  # Initialize weights and apply final processing
262
  self.post_init()
263
 
 
264
 
265
  def get_model(self):
266
  return self.model
 
269
  task_: str = "quality",
270
  input_: str = "image",
271
  ):
272
+ if not hasattr(self, "weight_tensor"):
273
+ self.weight_tensor = torch.Tensor([5.,4.,3.,2.,1.]).half().to(self.device)
274
  prompt = "USER: How would you rate the {} of this {}?\n<|image|>\nASSISTANT: The {} of the {} is".format(task_, input_, input_, task_)
275
  if input_ == "image":
276
  images = [expand2square(img, tuple(int(x*255) for x in self.image_processor.image_mean)) for img in images]