Download code/alpamayo2_super/geometry/coordinates.py from changh95/Alpamayo2-Super-p300x2: direct link, hf CLI and curl.
- Browser
- Download file 1.92 kB
-
https://huggingface.co/changh95/Alpamayo2-Super-p300x2/resolve/main/code/alpamayo2_super/geometry/coordinates.py
- Command line
-
hf download hf://changh95/Alpamayo2-Super-p300x2/code/alpamayo2_super/geometry/coordinates.py
-
curl -L -o coordinates.py https://huggingface.co/changh95/Alpamayo2-Super-p300x2/resolve/main/code/alpamayo2_super/geometry/coordinates.py
1.92 kB
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | |
| # SPDX-License-Identifier: Apache-2.0 | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| import torch | |
| def xyzrot_to_corners(xyz: torch.Tensor, rot: torch.Tensor, dims: torch.Tensor) -> torch.Tensor: | |
| """Get the corners of a 3d bounding box. The implementation interprets the tail dimensions as | |
| the meaningful ones, and everything else effectively as a batch dimension. | |
| Args: | |
| xyz: ...x3 location of the center of the bounding box | |
| rot: ...x3x3 orientation of the bounding box represented as a rotation matrix | |
| dims: ...x3 dimensions of the bounding box (length, width, height) | |
| Returns: | |
| corns: ...x8x3 corners of the bounding box. The first 4 points are the bottom | |
| corners and the next 4 are the top corners. | |
| """ | |
| corns = torch.tensor( | |
| [ | |
| [-0.5, -0.5, -0.5], | |
| [0.5, -0.5, -0.5], | |
| [0.5, 0.5, -0.5], | |
| [-0.5, 0.5, -0.5], | |
| [-0.5, -0.5, 0.5], | |
| [0.5, -0.5, 0.5], | |
| [0.5, 0.5, 0.5], | |
| [-0.5, 0.5, 0.5], | |
| ], | |
| device=xyz.device, | |
| dtype=xyz.dtype, | |
| ) | |
| # scale | |
| corns = dims.unsqueeze(-2) * corns | |
| # rotate | |
| corns = (rot.unsqueeze(-3) @ corns.unsqueeze(-1)).squeeze(-1) | |
| # translate | |
| corns = corns + xyz.unsqueeze(-2) | |
| return corns | |