TensorFlow Graphics
raw JSON → 2021.12.3 verified Sat May 09 auth: no python maintenance
A library that provides well-defined, reusable and cleanly written graphics ops and utility functions for TensorFlow, enabling differentiable graphics rendering, transformations, and 3D geometry operations. The latest version on PyPI is 2021.12.3. Releases are infrequent and the library may lag behind TensorFlow releases.
pip install tensorflow-graphics Common errors
error ModuleNotFoundError: No module named 'tensorflow_graphics' ↓
cause Library not installed or installed under a different name.
fix
Run: pip install tensorflow-graphics
error ImportError: cannot import name 'TriangleMesh' from 'tensorflow_graphics' ↓
cause Incorrect import path; TriangleMesh is not in the top-level module.
fix
Use: from tensorflow_graphics.geometry.representation.mesh import TriangleMesh
error AttributeError: module 'tensorflow_graphics' has no attribute 'rendering' ↓
cause Rendering module may not be installed if 'tensorflow-graphics' was installed via minimal extras.
fix
Ensure full install: pip install tensorflow-graphics[all]
error TypeError: Expected int32, got list containing Tensors of type 'float32' ↓
cause Function expecting integer tensor but passed float; face indices must be integer type.
fix
Cast face indices to tf.int32 before passing: tf.cast(faces, tf.int32)
Warnings
breaking TensorFlow Graphics v2021.x may not be compatible with TensorFlow 2.x later than 2.9. Installing newer tensorflow versions can cause import errors or broken ops. ↓
fix Pin tensorflow to 2.8-2.9 or use the nightly build from GitHub.
deprecated The library has not been actively updated since 2021. Some modules like 'rendering' are experimental and may have breaking changes if future releases occur. ↓
fix Use with caution; consider alternative libraries for actively maintained features.
gotcha Expects TensorFlow eager mode by default; using tf.function on graphics ops may cause unexpected graph tracing errors if the ops have side effects or use Python control flow. ↓
fix Wrap only pure TF ops inside tf.function; keep graphics-specific ops in eager mode.
gotcha Mesh face indices must be in counter-clockwise order for correct normal computation, but the library does not validate orientation. ↓
fix Ensure face winding is consistent; use tfg.geometry.representation.mesh.normals functions to verify.
Install
pip install tensorflow-graphics==2021.12.3 Imports
- TriangleMesh wrong
from tensorflow_graphics.mesh import TriangleMeshcorrectfrom tensorflow_graphics.geometry.representation.mesh import TriangleMesh - perspective wrong
from tensorflow_graphics.transforms import perspectivecorrectfrom tensorflow_graphics.geometry.transformation import perspective - render wrong
from tensorflow_graphics.render import rasterizercorrectfrom tensorflow_graphics.rendering import rasterizer
Quickstart
import tensorflow as tf
import tensorflow_graphics as tfg
from tensorflow_graphics.geometry.representation.mesh import TriangleMesh
# Create a simple mesh (cube)
vertices = tf.constant([
[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0],
[0, 0, 1], [1, 0, 1], [1, 1, 1], [0, 1, 1]
], dtype=tf.float32)
faces = tf.constant([
[0, 1, 2], [2, 3, 0],
[1, 5, 6], [6, 2, 1],
[5, 4, 7], [7, 6, 5],
[4, 0, 3], [3, 7, 4],
[3, 2, 6], [6, 7, 3],
[4, 5, 1], [1, 0, 4]
], dtype=tf.int32)
mesh = TriangleMesh(vertices=vertices, indices=faces)
print('Mesh vertex count:', tf.shape(mesh.vertices)[0].numpy())