Git Product home page Git Product logo

Comments (7)

playertr avatar playertr commented on September 16, 2024 9

Here's my script:

"""
convert_meshes.py
Process the .obj files and make them waterproof and simplified.
"""
import os
import subprocess
from tqdm import tqdm
from multiprocessing import Pool, cpu_count

GRASPDIR = "/path/to/acronym/data/grasps/"
OBJDIR = "/path/to/acronym/data/shapenetsem/models-OBJ/"
MANIFOLD_PATH = "/path/to/Manifold/build/manifold"
SIMPLIFY_PATH = "/path/to/Manifold/build/simplify"

## Grab the object file names from the grasp directory
hashes = []
for fname in os.listdir(GRASPDIR):
    tokens = fname.split("_")
    assert(len(tokens) == 3)
    hashes.append(tokens[1])

## Define function to process a single file
def process_hash(h):
    """Process a single object file by calling a subshell with the mesh processing script.

    Args:
        h (string): the hash denoting the file type
    """
    obj = OBJDIR + 'models/' + h + ".obj"

    if not os.path.isfile(obj):
        return
    
    # Waterproof the object
    temp_name = f"temp.{h}.watertight.obj"
    completed = subprocess.run(["timeout", "-sKILL", "30", MANIFOLD_PATH, obj, temp_name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

    if completed.returncode != 0:
        print(f"Skipping object (manifold failed): {h}")
        return
            
    # Simplify the object
    outfile = OBJDIR + "simplified/" + h + ".obj"
    completed = subprocess.run([SIMPLIFY_PATH, "-i", temp_name, "-o", outfile, "-m", "-r", "0.02"],  stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

    if completed.returncode != 0:
        print(f"Skipping object (simplify failed): {h}")
        
## Issue the commands in a multiprocessing pool
with Pool(cpu_count()-2) as p:
    examples = list(
        tqdm(
            p.imap_unordered(process_hash, hashes),
            total=len(hashes)
        )
    )

from acronym.

seann999 avatar seann999 commented on September 16, 2024

Only processing the 7897 models mentioned in the acronym dataset (the IDs in the filenames) instead of all 24980 in the original ShapeNetSem seems to have worked.

from acronym.

ymxlzgy avatar ymxlzgy commented on September 16, 2024

Only processing the 7897 models mentioned in the acronym dataset (the IDs in the filenames) instead of all 24980 in the original ShapeNetSem seems to have worked.

Do you solve the stuck problem?

from acronym.

clemense avatar clemense commented on September 16, 2024

What exactly is the problem that you are referring to?

from acronym.

ymxlzgy avatar ymxlzgy commented on September 16, 2024

What exactly is the problem that you are referring to?

I use this script but only obtaining about 1000 meshes because this script can get stuck in the middle of the mesh generation. How can I solve it?

from acronym.

clemense avatar clemense commented on September 16, 2024

You could increase the timeout duration. It's currently set to 10 seconds.

from acronym.

ymxlzgy avatar ymxlzgy commented on September 16, 2024

You could increase the timeout duration. It's currently set to 10 seconds.

I have extended it even to 1000... But I only got 6880 objects although it indeed increases. Could you upload the generated obj file to google drive to solve this problem once for all?

from acronym.

Related Issues (16)

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.