yifehuang97 commited on
Commit
27de4bf
·
verified ·
1 Parent(s): 165f1b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -211,9 +211,7 @@ def count_objects(image, pos_caption, neg_caption, box_threshold, point_radius,
211
 
212
 
213
  if use_neg:
214
- print('neg_caption: ', neg_caption)
215
- if neg_caption is None:
216
- neg_caption = "None."
217
  neg_inputs = processor(
218
  images=image,
219
  text=neg_caption,
@@ -231,6 +229,22 @@ def count_objects(image, pos_caption, neg_caption, box_threshold, point_radius,
231
  pos_inputs['neg_input_ids'] = neg_inputs['input_ids']
232
  pos_inputs['use_neg'] = True
233
  else:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
234
  pos_inputs['use_neg'] = False
235
 
236
  # Run inference
 
211
 
212
 
213
  if use_neg:
214
+ # print('neg_caption: ', neg_caption)
 
 
215
  neg_inputs = processor(
216
  images=image,
217
  text=neg_caption,
 
229
  pos_inputs['neg_input_ids'] = neg_inputs['input_ids']
230
  pos_inputs['use_neg'] = True
231
  else:
232
+ neg_caption = "None."
233
+ neg_inputs = processor(
234
+ images=image,
235
+ text=neg_caption,
236
+ return_tensors="pt",
237
+ padding=True
238
+ )
239
+ neg_inputs = {k: v.to(device) for k, v in neg_inputs.items()}
240
+ neg_inputs['pixel_values'] = neg_inputs['pixel_values'].to(torch.bfloat16)
241
+
242
+ # Add negative inputs to positive inputs dict
243
+ pos_inputs['neg_token_type_ids'] = neg_inputs['token_type_ids']
244
+ pos_inputs['neg_attention_mask'] = neg_inputs['attention_mask']
245
+ pos_inputs['neg_pixel_mask'] = neg_inputs['pixel_mask']
246
+ pos_inputs['neg_pixel_values'] = neg_inputs['pixel_values']
247
+ pos_inputs['neg_input_ids'] = neg_inputs['input_ids']
248
  pos_inputs['use_neg'] = False
249
 
250
  # Run inference