dora-openarm-classifier 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dora_openarm_classifier-0.1.0/LICENSE +202 -0
- dora_openarm_classifier-0.1.0/PKG-INFO +127 -0
- dora_openarm_classifier-0.1.0/README.md +100 -0
- dora_openarm_classifier-0.1.0/pyproject.toml +61 -0
- dora_openarm_classifier-0.1.0/setup.cfg +4 -0
- dora_openarm_classifier-0.1.0/src/dora_openarm_classifier/__init__.py +15 -0
- dora_openarm_classifier-0.1.0/src/dora_openarm_classifier/main.py +228 -0
- dora_openarm_classifier-0.1.0/src/dora_openarm_classifier/server.py +104 -0
- dora_openarm_classifier-0.1.0/src/dora_openarm_classifier/topreward.py +107 -0
- dora_openarm_classifier-0.1.0/src/dora_openarm_classifier.egg-info/PKG-INFO +127 -0
- dora_openarm_classifier-0.1.0/src/dora_openarm_classifier.egg-info/SOURCES.txt +13 -0
- dora_openarm_classifier-0.1.0/src/dora_openarm_classifier.egg-info/dependency_links.txt +1 -0
- dora_openarm_classifier-0.1.0/src/dora_openarm_classifier.egg-info/entry_points.txt +3 -0
- dora_openarm_classifier-0.1.0/src/dora_openarm_classifier.egg-info/requires.txt +13 -0
- dora_openarm_classifier-0.1.0/src/dora_openarm_classifier.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dora-openarm-classifier
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: dora-rs node that classifies whether the current state completes the task successfully or not
|
|
5
|
+
Author: Enactic, Inc.
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Changelog, https://github.com/enactic/dora-openarm-classifier/releases
|
|
8
|
+
Project-URL: Issues, https://github.com/enactic/dora-openarm-classifier/issues
|
|
9
|
+
Project-URL: Repository, https://github.com/enactic/dora-openarm-classifier
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: accelerate
|
|
14
|
+
Requires-Dist: dora-rs>=0.5.0
|
|
15
|
+
Requires-Dist: fastapi
|
|
16
|
+
Requires-Dist: numpy
|
|
17
|
+
Requires-Dist: pillow
|
|
18
|
+
Requires-Dist: pyarrow
|
|
19
|
+
Requires-Dist: python-multipart
|
|
20
|
+
Requires-Dist: qwen-vl-utils
|
|
21
|
+
Requires-Dist: httpx
|
|
22
|
+
Requires-Dist: torch==2.8.*
|
|
23
|
+
Requires-Dist: torchvision==0.23.*
|
|
24
|
+
Requires-Dist: transformers
|
|
25
|
+
Requires-Dist: uvicorn
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# dora-openarm-classifier
|
|
29
|
+
|
|
30
|
+
dora-rs node that classifies whether the current state completes the
|
|
31
|
+
task successfully or not.
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install dora-openarm-classifier
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
This package provides two entry points:
|
|
42
|
+
|
|
43
|
+
- `dora-openarm-classifier`: the dora-rs node.
|
|
44
|
+
- `dora-openarm-classifier-server`: an optional standalone HTTP server
|
|
45
|
+
that loads the model once and serves classification requests, so the
|
|
46
|
+
node itself does not have to hold the model in memory.
|
|
47
|
+
|
|
48
|
+
For each incoming camera frame the node runs single-frame
|
|
49
|
+
[TOPReward](https://topreward.github.io/webpage/), keeps a sliding
|
|
50
|
+
window of the last `--window` scores, and reports the window median as
|
|
51
|
+
the verdict. When arm positions are provided, `SUCCESS` is only latched
|
|
52
|
+
once the grippers are open (release) **and** the vision window agrees,
|
|
53
|
+
combining vision and proprioception.
|
|
54
|
+
|
|
55
|
+
Use it in a dora dataflow:
|
|
56
|
+
|
|
57
|
+
```yaml
|
|
58
|
+
nodes:
|
|
59
|
+
- id: classifier
|
|
60
|
+
build: pip install dora-openarm-classifier
|
|
61
|
+
path: dora-openarm-classifier
|
|
62
|
+
env:
|
|
63
|
+
QUESTION: "Is the object placed in the box?"
|
|
64
|
+
inputs:
|
|
65
|
+
image: camera/image
|
|
66
|
+
position_right: arm-right/state
|
|
67
|
+
position_left: arm-left/state
|
|
68
|
+
outputs:
|
|
69
|
+
- result
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
By default the node loads Qwen3-VL locally. To offload inference to the
|
|
73
|
+
server instead, start the server and point the node at it:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Terminal 1: start the model server
|
|
77
|
+
dora-openarm-classifier-server --port 8000
|
|
78
|
+
|
|
79
|
+
# Terminal 2 (or via the dataflow): run the node against the server
|
|
80
|
+
dora-openarm-classifier --question "..." --server-url http://127.0.0.1:8000
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Inputs
|
|
84
|
+
|
|
85
|
+
| Input | Description |
|
|
86
|
+
| ---------------- | ------------------------------------------------------------------------------------------------- |
|
|
87
|
+
| `image` | JPEG bytes (uint8 array) with `width`/`height`/`encoding` metadata. Triggers a classification. |
|
|
88
|
+
| `position` | Optional 16-dim arm state `[right(8), left(8)]`; gripper joints at indices 7 and 15. |
|
|
89
|
+
| `position_right` | Optional 8-dim right arm state; gripper joint at index 7. |
|
|
90
|
+
| `position_left` | Optional 8-dim left arm state; gripper joint at index 7. |
|
|
91
|
+
|
|
92
|
+
Positions may be plain arrays or `StructArray`s with a `qpos` field.
|
|
93
|
+
They are stored and applied to the next incoming `image`. Without any
|
|
94
|
+
position input, the node falls back to a vision-only verdict.
|
|
95
|
+
|
|
96
|
+
## Outputs
|
|
97
|
+
|
|
98
|
+
| Output | Description |
|
|
99
|
+
| -------- | ----------------------------------------------------------------------------------------------------------- |
|
|
100
|
+
| `result` | Float32 window-median score. Metadata carries `verdict` (`SUCCESS`/`FAIL`) and `frame` (frame counter). |
|
|
101
|
+
|
|
102
|
+
## Command line options
|
|
103
|
+
|
|
104
|
+
Each option can also be set through the matching environment variable.
|
|
105
|
+
|
|
106
|
+
| Option | Environment variable | Default | Description |
|
|
107
|
+
| --------------------- | -------------------- | ---------------------------- | --------------------------------------------------------------------- |
|
|
108
|
+
| `--question` | `QUESTION` | (required) | Yes/no success question asked about each image. |
|
|
109
|
+
| `--server-url` | `SERVER_URL` | (unset; load model locally) | URL of `dora-openarm-classifier-server`. |
|
|
110
|
+
| `--window` | `WINDOW` | `5` | Sliding-window size in frames. |
|
|
111
|
+
| `--threshold` | `THRESHOLD` | `0.5` | `P_yes` threshold for `SUCCESS`. |
|
|
112
|
+
| `--gripper-threshold` | `GRIPPER_THRESHOLD` | `0.2` | `\|gripper joint\|` above which a gripper counts as open. |
|
|
113
|
+
| `--classify-hz` | `CLASSIFY_HZ` | `0.0` | Max inference rate; frames arriving faster are dropped (`0` = no limit). |
|
|
114
|
+
|
|
115
|
+
The server (`dora-openarm-classifier-server`) accepts `--host`
|
|
116
|
+
(default `127.0.0.1`), `--port` (default `8000`), and `--model-id`
|
|
117
|
+
(default `Qwen/Qwen3-VL-4B-Instruct`).
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
Licensed under the Apache License 2.0. See [LICENSE](LICENSE) for details.
|
|
122
|
+
|
|
123
|
+
Copyright 2026 Enactic, Inc.
|
|
124
|
+
|
|
125
|
+
## Code of Conduct
|
|
126
|
+
|
|
127
|
+
All participation in the OpenArm project is governed by our [Code of Conduct](CODE_OF_CONDUCT.md).
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# dora-openarm-classifier
|
|
2
|
+
|
|
3
|
+
dora-rs node that classifies whether the current state completes the
|
|
4
|
+
task successfully or not.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install dora-openarm-classifier
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
This package provides two entry points:
|
|
15
|
+
|
|
16
|
+
- `dora-openarm-classifier`: the dora-rs node.
|
|
17
|
+
- `dora-openarm-classifier-server`: an optional standalone HTTP server
|
|
18
|
+
that loads the model once and serves classification requests, so the
|
|
19
|
+
node itself does not have to hold the model in memory.
|
|
20
|
+
|
|
21
|
+
For each incoming camera frame the node runs single-frame
|
|
22
|
+
[TOPReward](https://topreward.github.io/webpage/), keeps a sliding
|
|
23
|
+
window of the last `--window` scores, and reports the window median as
|
|
24
|
+
the verdict. When arm positions are provided, `SUCCESS` is only latched
|
|
25
|
+
once the grippers are open (release) **and** the vision window agrees,
|
|
26
|
+
combining vision and proprioception.
|
|
27
|
+
|
|
28
|
+
Use it in a dora dataflow:
|
|
29
|
+
|
|
30
|
+
```yaml
|
|
31
|
+
nodes:
|
|
32
|
+
- id: classifier
|
|
33
|
+
build: pip install dora-openarm-classifier
|
|
34
|
+
path: dora-openarm-classifier
|
|
35
|
+
env:
|
|
36
|
+
QUESTION: "Is the object placed in the box?"
|
|
37
|
+
inputs:
|
|
38
|
+
image: camera/image
|
|
39
|
+
position_right: arm-right/state
|
|
40
|
+
position_left: arm-left/state
|
|
41
|
+
outputs:
|
|
42
|
+
- result
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
By default the node loads Qwen3-VL locally. To offload inference to the
|
|
46
|
+
server instead, start the server and point the node at it:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Terminal 1: start the model server
|
|
50
|
+
dora-openarm-classifier-server --port 8000
|
|
51
|
+
|
|
52
|
+
# Terminal 2 (or via the dataflow): run the node against the server
|
|
53
|
+
dora-openarm-classifier --question "..." --server-url http://127.0.0.1:8000
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Inputs
|
|
57
|
+
|
|
58
|
+
| Input | Description |
|
|
59
|
+
| ---------------- | ------------------------------------------------------------------------------------------------- |
|
|
60
|
+
| `image` | JPEG bytes (uint8 array) with `width`/`height`/`encoding` metadata. Triggers a classification. |
|
|
61
|
+
| `position` | Optional 16-dim arm state `[right(8), left(8)]`; gripper joints at indices 7 and 15. |
|
|
62
|
+
| `position_right` | Optional 8-dim right arm state; gripper joint at index 7. |
|
|
63
|
+
| `position_left` | Optional 8-dim left arm state; gripper joint at index 7. |
|
|
64
|
+
|
|
65
|
+
Positions may be plain arrays or `StructArray`s with a `qpos` field.
|
|
66
|
+
They are stored and applied to the next incoming `image`. Without any
|
|
67
|
+
position input, the node falls back to a vision-only verdict.
|
|
68
|
+
|
|
69
|
+
## Outputs
|
|
70
|
+
|
|
71
|
+
| Output | Description |
|
|
72
|
+
| -------- | ----------------------------------------------------------------------------------------------------------- |
|
|
73
|
+
| `result` | Float32 window-median score. Metadata carries `verdict` (`SUCCESS`/`FAIL`) and `frame` (frame counter). |
|
|
74
|
+
|
|
75
|
+
## Command line options
|
|
76
|
+
|
|
77
|
+
Each option can also be set through the matching environment variable.
|
|
78
|
+
|
|
79
|
+
| Option | Environment variable | Default | Description |
|
|
80
|
+
| --------------------- | -------------------- | ---------------------------- | --------------------------------------------------------------------- |
|
|
81
|
+
| `--question` | `QUESTION` | (required) | Yes/no success question asked about each image. |
|
|
82
|
+
| `--server-url` | `SERVER_URL` | (unset; load model locally) | URL of `dora-openarm-classifier-server`. |
|
|
83
|
+
| `--window` | `WINDOW` | `5` | Sliding-window size in frames. |
|
|
84
|
+
| `--threshold` | `THRESHOLD` | `0.5` | `P_yes` threshold for `SUCCESS`. |
|
|
85
|
+
| `--gripper-threshold` | `GRIPPER_THRESHOLD` | `0.2` | `\|gripper joint\|` above which a gripper counts as open. |
|
|
86
|
+
| `--classify-hz` | `CLASSIFY_HZ` | `0.0` | Max inference rate; frames arriving faster are dropped (`0` = no limit). |
|
|
87
|
+
|
|
88
|
+
The server (`dora-openarm-classifier-server`) accepts `--host`
|
|
89
|
+
(default `127.0.0.1`), `--port` (default `8000`), and `--model-id`
|
|
90
|
+
(default `Qwen/Qwen3-VL-4B-Instruct`).
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
Licensed under the Apache License 2.0. See [LICENSE](LICENSE) for details.
|
|
95
|
+
|
|
96
|
+
Copyright 2026 Enactic, Inc.
|
|
97
|
+
|
|
98
|
+
## Code of Conduct
|
|
99
|
+
|
|
100
|
+
All participation in the OpenArm project is governed by our [Code of Conduct](CODE_OF_CONDUCT.md).
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Copyright 2026 Enactic, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
[project]
|
|
16
|
+
name = "dora-openarm-classifier"
|
|
17
|
+
version = "0.1.0"
|
|
18
|
+
authors = [{ name = "Enactic, Inc." }]
|
|
19
|
+
description = "dora-rs node that classifies whether the current state completes the task successfully or not"
|
|
20
|
+
license = { text = "Apache-2.0" }
|
|
21
|
+
readme = "README.md"
|
|
22
|
+
requires-python = ">=3.10"
|
|
23
|
+
|
|
24
|
+
dependencies = [
|
|
25
|
+
"accelerate",
|
|
26
|
+
"dora-rs>=0.5.0",
|
|
27
|
+
"fastapi",
|
|
28
|
+
"numpy",
|
|
29
|
+
"pillow",
|
|
30
|
+
"pyarrow",
|
|
31
|
+
"python-multipart",
|
|
32
|
+
"qwen-vl-utils",
|
|
33
|
+
"httpx",
|
|
34
|
+
"torch==2.8.*",
|
|
35
|
+
"torchvision==0.23.*",
|
|
36
|
+
"transformers",
|
|
37
|
+
"uvicorn",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[dependency-groups]
|
|
41
|
+
dev = [
|
|
42
|
+
"ruff == 0.14.11", # sync with .pre-commit-config.yaml
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[project.scripts]
|
|
46
|
+
dora-openarm-classifier = "dora_openarm_classifier.main:main"
|
|
47
|
+
dora-openarm-classifier-server = "dora_openarm_classifier.server:main"
|
|
48
|
+
|
|
49
|
+
[project.urls]
|
|
50
|
+
Changelog = "https://github.com/enactic/dora-openarm-classifier/releases"
|
|
51
|
+
Issues = "https://github.com/enactic/dora-openarm-classifier/issues"
|
|
52
|
+
Repository = "https://github.com/enactic/dora-openarm-classifier"
|
|
53
|
+
|
|
54
|
+
[tool.ruff.lint]
|
|
55
|
+
extend-select = [
|
|
56
|
+
"D", # pydocstyle
|
|
57
|
+
"UP"
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
[tool.ruff.lint.per-file-ignores]
|
|
61
|
+
"!src/**.py" = ["D"]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Copyright 2026 Enactic, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""dora-rs node that classifies whether the current state completes the task successfully or not."""
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# Copyright 2026 Enactic, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""dora-rs node that classifies whether the current state completes the task successfully or not.
|
|
16
|
+
|
|
17
|
+
For each incoming camera frame it runs single-frame TOPReward, keeps a
|
|
18
|
+
sliding window of the last WINDOW scores, and reports the window
|
|
19
|
+
median as the verdict. When arm positions are provided, success is
|
|
20
|
+
only latched once the grippers are open (release) AND the vision
|
|
21
|
+
window agrees -- combining vision and proprioception, like the
|
|
22
|
+
production classifier node.
|
|
23
|
+
|
|
24
|
+
Inputs:
|
|
25
|
+
image JPEG bytes (uint8 array) with width/height/encoding metadata
|
|
26
|
+
position optional 16-dim arm state [right(8), left(8)]; grippers at 7 and 15
|
|
27
|
+
position_right optional 8-dim right arm state; gripper at 7
|
|
28
|
+
position_left optional 8-dim left arm state; gripper at 7
|
|
29
|
+
Outputs:
|
|
30
|
+
result Float32 score; metadata has "verdict" (SUCCESS/FAIL) and "frame"
|
|
31
|
+
|
|
32
|
+
Command line options/Environment variables:
|
|
33
|
+
--question, QUESTION yes/no success question
|
|
34
|
+
--server-url, SERVER_URL URL for dora-openarm-classifier-server
|
|
35
|
+
--window, WINDOW sliding-window size in frames (default 5)
|
|
36
|
+
--threshold, THRESHOLD P_yes threshold for SUCCESS (default 0.5)
|
|
37
|
+
--gripper-threshold, GRIPPER_THRESHOLD
|
|
38
|
+
|gripper joint| above which a gripper counts
|
|
39
|
+
as open (default 0.2)
|
|
40
|
+
--classify-hz, CLASSIFY_HZ max inference rate; drop frames arriving
|
|
41
|
+
faster (0 = no limit)
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
import argparse
|
|
45
|
+
from collections import deque
|
|
46
|
+
import dora
|
|
47
|
+
from PIL import Image
|
|
48
|
+
import httpx
|
|
49
|
+
import io
|
|
50
|
+
import numpy as np
|
|
51
|
+
import os
|
|
52
|
+
import pyarrow as pa
|
|
53
|
+
import time
|
|
54
|
+
|
|
55
|
+
from .topreward import TOPRewardScorer
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _score_remote(args, image_bytes):
|
|
59
|
+
response = httpx.post(
|
|
60
|
+
f"{args.server_url}/classify",
|
|
61
|
+
data={"question": args.question, "threshold": args.threshold},
|
|
62
|
+
files={"image": ("image.jpeg", image_bytes, "image/jpeg")},
|
|
63
|
+
timeout=10,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
if response.status_code != 200:
|
|
67
|
+
print(
|
|
68
|
+
f"ERROR: Server returned {response.status_code}: {response.content}",
|
|
69
|
+
flush=True,
|
|
70
|
+
)
|
|
71
|
+
return None
|
|
72
|
+
|
|
73
|
+
return response.json()["score"]
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def main():
|
|
77
|
+
"""Run the real-time TOPReword based success classifier."""
|
|
78
|
+
parser = argparse.ArgumentParser(
|
|
79
|
+
description="Classify whether the current task is completed successully or not"
|
|
80
|
+
)
|
|
81
|
+
default_question = os.getenv("QUESTION")
|
|
82
|
+
parser.add_argument(
|
|
83
|
+
"--question",
|
|
84
|
+
required=default_question is None,
|
|
85
|
+
default=default_question,
|
|
86
|
+
help="Yes/no question to ask about images",
|
|
87
|
+
)
|
|
88
|
+
parser.add_argument(
|
|
89
|
+
"--server-url",
|
|
90
|
+
default=os.getenv("SERVER_URL"),
|
|
91
|
+
help="dora-openarm-classifier-server URL",
|
|
92
|
+
)
|
|
93
|
+
parser.add_argument(
|
|
94
|
+
"--window",
|
|
95
|
+
default=int(os.getenv("WINDOW", "5")),
|
|
96
|
+
help="The number of images to use for classification",
|
|
97
|
+
type=int,
|
|
98
|
+
)
|
|
99
|
+
parser.add_argument(
|
|
100
|
+
"--threshold",
|
|
101
|
+
default=float(os.getenv("THRESHOLD", "0.5")),
|
|
102
|
+
help="P_yes threshold for SUCCESS (default: 0.5)",
|
|
103
|
+
type=float,
|
|
104
|
+
)
|
|
105
|
+
parser.add_argument(
|
|
106
|
+
"--gripper-threshold",
|
|
107
|
+
type=float,
|
|
108
|
+
default=float(os.getenv("GRIPPER_THRESHOLD", "0.2")),
|
|
109
|
+
help="Above which a gripper counts as open (default 0.2)",
|
|
110
|
+
)
|
|
111
|
+
parser.add_argument(
|
|
112
|
+
"--classify-hz",
|
|
113
|
+
type=float,
|
|
114
|
+
default=float(os.getenv("CLASSIFY_HZ", "0.0")),
|
|
115
|
+
# Real cameras run at ~30fps but Qwen is ~2Hz, so cap it and
|
|
116
|
+
# drop frames that arrive too soon.
|
|
117
|
+
help="Max classify rate; drop frames arriving faster (0 = no limit)",
|
|
118
|
+
)
|
|
119
|
+
args = parser.parse_args()
|
|
120
|
+
min_interval = 1.0 / args.classify_hz if args.classify_hz > 0 else 0.0
|
|
121
|
+
last_classify = 0.0
|
|
122
|
+
|
|
123
|
+
if args.server_url:
|
|
124
|
+
print(f"Connecting to server: {args.server_url}", flush=True)
|
|
125
|
+
try:
|
|
126
|
+
httpx.get(f"{args.server_url}/health", timeout=5)
|
|
127
|
+
except Exception as error:
|
|
128
|
+
print(f"Cannot connect to server: {args.server_url}: {error}", flush=True)
|
|
129
|
+
print(
|
|
130
|
+
"Make sure server is running: dora-openarm-classifier-server",
|
|
131
|
+
flush=True,
|
|
132
|
+
)
|
|
133
|
+
raise
|
|
134
|
+
else:
|
|
135
|
+
print("Loading Qwen3-VL ...", flush=True)
|
|
136
|
+
scorer = TOPRewardScorer()
|
|
137
|
+
|
|
138
|
+
print("Ready:", flush=True)
|
|
139
|
+
print(f" window: {args.window}", flush=True)
|
|
140
|
+
print(f" threshold: {args.threshold:.0%}", flush=True)
|
|
141
|
+
print(f" question: {args.question}", flush=True)
|
|
142
|
+
|
|
143
|
+
scores = deque(maxlen=args.window)
|
|
144
|
+
last_right_pos = None # latest right arm position (8-dim)
|
|
145
|
+
last_left_pos = None # latest left arm position (8-dim)
|
|
146
|
+
success_latched = False # sticky once vision + grippers agree
|
|
147
|
+
node = dora.Node()
|
|
148
|
+
n = 0
|
|
149
|
+
for event in node:
|
|
150
|
+
if event["type"] != "INPUT":
|
|
151
|
+
continue
|
|
152
|
+
|
|
153
|
+
if event["id"] == "position":
|
|
154
|
+
value = event["value"]
|
|
155
|
+
if isinstance(value, pa.StructArray):
|
|
156
|
+
value = value.field("qpos")
|
|
157
|
+
last_pos = value.to_numpy(zero_copy_only=False)
|
|
158
|
+
last_right_pos = last_pos[:8]
|
|
159
|
+
last_left_pos = last_pos[8:]
|
|
160
|
+
continue
|
|
161
|
+
|
|
162
|
+
if event["id"] == "position_right":
|
|
163
|
+
value = event["value"]
|
|
164
|
+
if isinstance(value, pa.StructArray):
|
|
165
|
+
value = value.field("qpos")
|
|
166
|
+
last_right_pos = value.to_numpy(zero_copy_only=False)
|
|
167
|
+
continue
|
|
168
|
+
|
|
169
|
+
if event["id"] == "position_left":
|
|
170
|
+
value = event["value"]
|
|
171
|
+
if isinstance(value, pa.StructArray):
|
|
172
|
+
value = value.field("qpos")
|
|
173
|
+
last_left_pos = value.to_numpy(zero_copy_only=False)
|
|
174
|
+
continue
|
|
175
|
+
|
|
176
|
+
if event["id"] == "image":
|
|
177
|
+
# rate-limit: drop frames that arrive faster than INFER_HZ
|
|
178
|
+
now = time.monotonic()
|
|
179
|
+
if min_interval and (now - last_classify) < min_interval:
|
|
180
|
+
continue
|
|
181
|
+
last_classify = now
|
|
182
|
+
|
|
183
|
+
image_bytes = event["value"].to_numpy(zero_copy_only=False).tobytes()
|
|
184
|
+
if args.server_url:
|
|
185
|
+
score = _score_remote(args, image_bytes)
|
|
186
|
+
if score is None:
|
|
187
|
+
continue
|
|
188
|
+
else:
|
|
189
|
+
image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
|
|
190
|
+
_, _, score = scorer.score(image, args.question)
|
|
191
|
+
scores.append(score)
|
|
192
|
+
agg = float(np.median(scores))
|
|
193
|
+
|
|
194
|
+
grip_info = ""
|
|
195
|
+
if (
|
|
196
|
+
last_right_pos is not None
|
|
197
|
+
and len(last_right_pos) >= 8
|
|
198
|
+
and last_left_pos is not None
|
|
199
|
+
and len(last_left_pos) >= 8
|
|
200
|
+
):
|
|
201
|
+
gr, gl = float(last_right_pos[7]), float(last_left_pos[7])
|
|
202
|
+
grippers_open = (
|
|
203
|
+
abs(gr) > args.gripper_threshold
|
|
204
|
+
and abs(gl) > args.gripper_threshold
|
|
205
|
+
)
|
|
206
|
+
if not success_latched and grippers_open and agg >= args.threshold:
|
|
207
|
+
success_latched = True
|
|
208
|
+
verdict = "SUCCESS" if success_latched else "FAIL"
|
|
209
|
+
grip_info = f" grip(r={gr:+.2f} l={gl:+.2f} {'OPEN' if grippers_open else 'closed'})"
|
|
210
|
+
else:
|
|
211
|
+
# no arm data -> vision-only fallback
|
|
212
|
+
verdict = "SUCCESS" if agg >= args.threshold else "FAIL"
|
|
213
|
+
|
|
214
|
+
n += 1
|
|
215
|
+
print(
|
|
216
|
+
f"frame {n:03d} P_yes={score:5.1%} "
|
|
217
|
+
f"window_median={agg:5.1%}{grip_info} -> {verdict}",
|
|
218
|
+
flush=True,
|
|
219
|
+
)
|
|
220
|
+
node.send_output(
|
|
221
|
+
"result",
|
|
222
|
+
pa.array([agg], type=pa.float32()),
|
|
223
|
+
metadata={"verdict": verdict, "frame": n},
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
if __name__ == "__main__":
|
|
228
|
+
main()
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Copyright 2026 Enactic, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Classification server.
|
|
16
|
+
|
|
17
|
+
Standalone server that loads model once and serves classification requests.
|
|
18
|
+
Clients can send images via HTTP POST and get back success scores.
|
|
19
|
+
|
|
20
|
+
Usage:
|
|
21
|
+
dora-openarm-classifier-server --port 8000
|
|
22
|
+
|
|
23
|
+
API:
|
|
24
|
+
POST /classify
|
|
25
|
+
Content-Type: multipart/form-data
|
|
26
|
+
question: yes/no success question
|
|
27
|
+
image: JPEG or PNG image
|
|
28
|
+
Content-Type: image/jpeg or image/png
|
|
29
|
+
|
|
30
|
+
Response (JSON):
|
|
31
|
+
{
|
|
32
|
+
"p_yes": 0.85,
|
|
33
|
+
"p_no": 0.12,
|
|
34
|
+
"score": 0.876, # normalized p_yes
|
|
35
|
+
}
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
import argparse
|
|
39
|
+
from fastapi import FastAPI, Form, File, UploadFile
|
|
40
|
+
from fastapi.responses import JSONResponse
|
|
41
|
+
from PIL import Image
|
|
42
|
+
from typing import Annotated
|
|
43
|
+
import uvicorn
|
|
44
|
+
|
|
45
|
+
from .topreward import TOPRewardScorer
|
|
46
|
+
|
|
47
|
+
app = FastAPI()
|
|
48
|
+
|
|
49
|
+
scorer = None
|
|
50
|
+
args = None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@app.get("/health", response_class=JSONResponse)
|
|
54
|
+
def _health():
|
|
55
|
+
return {"status": "healthy"}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@app.post("/classify", response_class=JSONResponse)
|
|
59
|
+
async def _classify(
|
|
60
|
+
question: Annotated[str, Form()], image: Annotated[UploadFile, File()]
|
|
61
|
+
):
|
|
62
|
+
p_yes, p_no, score = scorer.score(Image.open(image.file).convert("RGB"), question)
|
|
63
|
+
return {
|
|
64
|
+
"p_yes": float(p_yes),
|
|
65
|
+
"p_no": float(p_no),
|
|
66
|
+
"score": float(score),
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def main():
|
|
71
|
+
"""Run TOPReward based classification server."""
|
|
72
|
+
parser = argparse.ArgumentParser(description="Classification server")
|
|
73
|
+
parser.add_argument(
|
|
74
|
+
"--port", type=int, default=8000, help="Server port (default: 8000)"
|
|
75
|
+
)
|
|
76
|
+
parser.add_argument(
|
|
77
|
+
"--host", type=str, default="127.0.0.1", help="Server host (default: 127.0.0.1)"
|
|
78
|
+
)
|
|
79
|
+
parser.add_argument(
|
|
80
|
+
"--model-id",
|
|
81
|
+
type=str,
|
|
82
|
+
default=None,
|
|
83
|
+
help="Model ID (default: Qwen/Qwen3-VL-4B-Instruct)",
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
global args
|
|
87
|
+
args = parser.parse_args()
|
|
88
|
+
|
|
89
|
+
print("Loading model...", flush=True)
|
|
90
|
+
global scorer
|
|
91
|
+
if args.model_id:
|
|
92
|
+
scorer = TOPRewardScorer(args.model_id)
|
|
93
|
+
else:
|
|
94
|
+
scorer = TOPRewardScorer()
|
|
95
|
+
print("Ready!", flush=True)
|
|
96
|
+
|
|
97
|
+
config = uvicorn.Config(app, host=args.host, port=args.port, log_level="info")
|
|
98
|
+
server = uvicorn.Server(config)
|
|
99
|
+
|
|
100
|
+
server.run()
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
if __name__ == "__main__":
|
|
104
|
+
main()
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Copyright 2026 Enactic, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Qwen-VL TOPReward scorer.
|
|
16
|
+
|
|
17
|
+
https://topreward.github.io/webpage/
|
|
18
|
+
|
|
19
|
+
Asks a yes/no question about an image and reads the probability the model
|
|
20
|
+
assigns to "Yes" from the next-token logits. The normalized
|
|
21
|
+
P_yes = P(yes) / (P(yes) + P(no)) is the success score -- no labels, no training.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from qwen_vl_utils import process_vision_info
|
|
25
|
+
import torch
|
|
26
|
+
from transformers import AutoProcessor
|
|
27
|
+
|
|
28
|
+
MODEL_ID = "Qwen/Qwen3-VL-4B-Instruct"
|
|
29
|
+
YES_WORDS = ["Yes", "yes", "YES", " Yes", " yes"]
|
|
30
|
+
NO_WORDS = ["No", "no", "NO", " No", " no"]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _load_model(model_id):
|
|
34
|
+
"""Pick the right model class from the id.
|
|
35
|
+
|
|
36
|
+
Use Instruct (not Thinking)
|
|
37
|
+
variants: we read the FIRST generated token, but Thinking models emit
|
|
38
|
+
reasoning first, so the first token would not be Yes/No.
|
|
39
|
+
"""
|
|
40
|
+
low = model_id.lower()
|
|
41
|
+
if "qwen3-vl" in low and "moe" in low:
|
|
42
|
+
from transformers import Qwen3VLMoeForConditionalGeneration as Cls
|
|
43
|
+
elif "qwen3-vl" in low:
|
|
44
|
+
from transformers import Qwen3VLForConditionalGeneration as Cls
|
|
45
|
+
else: # qwen2.5-vl and friends
|
|
46
|
+
from transformers import Qwen2_5_VLForConditionalGeneration as Cls
|
|
47
|
+
return Cls.from_pretrained(model_id, torch_dtype="auto", device_map="auto").eval()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class TOPRewardScorer:
|
|
51
|
+
"""Single-frame Qwen-VL success scorer."""
|
|
52
|
+
|
|
53
|
+
def __init__(self, model_id=MODEL_ID):
|
|
54
|
+
"""Load the model and processor once."""
|
|
55
|
+
print(f"[load] {model_id} ...", flush=True)
|
|
56
|
+
self.model = _load_model(model_id)
|
|
57
|
+
self.proc = AutoProcessor.from_pretrained(model_id)
|
|
58
|
+
self.tok = self.proc.tokenizer
|
|
59
|
+
print(
|
|
60
|
+
f"[load] done. device={self.model.device} dtype={self.model.dtype}\n",
|
|
61
|
+
flush=True,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
def _mass(self, probs, words):
|
|
65
|
+
s = 0.0
|
|
66
|
+
for w in words:
|
|
67
|
+
ids = self.tok.encode(w, add_special_tokens=False)
|
|
68
|
+
if len(ids) == 1:
|
|
69
|
+
s += float(probs[ids[0]].item())
|
|
70
|
+
return s
|
|
71
|
+
|
|
72
|
+
def next_token_probs(self, image, question):
|
|
73
|
+
"""Next-token probability distribution for (image, question).
|
|
74
|
+
|
|
75
|
+
``image`` may be a file path or a PIL image.
|
|
76
|
+
"""
|
|
77
|
+
messages = [
|
|
78
|
+
{
|
|
79
|
+
"role": "user",
|
|
80
|
+
"content": [
|
|
81
|
+
{"type": "image", "image": image},
|
|
82
|
+
{"type": "text", "text": question},
|
|
83
|
+
],
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
text = self.proc.apply_chat_template(
|
|
87
|
+
messages, tokenize=False, add_generation_prompt=True
|
|
88
|
+
)
|
|
89
|
+
image_inputs, video_inputs = process_vision_info(messages)
|
|
90
|
+
inputs = self.proc(
|
|
91
|
+
text=[text],
|
|
92
|
+
images=image_inputs,
|
|
93
|
+
videos=video_inputs,
|
|
94
|
+
padding=True,
|
|
95
|
+
return_tensors="pt",
|
|
96
|
+
).to(self.model.device)
|
|
97
|
+
with torch.no_grad():
|
|
98
|
+
logits = self.model(**inputs).logits[0, -1]
|
|
99
|
+
return torch.softmax(logits.float(), dim=-1)
|
|
100
|
+
|
|
101
|
+
def score(self, image, question):
|
|
102
|
+
"""Return (raw P_yes, raw P_no, normalized P_yes = TOPReward)."""
|
|
103
|
+
probs = self.next_token_probs(image, question + "\n\nAnswer Yes or No.")
|
|
104
|
+
p_yes = self._mass(probs, YES_WORDS)
|
|
105
|
+
p_no = self._mass(probs, NO_WORDS)
|
|
106
|
+
norm = p_yes / (p_yes + p_no) if (p_yes + p_no) > 0 else 0.0
|
|
107
|
+
return p_yes, p_no, norm
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dora-openarm-classifier
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: dora-rs node that classifies whether the current state completes the task successfully or not
|
|
5
|
+
Author: Enactic, Inc.
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Changelog, https://github.com/enactic/dora-openarm-classifier/releases
|
|
8
|
+
Project-URL: Issues, https://github.com/enactic/dora-openarm-classifier/issues
|
|
9
|
+
Project-URL: Repository, https://github.com/enactic/dora-openarm-classifier
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: accelerate
|
|
14
|
+
Requires-Dist: dora-rs>=0.5.0
|
|
15
|
+
Requires-Dist: fastapi
|
|
16
|
+
Requires-Dist: numpy
|
|
17
|
+
Requires-Dist: pillow
|
|
18
|
+
Requires-Dist: pyarrow
|
|
19
|
+
Requires-Dist: python-multipart
|
|
20
|
+
Requires-Dist: qwen-vl-utils
|
|
21
|
+
Requires-Dist: httpx
|
|
22
|
+
Requires-Dist: torch==2.8.*
|
|
23
|
+
Requires-Dist: torchvision==0.23.*
|
|
24
|
+
Requires-Dist: transformers
|
|
25
|
+
Requires-Dist: uvicorn
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# dora-openarm-classifier
|
|
29
|
+
|
|
30
|
+
dora-rs node that classifies whether the current state completes the
|
|
31
|
+
task successfully or not.
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install dora-openarm-classifier
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
This package provides two entry points:
|
|
42
|
+
|
|
43
|
+
- `dora-openarm-classifier`: the dora-rs node.
|
|
44
|
+
- `dora-openarm-classifier-server`: an optional standalone HTTP server
|
|
45
|
+
that loads the model once and serves classification requests, so the
|
|
46
|
+
node itself does not have to hold the model in memory.
|
|
47
|
+
|
|
48
|
+
For each incoming camera frame the node runs single-frame
|
|
49
|
+
[TOPReward](https://topreward.github.io/webpage/), keeps a sliding
|
|
50
|
+
window of the last `--window` scores, and reports the window median as
|
|
51
|
+
the verdict. When arm positions are provided, `SUCCESS` is only latched
|
|
52
|
+
once the grippers are open (release) **and** the vision window agrees,
|
|
53
|
+
combining vision and proprioception.
|
|
54
|
+
|
|
55
|
+
Use it in a dora dataflow:
|
|
56
|
+
|
|
57
|
+
```yaml
|
|
58
|
+
nodes:
|
|
59
|
+
- id: classifier
|
|
60
|
+
build: pip install dora-openarm-classifier
|
|
61
|
+
path: dora-openarm-classifier
|
|
62
|
+
env:
|
|
63
|
+
QUESTION: "Is the object placed in the box?"
|
|
64
|
+
inputs:
|
|
65
|
+
image: camera/image
|
|
66
|
+
position_right: arm-right/state
|
|
67
|
+
position_left: arm-left/state
|
|
68
|
+
outputs:
|
|
69
|
+
- result
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
By default the node loads Qwen3-VL locally. To offload inference to the
|
|
73
|
+
server instead, start the server and point the node at it:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Terminal 1: start the model server
|
|
77
|
+
dora-openarm-classifier-server --port 8000
|
|
78
|
+
|
|
79
|
+
# Terminal 2 (or via the dataflow): run the node against the server
|
|
80
|
+
dora-openarm-classifier --question "..." --server-url http://127.0.0.1:8000
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Inputs
|
|
84
|
+
|
|
85
|
+
| Input | Description |
|
|
86
|
+
| ---------------- | ------------------------------------------------------------------------------------------------- |
|
|
87
|
+
| `image` | JPEG bytes (uint8 array) with `width`/`height`/`encoding` metadata. Triggers a classification. |
|
|
88
|
+
| `position` | Optional 16-dim arm state `[right(8), left(8)]`; gripper joints at indices 7 and 15. |
|
|
89
|
+
| `position_right` | Optional 8-dim right arm state; gripper joint at index 7. |
|
|
90
|
+
| `position_left` | Optional 8-dim left arm state; gripper joint at index 7. |
|
|
91
|
+
|
|
92
|
+
Positions may be plain arrays or `StructArray`s with a `qpos` field.
|
|
93
|
+
They are stored and applied to the next incoming `image`. Without any
|
|
94
|
+
position input, the node falls back to a vision-only verdict.
|
|
95
|
+
|
|
96
|
+
## Outputs
|
|
97
|
+
|
|
98
|
+
| Output | Description |
|
|
99
|
+
| -------- | ----------------------------------------------------------------------------------------------------------- |
|
|
100
|
+
| `result` | Float32 window-median score. Metadata carries `verdict` (`SUCCESS`/`FAIL`) and `frame` (frame counter). |
|
|
101
|
+
|
|
102
|
+
## Command line options
|
|
103
|
+
|
|
104
|
+
Each option can also be set through the matching environment variable.
|
|
105
|
+
|
|
106
|
+
| Option | Environment variable | Default | Description |
|
|
107
|
+
| --------------------- | -------------------- | ---------------------------- | --------------------------------------------------------------------- |
|
|
108
|
+
| `--question` | `QUESTION` | (required) | Yes/no success question asked about each image. |
|
|
109
|
+
| `--server-url` | `SERVER_URL` | (unset; load model locally) | URL of `dora-openarm-classifier-server`. |
|
|
110
|
+
| `--window` | `WINDOW` | `5` | Sliding-window size in frames. |
|
|
111
|
+
| `--threshold` | `THRESHOLD` | `0.5` | `P_yes` threshold for `SUCCESS`. |
|
|
112
|
+
| `--gripper-threshold` | `GRIPPER_THRESHOLD` | `0.2` | `\|gripper joint\|` above which a gripper counts as open. |
|
|
113
|
+
| `--classify-hz` | `CLASSIFY_HZ` | `0.0` | Max inference rate; frames arriving faster are dropped (`0` = no limit). |
|
|
114
|
+
|
|
115
|
+
The server (`dora-openarm-classifier-server`) accepts `--host`
|
|
116
|
+
(default `127.0.0.1`), `--port` (default `8000`), and `--model-id`
|
|
117
|
+
(default `Qwen/Qwen3-VL-4B-Instruct`).
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
Licensed under the Apache License 2.0. See [LICENSE](LICENSE) for details.
|
|
122
|
+
|
|
123
|
+
Copyright 2026 Enactic, Inc.
|
|
124
|
+
|
|
125
|
+
## Code of Conduct
|
|
126
|
+
|
|
127
|
+
All participation in the OpenArm project is governed by our [Code of Conduct](CODE_OF_CONDUCT.md).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/dora_openarm_classifier/__init__.py
|
|
5
|
+
src/dora_openarm_classifier/main.py
|
|
6
|
+
src/dora_openarm_classifier/server.py
|
|
7
|
+
src/dora_openarm_classifier/topreward.py
|
|
8
|
+
src/dora_openarm_classifier.egg-info/PKG-INFO
|
|
9
|
+
src/dora_openarm_classifier.egg-info/SOURCES.txt
|
|
10
|
+
src/dora_openarm_classifier.egg-info/dependency_links.txt
|
|
11
|
+
src/dora_openarm_classifier.egg-info/entry_points.txt
|
|
12
|
+
src/dora_openarm_classifier.egg-info/requires.txt
|
|
13
|
+
src/dora_openarm_classifier.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dora_openarm_classifier
|