Comments (4)
Well, this is much tougher than the main transformation ! It involves the function atan2 it's not trivial ;)
After a quick google search, you can try a variation of this proposed algorithm : https://www.learnopencv.com/rotation-matrix-to-euler-angles/
Fortunately, the atan2 function is available in pytorch ! see here https://pytorch.org/docs/stable/torch.html#torch.atan2
Good luck,
from sfmlearner-pytorch.
your code is unfortunately not differentiable becasue you create a new FloatTensor.
You should just have theta = torch.stack([x,y,z])
Other than that, the code is not very parallel, but I guess with the singular check, you cannot do much better. the sy can be computed batchwise however
def pose_mat2vec(Rt):
t_all = Rt[:,:,-1]
R_all = Rt[:,:,:3]
sy = R[:,0,0]^2 + R[:,1,0]^2
y_all = torch.atan2(-R[:,2,0], sy)
theta = []
for (R,t, s) in zip(R_all,t_all, sy, y_all):
singular = s < 1e-6
if not singular :
x = torch.atan2(R[2,1] , R[2,2])
z = torch.atan2(R[1,0], R[0,0])
else :
x = torch.atan2(-R[1,2], R[1,1])
z = 0
theta.append(torch.stack([x, y, z]))
theta = torch.stack(theta)
pose_all = torch.cat([theta,t_all], dim=1)
return pose_all
from sfmlearner-pytorch.
Thank you very much for your quick reply.
from sfmlearner-pytorch.
I wrote this to convert mat to vec in pytorch. Could you please have a look at it and let me know if it is wrong or there is anyway to improve the performance.
def pose_mat2vec(Rt):
t_all = Rt[:,:,-1]
R_all = Rt[:,:,:3]
pose_all = []
for R,t in zip(R_all,t_all):
sy = torch.sqrt(R[0,0] * R[0,0] + R[1,0] * R[1,0])
singular = sy < 1e-6
if not singular :
x = torch.atan2(R[2,1] , R[2,2])
y = torch.atan2(-R[2,0], sy)
z = torch.atan2(R[1,0], R[0,0])
else :
x = torch.atan2(-R[1,2], R[1,1])
y = torch.atan2(-R[2,0], sy)
z = 0
theta = torch.FloatTensor([x, y, z]).cuda(0)
pose_6 = torch.cat((theta, t),0)
pose_all.append(pose_6)
pose_all = torch.stack(pose_all,0)
return pose_all
Thanks a lot.
from sfmlearner-pytorch.
Related Issues (20)
- Query regarding depth map. HOT 2
- Large Errors on Pose Prediction Network HOT 3
- why the gpu memory cost of tensorflow version is larger than pytorch version HOT 2
- Weird results from pretrained model on KITTI images HOT 4
- Question about using oxts data HOT 1
- Cannot run `train.py` with nohup HOT 2
- imread during inference load the image as uint8 HOT 4
- How About the Flops, fps and parameter of this model? HOT 1
- regarding the predicted depth map during inverse warp HOT 2
- How to visualize the warped image (ref_img_wapred) HOT 2
- regarding inverse_warping HOT 10
- Is the image input of depth network fixed? HOT 2
- Question about diff
- How to load training dataset
- Regarding the depth used for generating target image HOT 5
- Question about the poses predicted by the posenet HOT 2
- about the pose scale HOT 2
- difference of the predicted translation and ground truth vectors HOT 7
- samples in test_files_eigen dont exist in the KITTI
- Seq 10 is not in the test_secens.txt HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sfmlearner-pytorch.