Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions ai2thor/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,6 @@ def process_colors_ids(self):
if self.instance_segmentation_frame is None:
return

MIN_DETECTION_LEN = 0

self.instance_detections2D = {}
unique_ids, unique_inverse = unique_rows(
self.instance_segmentation_frame.reshape(-1, 3), return_inverse=True
Expand All @@ -283,9 +281,7 @@ def process_colors_ids(self):
== np.arange(len(unique_ids))[:, np.newaxis, np.newaxis]
)

# for unique_color_ind, unique_color in enumerate(unique_ids):
for color_bounds in self.metadata["colorBounds"]:
color = np.array(color_bounds["color"])
for color_ind, color in enumerate(unique_ids):
color_name = self.color_to_object_id.get(
tuple(int(cc) for cc in color), "background"
)
Expand All @@ -295,29 +291,29 @@ def process_colors_ids(self):
cls = cls.split("|")[0]
simObj = True

bb = np.array(color_bounds["bounds"])
bb[[1, 3]] = self.metadata["screenHeight"] - bb[[3, 1]]
if not (
(bb[2] - bb[0]) < MIN_DETECTION_LEN
or (bb[3] - bb[1]) < MIN_DETECTION_LEN
):
if cls not in self.class_detections2D:
self.class_detections2D[cls] = []
if cls not in self.class_detections2D:
self.class_detections2D[cls] = []
mask = unique_masks[color_ind, ...]
bb = self.mask_bounding_box(mask)
self.class_detections2D[cls].append(bb)

if simObj:
self.instance_detections2D[color_name] = bb
self.instance_masks[color_name] = mask

self.class_detections2D[cls].append(bb)
if cls not in self.class_masks:
self.class_masks[cls] = mask
else:
self.class_masks[cls] = np.logical_or(self.class_masks[cls], mask)

color_ind = np.argmin(np.sum(np.abs(unique_ids - color), axis=1))
def mask_bounding_box(self, mask):
rows = np.any(mask, axis=1)
cols = np.any(mask, axis=0)
rmin, rmax = np.where(rows)[0][[0, -1]]
cmin, cmax = np.where(cols)[0][[0, -1]]

if simObj:
self.instance_detections2D[color_name] = bb
self.instance_masks[color_name] = unique_masks[color_ind, ...]
return cmin, rmin, cmax, rmax

if cls not in self.class_masks:
self.class_masks[cls] = unique_masks[color_ind, ...]
else:
self.class_masks[cls] = np.logical_or(
self.class_masks[cls], unique_masks[color_ind, ...]
)

def _image_depth(self, image_depth_data, **kwargs):
image_depth = read_buffer_image(
Expand Down
4 changes: 0 additions & 4 deletions ai2thor/tests/data/arm-metadata-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,6 @@
"colors": {
"type": "null"
},
"colorBounds": {
"type": "null"
},
"flatSurfacesOnGrid": {
"type": "array"
},
Expand Down Expand Up @@ -708,7 +705,6 @@
"cameraPosition",
"collided",
"collidedObjects",
"colorBounds",
"colors",
"currentTime",
"distances",
Expand Down
4 changes: 0 additions & 4 deletions ai2thor/tests/data/metadata-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,6 @@
"colors": {
"type": "null"
},
"colorBounds": {
"type": "null"
},
"flatSurfacesOnGrid": {
"type": "array"
},
Expand Down Expand Up @@ -571,7 +568,6 @@
"cameraPosition",
"collided",
"collidedObjects",
"colorBounds",
"colors",
"currentTime",
"distances",
Expand Down
38 changes: 0 additions & 38 deletions unity/Assets/Scripts/AgentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -797,43 +797,6 @@ private void addObjectImage(List<KeyValuePair<string, byte[]>> payload, BaseFPSA
byte[] bytes = agent.imageSynthesis.Encode("_id");
payload.Add(new KeyValuePair<string, byte[]>("image_ids", bytes));

Color[] id_image = agent.imageSynthesis.tex.GetPixels();
Dictionary<Color, int[]> colorBounds = new Dictionary<Color, int[]>();
for (int yy = 0; yy < UnityEngine.Screen.height; yy++) {
for (int xx = 0; xx < tex.width; xx++) {
Color colorOn = id_image[yy * UnityEngine.Screen.width + xx];
if (!colorBounds.ContainsKey(colorOn)) {
colorBounds[colorOn] = new int[] { xx, yy, xx, yy };
} else {
int[] oldPoint = colorBounds[colorOn];
if (xx < oldPoint[0]) {
oldPoint[0] = xx;
}
if (yy < oldPoint[1]) {
oldPoint[1] = yy;
}
if (xx > oldPoint[2]) {
oldPoint[2] = xx;
}
if (yy > oldPoint[3]) {
oldPoint[3] = yy;
}
}
}
}
List<ColorBounds> boundsList = new List<ColorBounds>();
foreach (Color key in colorBounds.Keys) {
ColorBounds bounds = new ColorBounds();
bounds.color = new ushort[] {
(ushort)Math.Round (key.r * 255),
(ushort)Math.Round (key.g * 255),
(ushort)Math.Round (key.b * 255)
};
bounds.bounds = colorBounds[key];
boundsList.Add(bounds);
}
metadata.colorBounds = boundsList.ToArray();

List<ColorId> colors = new List<ColorId>();
foreach (Color key in agent.imageSynthesis.colorIds.Keys) {
ColorId cid = new ColorId();
Expand Down Expand Up @@ -1601,7 +1564,6 @@ public struct MetadataWrapper {
public int screenHeight;
public int agentId;
public ColorId[] colors;
public ColorBounds[] colorBounds;

// Extras
public float[] flatSurfacesOnGrid;
Expand Down