autonomousvision / occupancy_networks

This repository contains the code for the paper "Occupancy Networks - Learning 3D Reconstruction in Function Space"
https://avg.is.tuebingen.mpg.de/publications/occupancy-networks
MIT License
1.5k stars 292 forks source link

sample_mesh script not working with voxel option #22

Open noamgat opened 4 years ago

noamgat commented 4 years ago

When running the sample_mesh.py script with the voxelize flags, I get the following error:

AttributeError: module 'im2mesh.utils.voxels' has no attribute 'voxelize'

In line 158 of sample_mesh.py which is:

voxels_occ = voxels.voxelize(mesh, res)

When looking at the module, I indeed see no .voxelize function, only voxelize_fill, voxelize_mesh etc. Am I missing something? What is the intended way of using this script for voxel generation?

jnyjxn commented 4 years ago

@noamgat I'm not affiliated with this work but see my fixes here.

LMescheder commented 4 years ago

Thanks for reporting the issue. I will have a look.

jnyjxn commented 4 years ago

@LMescheder If it helps, I've made all the necessary fixes in this fork.

Specifically, im2mesh/utils/binvox_rw.py and scripts/sample_mesh.py need to be changed.

YokkaBear commented 4 years ago

@jnyjxn Thank you pretty much for your fixes, they work and help me obtain the .binvox files.

iSarmad commented 4 years ago

Hi, I would like to add that I ran into problems when visualizing the custom .binvox files produced after @LMescheder's fix, the str.encodes() function uses default encoding as UTF-8 format which was causing the problem in visualizing. I changed the coding to latin-1 and things are looking good now. Below is the example with airplane model. Before: image

After image

the changes in the binvox_rw.py files look like this

for c in voxels_flat:
    if c==state:
        ctr += 1
        # if ctr hits max, dump
        if ctr==255:
            # fp.write(chr(state))
            # fp.write(chr(ctr))
            temp = chr(ctr)
            temp1 = str.encode(temp)
            fp.write(str.encode(chr(state),encoding='latin-1'))
            fp.write(str.encode(chr(ctr),encoding='latin-1'))
            ctr = 0
    else:
        # if switch state, dump
        # fp.write(chr(state))
        # fp.write(chr(ctr))
        fp.write(str.encode(chr(state),encoding='latin-1'))
        fp.write(str.encode(chr(ctr),encoding='latin-1'))
        state = c
        ctr = 1

# flush out remainders
if ctr > 0:
    # fp.write(chr(state))
    # fp.write(chr(ctr))
    fp.write(str.encode(chr(state),encoding='latin-1'))
    fp.write(str.encode(chr(ctr),encoding='latin-1'))