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/_probe_stackcan_plate_v2.py from hchen657Naza/PWM: direct link, hf CLI and curl.
- Browser
- Download file 2.27 kB
-
https://huggingface.co/hchen657Naza/PWM/resolve/main/PWM_code/reward_model/scripts/_probe_stackcan_plate_v2.py
- Command line
-
hf download hf://hchen657Naza/PWM/PWM_code/reward_model/scripts/_probe_stackcan_plate_v2.py
-
curl -L -o _probe_stackcan_plate_v2.py https://huggingface.co/hchen657Naza/PWM/resolve/main/PWM_code/reward_model/scripts/_probe_stackcan_plate_v2.py
2.27 kB
| #!/usr/bin/env python3 | |
| """Probe NEW plate prompts on the can-only Stack-Can demos (plate previously missed). | |
| For each (prompt), report how many of the probed demos it detects at ANY anchor.""" | |
| 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 | |
| ROOT = "/home/hongyi/PWM/external/DiffSynth-Studio/data/robot_new/Stack-Can" | |
| # subset of the 34 can-only demos (representative) | |
| DEMOS = ["ep002","ep007","ep010","ep011","ep012","ep018","ep019","ep020", | |
| "ep031","ep042","ep061","ep073","ep080","ep091","ep092"] | |
| PROMPTS = ["white round plate","round plate","white dish","dish","white disc", | |
| "white circle","ceramic plate","dinner plate","white bowl","saucer", | |
| "plate on the table","white object on the table","empty plate","white tray"] | |
| ANCHORS = [0,16,32,48] | |
| OUT="/tmp/stackcan_plate_v2"; os.makedirs(OUT, exist_ok=True) | |
| 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) | |
| def ground(frames, anchor, prompt): | |
| clip=frames[anchor:anchor+16] | |
| if len(clip)<4: return -1 | |
| tmp=os.path.join(OUT,"clip.mp4"); imageio.mimwrite(tmp, clip, fps=15, macro_block_size=1) | |
| m,n=sam3_propagate(pred, tmp, prompt) | |
| return 0 if m is None else int(np.asarray(m[0]).sum()) | |
| # cache squashed frames per demo | |
| frames_cache={} | |
| for d in DEMOS: | |
| fr=[cv2.resize(f,(384,384),interpolation=cv2.INTER_AREA) for f in load_video(f"{ROOT}/tableHF_{d}.mp4",None)] | |
| frames_cache[d]=fr | |
| hits={p:[] for p in PROMPTS} # demos detected (at any anchor) | |
| for p in PROMPTS: | |
| for d in DEMOS: | |
| fr=frames_cache[d] | |
| best=max((ground(fr,a,p) for a in ANCHORS if a<len(fr)), default=0) | |
| if best>50: | |
| hits[p].append(d) | |
| print(f"{p!r:32s} -> {len(hits[p])}/{len(DEMOS)} demos {hits[p]}", flush=True) | |
| print("\n=== ranking (most demos recovered) ===", flush=True) | |
| for p,h in sorted(hits.items(), key=lambda kv:-len(kv[1])): | |
| print(f" {len(h):2d}/{len(DEMOS)} {p!r}", flush=True) | |