Views
No views yet
1from PIL import Image
2from transformers import AutoModelForCausalLM, AutoProcessor, GenerationConfig
3
4img = Image.open("<path_to_image>")
5task = "Pour coffee from the blue mug."
6
7processor = AutoProcessor.from_pretrained("allenai/GraspMolmo", torch_dtype="auto", device_map="auto", trust_remote_code=True)
8model = AutoModelForCausalLM.from_pretrained("allenai/GraspMolmo", torch_dtype="auto", device_map="auto", trust_remote_code=True)
9
10prompt = f"Point to the grasp that would accomplish the following task: {task}"
11inputs = processor.process(images=img, text=prompt, return_tensors="pt")
12inputs = {k: v.to(model.device).unsqueeze(0) for k, v in inputs.items()}
13
14output = model.generate_from_batch(inputs, GenerationConfig(max_new_tokens=256, stop_strings="<|endoftext|>"), tokenizer=processor.tokenizer)
15generated_tokens = output[0, inputs["input_ids"].size(1):]
16generated_text = processor.tokenizer.decode(generated_tokens, skip_special_tokens=True)
17print(generated_text)In order to accomplish the task "Pour coffee from the blue mug.", the optimal grasp is described as follows: "The grasp is on the middle handle of the blue mug, with fingers grasping the sides of the handle.".
<point x="28.6" y="20.7" alt="Where to grasp the object">Where to grasp the object</point>graspmolmo withpip install "git+https://github.com/abhaybd/GraspMolmo.git#egg=graspmolmo[infer]"1from graspmolmo.inference.grasp_predictor import GraspMolmo
2
3task = "..."
4rgb, depth = get_image()
5camera_intrinsics = np.array(...)
6
7point_cloud = backproject(rgb, depth, camera_intrinsics)
8# grasps are in the camera reference frame
9grasps = predict_grasps(point_cloud) # Using your favorite grasp predictor (e.g. M2T2)
10
11gm = GraspMolmo()
12idx = gm.pred_grasp(rgb, point_cloud, task, grasps)
13
14print(f"Predicted grasp: {grasps[idx]}")