--- base_model: - nvidia/LocateAnything-3B pipeline_tag: object-detection library_name: transformers tags: - locateanything, --- # LocateAnything Full reimplementation of for compatibility with `transformers>=5` Example code: ```py import argparse from pathlib import Path import torch from PIL import Image from transformers import AutoModel, AutoProcessor repo_id = 'SD-Next/LocateAnything-3B' parser = argparse.ArgumentParser() parser.add_argument("--image", required=True, type=Path) parser.add_argument("--prompt", required=True) args = parser.parse_args() processor = AutoProcessor.from_pretrained(repo_id, trust_remote_code=True) model = AutoModel.from_pretrained(repo_id, trust_remote_code=True, torch_dtype="auto", device_map="auto").eval() image = Image.open(args.image).convert("RGB") messages = [{"role": "user", "content": [ {"type": "image", "image": image}, {"type": "text", "text": args.prompt} ]}] text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) inputs = processor(images=image, text=text, return_tensors="pt").to(model.device) with torch.inference_mode(): output = model.generate(**inputs, max_new_tokens=128, do_sample=False) decoded = processor.batch_decode(output[:, inputs["input_ids"].shape[1]:], skip_special_tokens=False) print(decoded[0]) ``` Example output: > python test-locateanything.py --image samples/cartoon.png --prompt "locate hands and face" ```xml hands' <312><754><357><888> <568><778><623><917> face <438><81><536><255> <|im_end|> ```