classification / explanation.txt
Silly98's picture
Upload 9 files
da6986a verified
Raw
History Blame Contribute Delete
8.4 kB
HEG BRep Component Identifier β€” integration brief
What it is
A self-contained Windows folder (~2.1 GB unpacked) that runs an ML classifier for STEP-format CAD parts. Given a STEP file path, it returns a component label (elbow, tee, pipe, miscellaneous, plus a subtype for elbows/tees).
It is not a DLL. It's a local HTTP service that runs as a child process of our viewer. The classifier is a PyTorch model behind a FastAPI server. The whole Python stack β€” interpreter, OCC kernel, torch, model weights β€” is bundled inside the folder. No Python install required on the user's machine.
Architecture
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Our C# 3D Viewer β”‚ spawn child + stdout β”‚ heg_brep_service.bat β”‚
β”‚ (parent process) β”‚ ───────────────────────► β”‚ (our launcher) β”‚
β”‚ β”‚ β”‚ └─► python.exe β”‚
β”‚ On viewer startup: β”‚ read line: β”‚ └─► FastAPI server β”‚
β”‚ - Process.Start(bat) β”‚ ◄───────────────────────│ on 127.0.0.1 β”‚
β”‚ - read "READY port=N" β”‚ "READY port=51571" β”‚ :random_port β”‚
β”‚ β”‚ β”‚ β”‚
β”‚ On user click: β”‚ POST /classify β”‚ Loads models once at β”‚
β”‚ - HttpClient.PostAsync β”‚ ───────────────────────► β”‚ startup. Per-request: β”‚
β”‚ - JSON body β”‚ ◄─────────────────────── β”‚ STEP β†’ OCC features β†’ β”‚
β”‚ {step_path: "..."} β”‚ JSON response β”‚ GNN classifier β†’ JSON β”‚
β”‚ β”‚ β”‚ β”‚
β”‚ On viewer exit: β”‚ POST /shutdown β”‚ β”‚
β”‚ - StopAsync() β”‚ ───────────────────────► β”‚ Graceful exit β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Two key properties:
One process per viewer instance. Service lifetime == viewer lifetime.
Loopback only. Binds to 127.0.0.1, never exposed to the network. No firewall prompts.
The API contract
Endpoint Method Body Returns
/health GET β€” {"status":"ok","models_loaded":true,"device":"cpu","uptime_sec":...}
/classify POST {"step_path":"C:\\full\\path.step"} classification JSON (below)
/classify_batch POST {"step_paths":["...","..."]} {"results":[...]}
/shutdown POST β€” {"status":"shutting_down"} (service exits ~200ms later)
Successful /classify response:
{
"status": "ok",
"final_label": "4_tee_wf",
"final_conf": 0.9997,
"route": "tee",
"pass1_argmax": "tee", "pass1_conf": 1.0,
"pass2_argmax": "4_tee_wf", "pass2_predicted": "4_tee_wf", "pass2_conf": 0.9997,
"step_path": "C:\\...\\part.step",
"npz_path": "C:\\Users\\...\\AppData\\Local\\Temp\\heg_brep_npz_xxx\\part.npz"
}
Error responses (HTTP 200 with an error status field, not HTTP 4xx β€” so the C# code branches on status):
{"step_path": "...", "status": "extraction_failed", "error": "Bodies which are not closed are not supported"}
{"step_path": "...", "status": "inference_failed", "error": "..."}
{"step_path": "...", "status": "error", "error": "step_path not found"}
Label space
Pass-1 (parent classifier): elbow / tee / pipe / miscellaneous
Pass-2 elbow subtypes: 1_elbow_wf / 2_elbow_pef / 3_elbow_sf / 8_elbow_misc
Pass-2 tee subtypes: 4_tee_wf / 5_tee_pef / 6_tee_sf / 9_tee_misc
Pipe / miscellaneous: final_label is random (no specialist for these families). Use pass1_argmax if you need the parent label.
*_wf = welded fitting, *_pef / *_sf = other manufacturing subtypes, *_misc = within-family unclassified.
What you need to implement in C#
There's a working reference client in dist/heg_brep_dist/csharp_sample/ (~150 lines). It targets .NET 6 but works on .NET Framework 4.7.2+ with no changes. Usage:
var client = new HegBrepClient();
// At viewer startup (or lazily on first identify request β€” your call):
await client.StartAsync(@"C:\Program Files\OurViewer\heg_brep\heg_brep_service.bat");
// When the user clicks "Identify component":
var stepPath = await ExportCurrentSelectionToTempStep(); // your existing OCC export
var result = await client.ClassifyAsync(stepPath);
labelControl.Text = $"{result.FinalLabel} ({result.FinalConf:P1})";
// On viewer shutdown:
await client.StopAsync();
The client class handles: spawning the bat, reading the READY port=N line from stdout, posting JSON, parsing responses, graceful shutdown with a Kill fallback.
Performance budget
Measured on a developer laptop (RTX 3050, but service runs on CPU):
Event Cost
Service startup 10–15 s (paid once per viewer launch)
First /classify after startup ~1.0 s
Subsequent /classify calls ~0.8 s (dominated by OCC feature extraction; inference itself is ~50 ms)
For UX, recommend you start the service eagerly at viewer launch (hide behind splash) or lazily on first Identify click (show a "warming up..." spinner for ~10 s).
Failure modes you must handle
Service won't start (heg_brep_service.bat exits before READY line) β†’ log stderr (the client forwards it to Debug.WriteLine), surface error to user, do not retry in a tight loop.
STEP fails extraction ("Bodies which are not closed are not supported" is the most common one β€” Inventor exports sometimes hit this). Branch on status != "ok".
Service hangs / takes too long β€” HegBrepClient has a 60-second timeout. If ClassifyAsync throws TaskCanceledException, the service is wedged. Call StopAsync() and restart.
Service crashes mid-session β€” process exits, next ClassifyAsync will throw a connection error. Recovery: catch, call StartAsync() again, retry once.
A small supervisor that restarts the service on crash (max 3 retries per session) is a reasonable addition.
What's in the bundle
heg_brep_dist/
β”œβ”€β”€ heg_brep_service.bat ← what you Process.Start
β”œβ”€β”€ heg_brep_batch.bat ← offline regression-test tool, irrelevant for the viewer
β”œβ”€β”€ README.txt ← detailed docs
β”œβ”€β”€ python/ ← bundled Python 3.10 env (do not modify)
β”œβ”€β”€ heg_brep/ ← our Python code
β”œβ”€β”€ BRepExtractor/ ← STEPβ†’features pipeline
β”œβ”€β”€ models/ ← 3 model files (~94 MB total)
└── csharp_sample/ ← HegBrepClient.cs + Program.cs (copy into your project)
Installer should drop this whole folder somewhere under the viewer's install dir (e.g. Program Files\OurViewer\heg_brep\) and never modify it. Updates ship as a new folder replacement; viewer code doesn't change.
Constraints / non-goals
Windows x64 only. Linux / macOS / 32-bit not supported.
CPU inference by default. A CUDA variant exists (separate ~2 GB bundle) if customers have NVIDIA GPUs β€” currently not packaged.
STEP input only. Other CAD formats (IGES, JT, native Inventor/SolidWorks) would need a converter layer first.
Single-threaded service. Don't fire concurrent /classify calls from multiple viewer threads β€” they'll serialize anyway. If you need parallelism, queue requests in C#.
Questions to send back
If anything in the contract is unclear, the things most worth raising before coding starts:
Where in the installer layout should heg_brep_dist/ live? That determines the path you pass to StartAsync.
Eager vs. lazy service startup β€” affects splash-screen design.
How does the viewer currently export a selected solid to a STEP file? (We need a file path, not in-memory geometry, in v1.)
Logging β€” should service stderr go to the viewer's existing log file, or to its own file alongside the bundle?