H4nwei commited on
Commit
d56984d
1 Parent(s): e1786ff

Update modeling_mplug_owl2.py

Browse files
Files changed (1) hide show
  1. modeling_mplug_owl2.py +4 -4
modeling_mplug_owl2.py CHANGED
@@ -93,7 +93,7 @@ def optimize_score_map_pytorch_cuda(c, seed=0, original_seed=20020, num_iteratio
93
 
94
  for _ in range(num_iterations):
95
  optimizer.zero_grad()
96
- sum_log_diff = torch.sum(c * torch.log(torch.maximum(torch.sigmoid(initial_scores[:, None] - initial_scores), torch.tensor(1e-6, device=device))))
97
  sum_squares = torch.sum(initial_scores ** 2) / 2
98
 
99
  loss = -(sum_log_diff - sum_squares)
@@ -108,7 +108,7 @@ def optimize_score_map_pytorch_cuda(c, seed=0, original_seed=20020, num_iteratio
108
 
109
  # Reset the seed
110
  np.random.seed(original_seed)
111
- return scaled_scores[-1]
112
 
113
  def softmax(logits):
114
  # exp_logits = np.exp(logits - np.max(logits))
@@ -343,7 +343,7 @@ class MPLUGOwl2LlamaForCausalLM(LlamaForCausalLM, MPLUGOwl2MetaForCausalLM):
343
  return self.download_image(path)
344
  return Image.open(path).convert('RGB')
345
 
346
- def score(self, image_path):
347
  prompt = "USER: <|image|> <|image|> Compared with the first image, what is your quality rating for second image? \nASSISTANT: The quality of the second image is"
348
  input_ids = tokenizer_image_token(prompt, self.tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').unsqueeze(0).to(self.device)
349
 
@@ -352,7 +352,7 @@ class MPLUGOwl2LlamaForCausalLM(LlamaForCausalLM, MPLUGOwl2MetaForCausalLM):
352
  probabilities = []
353
  for index in self.anchor_indices:
354
  anchor_image = anchor_images[index]
355
- image = self.load_image(image_path)
356
  images = [anchor_image, image]
357
  images = [expand2square(img, tuple(int(x*255) for x in self.image_processor.image_mean)) for img in images]
358
  image_tensor = self.image_processor.preprocess(images, return_tensors='pt')['pixel_values'].half().to(self.device)
 
93
 
94
  for _ in range(num_iterations):
95
  optimizer.zero_grad()
96
+ sum_log_diff = torch.sum(c * torch.log(torch.maximum(norm_cdf(initial_scores[:, None] - initial_scores), torch.tensor(1e-6, device=device))))
97
  sum_squares = torch.sum(initial_scores ** 2) / 2
98
 
99
  loss = -(sum_log_diff - sum_squares)
 
108
 
109
  # Reset the seed
110
  np.random.seed(original_seed)
111
+ return torch.tensor(scaled_scores[-1], device=device)
112
 
113
  def softmax(logits):
114
  # exp_logits = np.exp(logits - np.max(logits))
 
343
  return self.download_image(path)
344
  return Image.open(path).convert('RGB')
345
 
346
+ def score(self, image):
347
  prompt = "USER: <|image|> <|image|> Compared with the first image, what is your quality rating for second image? \nASSISTANT: The quality of the second image is"
348
  input_ids = tokenizer_image_token(prompt, self.tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').unsqueeze(0).to(self.device)
349
 
 
352
  probabilities = []
353
  for index in self.anchor_indices:
354
  anchor_image = anchor_images[index]
355
+ # image = self.load_image(image_path)
356
  images = [anchor_image, image]
357
  images = [expand2square(img, tuple(int(x*255) for x in self.image_processor.image_mean)) for img in images]
358
  image_tensor = self.image_processor.preprocess(images, return_tensors='pt')['pixel_values'].half().to(self.device)