-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speedup semantic rasterizer #140
base: master
Are you sure you want to change the base?
Speedup semantic rasterizer #140
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work! minors, you can either pick them up yourself or I can also do them, just let me know :)
@@ -174,7 +177,8 @@ def get_crosswalk_coords(self, element_id: str) -> dict: | |||
traffic_element.geo_frame, | |||
) | |||
|
|||
return {"xyz": xyz} | |||
xyz[:, -1] = 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this required? We ignore the z coordinates in the following so this shouldn't make any difference right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the current implementation, first you cut the z-coordinate lane_coords["xyz_right"][:, :2]
and later in the transform method you stack it back np.vstack((points[:num_dims, :], np.ones(points.shape[1])))
. With this we can save the one cut, the np.ones creation, the stack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way of doing this would be to only use the first 2x2 of the matrix (only XY) in the semantic rasterizer. My issue with setting 1 here is that we're removing information in a very hidden part of the code, which may render debugging problematic in the future (also considering there is a cache system in between)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. You can move it to the semantic rasterizer method; before the dot product calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea also :) Today was quite busy, but I should be able to work on this tomorrow (hopefully)
@@ -174,7 +177,8 @@ def get_crosswalk_coords(self, element_id: str) -> dict: | |||
traffic_element.geo_frame, | |||
) | |||
|
|||
return {"xyz": xyz} | |||
xyz[:, -1] = 1.0 | |||
return {"xyz": xyz.T} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see the point of caching this to avoid stack at runtime, but we may still want to include either the two lanes or at least the length of the first, so that we can always unpack the two apart (I'm thinking about centre line support right now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cheapest/easiest solution if you add the length of the first line. I think map_api
should handle the centerline calculation as well (cachable).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I agree on that and I'm fine with having the length included
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One note: I changed the returned xyz
format to xyz.T
.
xy_left = cv2_subpixel(transform_points(lane_coords["xyz_left"][:, :2], world_to_image_space)) | ||
xy_right = cv2_subpixel(transform_points(lane_coords["xyz_right"][:, :2], world_to_image_space)) | ||
lanes_area = np.vstack((xy_left, np.flip(xy_right, 0))) # start->end left then end->start right | ||
lanes_xy = cv2_subpixel(world_to_image_space.dot(lane_coords["xyz"]).T[:, :2]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using transform
or transform_transpose
functions here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seemed a bit complicated. Transposes, vstack, np.ones, cut z-axis, etc. I did not want to break other parts of the code by modifying those methods.
(Feel free to correct anything you want.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you're perfectly right about that. Let me see if we can also handle this case there (same len for matrix and points)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did these modifications only to save as many CPU cycles as I possibly can. I did not consider long term usability, I only care about speeding up for the competition, so it is fine if you drop all of or part of this PR.
render_semantic_map is the bottleneck when using a low count of history_frames. |
did you compare this against #196? |
thanks for pointing to that PR. It does even better once the caching is done: 52 ms ± 4.77 ms per loop (mean ± std. dev. of 7 runs, 10 loops each) no changes 32.9 ms ± 17.2 ms per loop (mean ± std. dev. of 7 runs, 10 loops each) PR #196 after caching: timings are for the full dataset loading (448x224 raster, 0 history frames) so the speedups are normalized to include all other operations such as box_rasterizer as well) |
I achieved ~ 7-8% speedup with these modifications.