Skip to main content

Client utilities for Neuromeka VFM FoundationPose RPC (upload meshes, call server)

Project description

neuromeka_vfm

A lightweight client SDK for communicating with Segmentation (SAM2, Grounding DINO) and Pose Estimation (NVIDIA FoundationPose) servers over RPC/ZeroMQ. It also provides SSH/SFTP utilities to upload mesh files to the host.

Installation

pip install neuromeka_vfm

Python API (usage by example)

  • Client PC: the machine running your application with this package installed.
  • Host PC: the machine running Segmentation and Pose Estimation Docker servers. If you run Docker locally, use localhost.

Segmentation

from neuromeka_vfm import Segmentation

seg = Segmentation(
    hostname="192.168.10.63",
    port=5432,
    compression_strategy="png",    # none | png | jpeg | h264
)

# Register using an image prompt
seg.add_image_prompt("drug_box", ref_rgb)
seg.register_first_frame(
    frame=first_rgb,
    prompt="drug_box",     # ID string
    use_image_prompt=True,
)

# Register using a text prompt
seg.register_first_frame(
    frame=first_rgb,
    prompt="box .",         # Text prompt (must end with " .")
    use_image_prompt=False,
)

# SAM2 tracking on the registered mask(s)
resp = seg.get_next(next_rgb)
if isinstance(resp, dict) and resp.get("result") == "ERROR":
    print(f"Tracking error: {resp.get('message')}")
    seg.reset()
else:
    masks = resp

# Segmentation settings / model selection (nrmk_realtime_segmentation v0.2+)
caps = seg.get_capabilities()["data"]
current = seg.get_config()["data"]
seg.set_config(
    {
        "grounding_dino": {
            "backbone": "Swin-B",        # Swin-T | Swin-B
            "box_threshold": 0.35,
            "text_threshold": 0.25,
        },
        "dino_detection": {
            "threshold": 0.5,
            "target_multiplier": 25,
            "img_multiplier": 50,
            "background_threshold": -1.0,
            "final_erosion_count": 10,
            "segment_min_size": 20,
        },
        "sam2": {
            "model": "facebook/sam2.1-hiera-large",
            "use_legacy": False,
            "compile": False,
            "offload_state_to_cpu": False,
            "offload_video_to_cpu": False,
        },
    }
)

# Remove an object (v0.2+, only when use_legacy=False)
seg.remove_object("cup_0")

seg.close()

Additional Segmentation APIs and behaviors

  • benchmark=True in the constructor enables timing counters (call_time, call_count) for add_image_prompt, register_first_frame, and get_next.
  • switch_compression_strategy() lets you change the compression strategy at runtime.
  • register_first_frame() returns True/False and raises ValueError if image prompts are missing when use_image_prompt=True.
  • register_first_frame() accepts a list of prompt IDs when use_image_prompt=True.
  • get_next() returns None if called before registration; it can also return the server error dict when available.
  • reset() performs a server-side reset, while finish() clears only local state.
  • Exposed state: tracking_object_ids, current_frame_masks, invisible_object_ids.
  • Backward-compat alias: NrmkRealtimeSegmentation.

Segmentation v0.2 config summary (defaults/choices)

seg.get_capabilities() can differ depending on server configuration. The following reflects v0.2 defaults.

grounding_dino:
  backbone:
    choices:
      - Swin-B
      - Swin-T
    default: Swin-T
  box_threshold:
    default: 0.35
    min: 0.0
    max: 1.0
  text_threshold:
    default: 0.25
    min: 0.0
    max: 1.0

dino_detection:
  threshold:
    default: 0.5
  target_multiplier:
    default: 25
  img_multiplier:
    default: 50
  background_threshold:
    default: -1.0
  final_erosion_count:
    default: 10
  segment_min_size:
    default: 20

sam2:
  model:
    choices:
      - facebook/sam2-hiera-base-plus
      - facebook/sam2-hiera-large
      - facebook/sam2-hiera-small
      - facebook/sam2-hiera-tiny
      - facebook/sam2.1-hiera-base-plus
      - facebook/sam2.1-hiera-large
      - facebook/sam2.1-hiera-small
      - facebook/sam2.1-hiera-tiny
    default: facebook/sam2.1-hiera-large
  use_legacy:
    default: false
  compile:
    default: false
  offload_state_to_cpu:
    default: false
  offload_video_to_cpu:
    default: false

Segmentation v0.2 notes and changes

  • If SAM2 VRAM estimation fails, seg.get_next() may return {"result":"ERROR"}. Handle the error and call reset before re-registering.
  • compile=True can slow down first-frame registration and reset.
  • CPU offloading is most effective when both offload_state_to_cpu=True and offload_video_to_cpu=True are set (legacy mode does not support offload_video_to_cpu).
  • remove_object is supported only when use_legacy=False.
  • GroundingDINO added the Swin-B backbone and fixed prompt-token merge issues.

Pose Estimation

Mesh upload: Upload the mesh file (STL) to /opt/meshes/ on the host PC. You can also use SSH directly.

from neuromeka_vfm import upload_mesh

upload_mesh(
    host="192.168.10.63",
    user="user",
    password="pass",
    local="mesh/my_mesh.stl",         # local mesh path
    remote="/opt/meshes/my_mesh.stl", # host mesh path (Docker volume)
)

Initialization

from neuromeka_vfm import PoseEstimation

pose = PoseEstimation(host="192.168.10.72", port=5557)

pose.init(
    mesh_path="/app/modules/foundation_pose/mesh/my_mesh.stl",
    apply_scale=1.0,
    track_refine_iter=3,
    min_n_views=40,
    inplane_step=60,
)
  • mesh_path: path to the mesh file (STL/OBJ). Initialization fails if missing.
  • apply_scale: scalar applied after loading the mesh.
    • STL in meters: 1.0 (no scaling)
    • STL in centimeters: 0.01 (1 cm -> 0.01 m)
    • STL in millimeters: 0.001 (1 mm -> 0.001 m)
  • force_apply_color: if True, forces a solid color when the mesh lacks color data.
  • apply_color: RGB tuple (0-255) used when force_apply_color=True.
  • est_refine_iter: number of refinement iterations during registration (higher = more accurate, slower).
  • track_refine_iter: number of refinement iterations per frame during tracking.
  • min_n_views: minimum number of sampled camera views (affects rotation candidates).
  • inplane_step: in-plane rotation step in degrees (smaller = more candidates).

Registration and tracking

# Registration (server defaults when iteration is omitted, check_vram=True pre-checks VRAM)
register_resp = pose.register(rgb=rgb0, depth=depth0, mask=mask0, K=cam_K, check_vram=True)

# Tracking (optionally limit search area with bbox_xywh)
track_resp = pose.track(rgb=rgb1, depth=depth1, K=cam_K, bbox_xywh=bbox_xywh)

pose.close()
  • cam_K: camera intrinsics.
  • Large RGB resolution, large min_n_views, or small inplane_step can cause GPU VRAM errors.
  • check_vram=True in register performs a pre-check to prevent server shutdown due to OOM.
  • iteration in register/track can override the server default if provided.
  • reset() resets the server state; reset_object() reuses the cached mesh to rebuild the rotation grid.
  • Default host/port can come from FPOSE_HOST and FPOSE_PORT environment variables.
  • Backward-compat alias: FoundationPoseClient.

Release notes

  • 0.1.2: Improved success detection for Segmentation responses (result/success/status), fixed image prompt registration/usage, added check_vram to PoseEstimation register.
  • 0.1.1: Improved resource cleanup in PoseEstimation/Segmentation, use server defaults when iteration is omitted, added pose demo example.
  • 0.1.0: Initial public release. Includes FoundationPose RPC client, real-time segmentation client, SSH-based mesh upload CLI/API.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neuromeka_vfm-0.1.6.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

neuromeka_vfm-0.1.6-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file neuromeka_vfm-0.1.6.tar.gz.

File metadata

  • Download URL: neuromeka_vfm-0.1.6.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for neuromeka_vfm-0.1.6.tar.gz
Algorithm Hash digest
SHA256 94db55d9b3b2d332b9bc0a0aa64a2f9d6e6b68f0829dbf11fd72ea9b7294a469
MD5 7b1d516a8f7039b938ea37dd03b8640a
BLAKE2b-256 4acc1f29a5d73b501bb9ef34ee3d3db475d9e64ddc9d26794cf4c64fad129c8e

See more details on using hashes here.

File details

Details for the file neuromeka_vfm-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: neuromeka_vfm-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for neuromeka_vfm-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a25f798ee1cd306ca47ba324b919c8c02962bf1112dc3105e0606e31850db9f5
MD5 f2a5ca8c11ece1034567cf217d25d241
BLAKE2b-256 f9ec7f29c7d782146914691e6099fd529daf01cdb2f43abecf25224724a9c7dd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page