davanstrien HF Staff commited on
Commit
b5861ea
·
1 Parent(s): 85c3e70

Enhance input processing by moving tensors to the model's device and converting to the appropriate dtype

Browse files
Files changed (1) hide show
  1. detect-objects.py +9 -1
detect-objects.py CHANGED
@@ -233,7 +233,15 @@ def process_batch(
233
  images=pil_images,
234
  text=class_names, # All class names as prompts
235
  return_tensors="pt",
236
- ).to(model.device)
 
 
 
 
 
 
 
 
237
 
238
  with torch.no_grad():
239
  outputs = model(**inputs)
 
233
  images=pil_images,
234
  text=class_names, # All class names as prompts
235
  return_tensors="pt",
236
+ )
237
+ # Move to device and convert to model's dtype
238
+ inputs = {
239
+ k: v.to(
240
+ model.device,
241
+ dtype=model.dtype if v.dtype.is_floating_point else v.dtype,
242
+ )
243
+ for k, v in inputs.items()
244
+ }
245
 
246
  with torch.no_grad():
247
  outputs = model(**inputs)