Giter VIP home page Giter VIP logo

Comments (11)

mmatl avatar mmatl commented on May 30, 2024

Hi Henry,

I'm not seeing that behavior anywhere on my machine. I didn't implement any multithreading in my load code, so if it's happening, it's happening in trimesh. Can you give me an example of the mesh file you're trying to load?

from pyrender.

henryclever avatar henryclever commented on May 30, 2024

Hi Matt,

Here's my code. When I comment out the second line (the pyrender command) but keep the trimesh command, it appears to only use up a single core of my CPU as expected.

tm = trimesh.base.Trimesh(vertices=smpl_vertices, faces=smpl_faces)
smpl_mesh = pyrender.Mesh.from_trimesh(tm, material=self.human_mat, wireframe = True)

zip file with numpy arrays for faces and vertices below:
verts_faces.zip

There are about 7000 vertices and a similar number of faces.

Henry

from pyrender.

mikedh avatar mikedh commented on May 30, 2024

Hey Henry, that mesh looks pretty reasonable on my computer, I didn't notice any core-maxing with the latest versions of trimesh/pyrender. What does it look like if you try running it with a profiler, like cProfile or pyinstrument?

In [1]: import numpy as np

In [2]: import trimesh

In [3]: v = np.load('smpl_vertices.npy')

In [4]: f = np.load('smpl_faces.npy')

In [5]: %timeit m = trimesh.Trimesh(v, f)
The slowest run took 10.21 times longer than the fastest. This could mean that an intermediate result is being cached.
100 loops, best of 3: 2.67 ms per loop

In [6]: m = trimesh.Trimesh(v, f)

In [8]: import pyrender

In [9]: %timeit p = pyrender.Mesh.from_trimesh(m)
The slowest run took 25.02 times longer than the fastest. This could mean that an intermediate result is being cached.
1000 loops, best of 3: 243 µs per loop

from pyrender.

henryclever avatar henryclever commented on May 30, 2024

Hi,
So I think I have found how I can reproduce the problem better, but I have not solved it and it does not appear to happen when using pyrender and trimesh in isolation from the rest of my program.

If I don't regenerate the mesh and just use it as you did, there is no problem. However, each time I loop I'm regenerating the mesh vertices and faces using the SMPL human parametrization. If I print out the mesh verts and faces to the terminal, use the trimesh command, etc, there is no extra CPU usage. But If I regenerate the mesh vertices and use Mesh.from_trimesh() concurrently, the problem exists.

Here are screenshots showing a hacky profiling:
Normal case:
only_trimesh_command

Smpl regen + trimesh + pyrender: (problem case, it looks ludicrous on the 32 core machine)
both_trimesh_and_pyrender

So weird.

Henry C.

from pyrender.

henryclever avatar henryclever commented on May 30, 2024

Anyway, thanks to Matt and Mike for the quick responses!
Henry C.

from pyrender.

mikedh avatar mikedh commented on May 30, 2024

Oh interesting. One thing it could be is auto-generated vertex normals requested in the from_trimesh call. Those are calculated with a scipy sparse matrix which is suspiciously fast and heavily parallelized. Maybe try with smooth=False and see if it still happens? IE:

smpl_mesh = pyrender.Mesh.from_trimesh(tm, material=self.human_mat, wireframe = True, smooth=False)

from pyrender.

henryclever avatar henryclever commented on May 30, 2024

Mike,
Interesting thought.

I tried setting smooth to False- doesn't work, though. Same problem.

Henry C.

from pyrender.

henryclever avatar henryclever commented on May 30, 2024

Also,

I tried changing the vertex positions manually every loop rather than having the SMPL parameterization do it - by adding a very small increment to the float value of each vertex x,y,z of 0.00001. In that case, the problem goes away. So it appears it's not just a matter of recreating arbitrary vertices and faces, rather it's something to do with the SMPL calculation.

Henry C.

from pyrender.

mmatl avatar mmatl commented on May 30, 2024

Closing this as it seems to not be an issue that can be fixed in pyrender.

from pyrender.

LogWell avatar LogWell commented on May 30, 2024

I have to render a series of meshes[path_objs]. When I do as the following, memory grows until it crashes. How to avoid this situation?

Memory growth seems to be related to mesh_pr = pyrender.Mesh.from_trimesh(mesh_tri).

THANKS~

scene = pyrender.Scene(bg_color=[1.0, 1.0, 1.0, 1.0], ambient_light=(0.5, 0.5, 0.5))

cam = pyrender.PerspectiveCamera(yfov=np.pi / 4., znear=0.05, zfar=5.0, aspectRatio=1.0)
scene.add(cam, pose=np.eye(4))

r = pyrender.OffscreenRenderer(viewport_width=1080,
                               viewport_height=1080,
                               point_size=1.0)

for path_obj in path_objs:
    mesh_tri = trimesh.load(path_obj, process=False)
    mesh_pr = pyrender.Mesh.from_trimesh(mesh_tri)
    node_mesh = pyrender.Node(mesh=mesh_pr)
    scene.add_node(node_mesh)

    color, depth = r.render(scene)
    imageio.imwrite(path_img, color)
    imageio.imwrite(path_img[:-4] + '_d.png', (depth * 1000).astype(np.uint16))

    scene.remove_node(node_mesh)

from pyrender.

monacv avatar monacv commented on May 30, 2024

@mikedh could you please let me know where you downloaded the smpl_vertices.npy from?

I cannot find it on SMPL website Download page
Screenshot from 2021-03-23 21-45-23

from pyrender.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.