Instructions to use hchen657Naza/PWM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use hchen657Naza/PWM with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("hchen657Naza/PWM", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Download PWM_code/reward_model/scripts/archive/_probe_stackcan_prompts.py from hchen657Naza/PWM: direct link, hf CLI and curl.
- Browser
- Download file 1.92 kB
-
https://huggingface.co/hchen657Naza/PWM/resolve/main/PWM_code/reward_model/scripts/archive/_probe_stackcan_prompts.py
- Command line
-
hf download hf://hchen657Naza/PWM/PWM_code/reward_model/scripts/archive/_probe_stackcan_prompts.py
-
curl -L -o _probe_stackcan_prompts.py https://huggingface.co/hchen657Naza/PWM/resolve/main/PWM_code/reward_model/scripts/archive/_probe_stackcan_prompts.py
1.92 kB
| #!/usr/bin/env python3 | |
| """Probe which SAM3 text prompts detect the Stack-Can objects at 384x384. | |
| Loads SAM3 once, squashes ep000 to 384, tries a list of prompts on a short clip, | |
| prints #objects + #mask px, and dumps a frame-0 mask overlay png per prompt.""" | |
| import sys, os | |
| from pathlib import Path | |
| import numpy as np, cv2, imageio | |
| sys.path.insert(0, "/home/hongyi/PWM/external") | |
| import sam3.model_builder as _mb | |
| from sam3.model_builder import build_sam3_video_predictor | |
| from track_objects_in_video import load_video, sam3_propagate | |
| VID = "/home/hongyi/PWM/external/DiffSynth-Studio/data/robot_new/Stack-Can/tableHF_ep000.mp4" | |
| OUT = "/tmp/stackcan_probe"; os.makedirs(OUT, exist_ok=True) | |
| PROMPTS = ["Green cup", "green cup", "cup", "mug", "White plate on the table", | |
| "white plate", "plate", "red can", "orange can", "can", "soda can", | |
| "tin can", "red object", "the object on the table"] | |
| frames = [cv2.resize(f, (384, 384), interpolation=cv2.INTER_AREA) for f in load_video(VID, None)] | |
| clip = frames[:16] | |
| tmp = os.path.join(OUT, "clip.mp4"); imageio.mimwrite(tmp, clip, fps=15, macro_block_size=1) | |
| imageio.imwrite(os.path.join(OUT, "frame0.png"), frames[0]) | |
| bpe = str(Path(_mb.__file__).parent / "assets" / "bpe_simple_vocab_16e6.txt.gz") | |
| pred = build_sam3_video_predictor(bpe_path=bpe, gpus_to_use=[0], apply_temporal_disambiguation=False) | |
| for p in PROMPTS: | |
| masks, n = sam3_propagate(pred, tmp, p) | |
| if masks is None: | |
| print(f" {p!r:40s} -> NONE", flush=True); continue | |
| m0 = masks[0] | |
| px = int(np.asarray(m0).sum()) | |
| print(f" {p!r:40s} -> n_obj={n} frame0_px={px}", flush=True) | |
| ov = frames[0].copy() | |
| mm = np.asarray(m0).astype(bool) | |
| if mm.ndim == 2 and mm.any(): | |
| ov[mm] = (0.5 * ov[mm] + np.array([0, 0, 255]) * 0.5).astype(np.uint8) | |
| imageio.imwrite(os.path.join(OUT, f"mask_{p.replace(' ','_')}.png"), ov) | |
| print("done ->", OUT, flush=True) | |