Skip to content

Commit ed4eb5c

Browse files
committed
Depth Vision and Segment Vision in the conformance suite (1.21) [skip publish]
The conformance driver reads both readings in the wire's shapes, and the readings' sizes and grid dimensions must be whole numbers of at least 0, as the suite holds them; a negative one makes the reading an UnknownReading. CI on conformance suite 1.21.
1 parent 0ea6603 commit ed4eb5c

4 files changed

Lines changed: 104 additions & 9 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ permissions:
99
contents: read
1010

1111
env:
12-
# The conformance suite commit this SDK is tested against (suite 1.20, tag v1.20, for specification 1.3). Change it here only.
13-
CONFORMANCE_REF: b9e549115c5d7e20fa33da9ebb187a06c8a26eca
12+
# The conformance suite commit this SDK is tested against (suite 1.21, tag v1.21, for specification 1.3). Change it here only.
13+
CONFORMANCE_REF: 2de217d7fbfbed7fb712bd9b0197605a8857e8f7
1414

1515
# Every action is pinned to a commit SHA; the tag it was resolved from follows as a comment.
1616
jobs:

‎src/main/java/com/bynn/decisionnode/Responses.java‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ private static DepthReading depthReading(Map<String, Object> raw) {
190190
Long width = integer(raw.get("width"));
191191
Long height = integer(raw.get("height"));
192192
Object ahead = raw.get("ahead");
193-
if (!(image instanceof String) || dirs == null || dirs.size() != 7 || !(ground instanceof Boolean) || rows == null
194-
|| cols == null || grid == null || depths == null || width == null || height == null
193+
if (!(image instanceof String) || dirs == null || dirs.size() != 7 || !(ground instanceof Boolean) || !whole(rows)
194+
|| !whole(cols) || grid == null || depths == null || !whole(width) || !whole(height)
195195
|| (ahead != null && Json.asDouble(ahead) == null)) {
196196
return null;
197197
}
@@ -227,7 +227,7 @@ private static SegmentReading segmentReading(Map<String, Object> raw) {
227227
List<Object> found = Json.asList(raw.get("instances"));
228228
Object source = raw.get("depth_source");
229229
Object hfov = raw.get("assumed_hfov_deg");
230-
if (!(image instanceof String) || width == null || height == null || prompts == null || found == null
230+
if (!(image instanceof String) || !whole(width) || !whole(height) || prompts == null || found == null
231231
|| (source != null && !(source instanceof String)) || (hfov != null && Json.asDouble(hfov) == null)) {
232232
return null;
233233
}
@@ -314,6 +314,11 @@ private static SegmentInstance segmentInstance(Map<String, Object> m) {
314314
polygon, area, centroid, opening, depth, size);
315315
}
316316

317+
/** A JSON integer of at least 0. */
318+
private static boolean whole(Long n) {
319+
return n != null && n >= 0;
320+
}
321+
317322
/** A JSON array of numbers, as doubles; null when it is not one. */
318323
private static List<Double> numberList(Object value) {
319324
List<Object> list = Json.asList(value);

‎src/test/java/com/bynn/decisionnode/ConformanceTest.java‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,33 @@ static Map<String, Object> normReading(Reading r) {
11281128
list.add(e);
11291129
}
11301130
n.put("matches", list);
1131+
} else if (r instanceof DepthReading dr) {
1132+
n.put("kind", "bynn_depth");
1133+
n.put("image", dr.image());
1134+
n.put("ahead", dr.ahead());
1135+
n.put("directions", dr.directions());
1136+
n.put("ground", dr.ground());
1137+
n.put("grid_rows", dr.gridRows());
1138+
n.put("grid_cols", dr.gridCols());
1139+
n.put("grid", dr.grid());
1140+
n.put("depth_min", dr.depthMin());
1141+
n.put("depth_max", dr.depthMax());
1142+
n.put("depth_median", dr.depthMedian());
1143+
n.put("width", dr.width());
1144+
n.put("height", dr.height());
1145+
} else if (r instanceof SegmentReading sr) {
1146+
n.put("kind", "bynn_segment");
1147+
n.put("image", sr.image());
1148+
n.put("width", sr.width());
1149+
n.put("height", sr.height());
1150+
n.put("prompts", sr.prompts());
1151+
n.put("depth_source", sr.depthSource());
1152+
n.put("assumed_hfov_deg", sr.assumedHfovDeg());
1153+
List<Object> instances = new ArrayList<>();
1154+
for (SegmentInstance i : sr.instances()) {
1155+
instances.add(normInstance(i));
1156+
}
1157+
n.put("instances", instances);
11311158
} else if (r instanceof OcrReading o) {
11321159
n.put("kind", "ocr");
11331160
n.put("image", o.image());
@@ -1140,6 +1167,67 @@ static Map<String, Object> normReading(Reading r) {
11401167
return n;
11411168
}
11421169

1170+
/** A Segment Vision match in the wire's fields and shapes: points as [x, y], an empty part as null. */
1171+
static Map<String, Object> normInstance(SegmentInstance i) {
1172+
Map<String, Object> n = new LinkedHashMap<>();
1173+
n.put("label", i.label());
1174+
n.put("score", i.score());
1175+
n.put("box", List.of(i.box().x1(), i.box().y1(), i.box().x2(), i.box().y2()));
1176+
n.put("polygon", pointList(i.polygon()));
1177+
n.put("area", i.area());
1178+
n.put("centroid", pointPair(i.centroid()));
1179+
if (i.opening() == null) {
1180+
n.put("opening", null);
1181+
} else {
1182+
Map<String, Object> o = new LinkedHashMap<>();
1183+
o.put("polygon", pointList(i.opening().polygon()));
1184+
o.put("centroid", pointPair(i.opening().centroid()));
1185+
o.put("width", i.opening().width());
1186+
o.put("height", i.opening().height());
1187+
o.put("offset", pointPair(i.opening().offset()));
1188+
o.put("area", i.opening().area());
1189+
n.put("opening", o);
1190+
}
1191+
if (i.depth() == null) {
1192+
n.put("depth", null);
1193+
} else {
1194+
Map<String, Object> d = new LinkedHashMap<>();
1195+
d.put("median", i.depth().median());
1196+
d.put("opening_median", i.depth().openingMedian());
1197+
d.put("opening_rim_median", i.depth().openingRimMedian());
1198+
n.put("depth", d);
1199+
}
1200+
if (i.sizeM() == null) {
1201+
n.put("size_m", null);
1202+
} else {
1203+
Map<String, Object> s = new LinkedHashMap<>();
1204+
s.put("width", i.sizeM().width());
1205+
s.put("height", i.sizeM().height());
1206+
if (i.sizeM().opening() == null) {
1207+
s.put("opening", null);
1208+
} else {
1209+
Map<String, Object> so = new LinkedHashMap<>();
1210+
so.put("width", i.sizeM().opening().width());
1211+
so.put("height", i.sizeM().opening().height());
1212+
s.put("opening", so);
1213+
}
1214+
n.put("size_m", s);
1215+
}
1216+
return n;
1217+
}
1218+
1219+
private static List<Object> pointPair(SegmentPoint p) {
1220+
return List.of(p.x(), p.y());
1221+
}
1222+
1223+
private static List<Object> pointList(List<SegmentPoint> points) {
1224+
List<Object> out = new ArrayList<>();
1225+
for (SegmentPoint p : points) {
1226+
out.add(pointPair(p));
1227+
}
1228+
return out;
1229+
}
1230+
11431231
static Map<String, Object> normBox(FaceBox b) {
11441232
Map<String, Object> box = new LinkedHashMap<>();
11451233
box.put("x1", b.x1());

‎src/test/java/com/bynn/decisionnode/VisionReadingsTest.java‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ void aMalformedDepthReadingIsGeneric() throws Exception {
5959
+ DEPTH.replace("\"grid_rows\":2", "\"grid_rows\":2.5") + ","
6060
+ DEPTH.replace("[1.5,2,2.25]", "[1.5,null,2.25]") + ","
6161
+ DEPTH.replace("\"ahead\":2.41", "\"ahead\":\"far\"") + ","
62-
+ DEPTH.replace("\"depth_median\":2.35,", "") + "]");
63-
assertEquals(8, r.size());
62+
+ DEPTH.replace("\"depth_median\":2.35,", "") + ","
63+
+ DEPTH.replace("\"width\":1280", "\"width\":-1") + "]");
64+
assertEquals(9, r.size());
6465
r.forEach(each -> assertEquals("bynn_depth", assertInstanceOf(UnknownReading.class, each).booster()));
6566
}
6667

@@ -116,8 +117,9 @@ void aMalformedSegmentReadingIsGeneric() throws Exception {
116117
+ head + INSTANCE.replace("{\"width\":0.8,\"height\":2.0}", "{\"width\":0.8}") + "]},"
117118
+ head + INSTANCE.replace("\"label\":\"door\",", "") + "]},"
118119
+ "{\"image\":\"hall\",\"width\":1280,\"height\":720,\"prompts\":[1],\"instances\":[]},"
119-
+ "{\"image\":\"hall\",\"width\":1280,\"height\":720,\"prompts\":[\"door\"],\"instances\":[],\"depth_source\":5}]");
120-
assertEquals(9, r.size());
120+
+ "{\"image\":\"hall\",\"width\":1280,\"height\":720,\"prompts\":[\"door\"],\"instances\":[],\"depth_source\":5},"
121+
+ "{\"image\":\"hall\",\"width\":1280,\"height\":-720,\"prompts\":[\"door\"],\"instances\":[]}]");
122+
assertEquals(10, r.size());
121123
r.forEach(each -> assertEquals("bynn_segment", assertInstanceOf(UnknownReading.class, each).booster()));
122124
assertFalse(r.isEmpty());
123125
}

0 commit comments

Comments
 (0)