Mechanics functions with end-to-end support for machine learning developers, written in Ivy
Project description
Mechanics functions with end-to-end support for machine learning developers, written in Ivy.
Contents
Overview
What is Ivy Mechanics?
Ivy mechanics provides functions for conversions of orientation, pose, and positional representations, as well as frame-of-reference transformations, and other more applied functions. Check out the docs for more info!
The library is built on top of the Ivy machine learning framework. This means all functions simultaneously support: Jax, Tensorflow, PyTorch, MXNet, and Numpy.
Ivy Libraries
There are a host of derived libraries written in Ivy, in the areas of mechanics, 3D vision, robotics, gym environments, neural memory, pre-trained models + implementations, and builder tools with trainers, data loaders and more. Click on the icons below to learn more!
Quick Start
Ivy mechanics can be installed like so: pip install ivy-mech
To quickly see the different aspects of the library, we suggest you check out the demos! We suggest you start by running the script run_through.py, and read the “Run Through” section below which explains this script.
For more interactive demos, we suggest you run either target_facing_rotation_matrix.py or polar_to_cartesian_coords.py in the interactive demos folder.
Run Through
We run through some of the different parts of the library via a simple ongoing example script. The full script is available in the demos folder, as file run_through.py. First, we select a random backend framework to use for the examples, from the options ivy.jax, ivy.tensorflow, ivy.torch, ivy.mxnd or ivy.numpy, and use this to set the ivy backend framework.
import ivy
from ivy_demo_utils.framework_utils import choose_random_framework
ivy.set_framework(choose_random_framework())
Orientation Module
The orientation module is the most comprehensive, with conversions to and from all euler conventions, quaternions, rotation matrices, rotation vectors, and axis-angle representations.
A few of the orientation functions are outlined below.
# rotation representations
# 3
rot_vec = ivy.array([0., 1., 0.])
# 3 x 3
rot_mat = ivy_mech.rot_vec_to_rot_mat(rot_vec)
# 3
euler_angles = ivy_mech.rot_mat_to_euler(rot_mat, 'zyx')
# 4
quat = ivy_mech.euler_to_quaternion(euler_angles)
# 3, 1
axis, angle = ivy_mech.quaternion_to_axis_and_angle(quat)
# 3
rot_vec_again = axis * angle
Pose Module
The pose representations mirror the orientation representations, with the addition of 3 values to represent the cartesian position. Again, we give some examples below.
# pose representations
# 3
position = ivy.ones_like(rot_vec)
# 6
rot_vec_pose = ivy.concatenate((position, rot_vec), 0)
# 3 x 4
mat_pose = ivy_mech.rot_vec_pose_to_mat_pose(rot_vec_pose)
# 6
euler_pose = ivy_mech.mat_pose_to_euler_pose(mat_pose)
# 7
quat_pose = ivy_mech.euler_pose_to_quaternion_pose(euler_pose)
# 6
rot_vec_pose_again = ivy_mech.quaternion_pose_to_rot_vec_pose(quat_pose)
Position Module
The position module includes functions for converting between positional representations, such as cartesian and polar conventions, and for applying frame-of-reference transformations to cartesian co-ordinates.
We give some examples for conversion of positional representation below.
# conversions of positional representation
# 3
cartesian_coord = ivy.random_uniform(0., 1., (3,))
# 3
polar_coord = ivy_mech.cartesian_to_polar_coords(
cartesian_coord)
# 3
cartesian_coord_again = ivy_mech.polar_to_cartesian_coords(
polar_coord)
Assuming cartesian form, we give an example of a frame-of-reference transformations below.
# cartesian co-ordinate frame-of-reference transformations
# 3 x 4
trans_mat = ivy.random_uniform(0., 1., (3, 4))
# 4
cartesian_coord_homo = ivy_mech.make_coordinates_homogeneous(
cartesian_coord)
# 3
trans_cartesian_coord = ivy.matmul(
trans_mat, ivy.expand_dims(cartesian_coord_homo, -1))[:, 0]
# 4
trans_cartesian_coord_homo = ivy_mech.make_coordinates_homogeneous(
trans_cartesian_coord)
# 4 x 4
trans_mat_homo = ivy_mech.make_transformation_homogeneous(
trans_mat)
# 3 x 4
inv_trans_mat = ivy.inv(trans_mat_homo)[0:3]
# 3
cartesian_coord_again = ivy.matmul(
inv_trans_mat, ivy.expand_dims(trans_cartesian_coord_homo, -1))[:, 0]
Interactive Demos
In addition to the run through above, we provide two further demo scripts, which are more visual and interactive, and are each built around a particular function.
Rather than presenting the code here, we show visualizations of the demos. The scripts for these demos can be found in the interactive demos folder.
Target Facing Rotation Matrix
The first demo uses the method ivy_mech.target_facing_rotation_matrix to dynamically track a moving target plant pot with a camera, as shown below:
Polar to Cartesian Co-ordinates
The second demo uses the method ivy_mech.polar_to_cartesian_coords to convert a polar depth image acquired from an omni-directional camera into cartesian co-ordinates, enabling the surrounding geometry to be represented as a point cloud, for interactive visualization.
Get Involed
We hope the functions in this library are useful to a wide range of machine learning developers. However, there are many more areas of mechanics which could be covered by this library.
If there are any particular mechanics functions you feel are missing, and your needs are not met by the functions currently on offer, then we are very happy to accept pull requests!
We look forward to working with the community on expanding and improving the Ivy mechanics library.
Citation
@article{lenton2021ivy, title={Ivy: Unified Machine Learning for Inter-Framework Portability}, author={Lenton, Daniel and Pardo, Fabio and Falck, Fabian and James, Stephen and Clark, Ronald}, journal={arXiv preprint arXiv:2102.02886}, year={2021} }
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ivy-mech-1.1.9.tar.gz
.
File metadata
- Download URL: ivy-mech-1.1.9.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4db46c74327a9d140212a4d09b38eaf84f41b7a565591c43de6deb6f3097b3de |
|
MD5 | c989982b690d00ff048c3c347a0594e3 |
|
BLAKE2b-256 | 9bb515db2cce9fc5ba8aa0cb74a04c3ed10d982136048e3fe3dbd0abfe04c9cb |
File details
Details for the file ivy_mech-1.1.9-py3-none-any.whl
.
File metadata
- Download URL: ivy_mech-1.1.9-py3-none-any.whl
- Upload date:
- Size: 23.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7456d3a79ddce00b17b89dd029513ee4dd1993d81aa564e27382400c745024f |
|
MD5 | 859125372ba597dcdb285e0e098e648a |
|
BLAKE2b-256 | e64d051f47f641bf19b19b085b72983b97bac2e873b66bfdc467bb2ede616b14 |