ReshotAI / gaussian-splatting-blender-addon

https://www.lingosub.com
423 stars 47 forks source link

ValueError: cannot reshape array of size 0 into shape #43

Open kaixin-bai opened 4 hours ago

kaixin-bai commented 4 hours ago

while import 3dgs file, i got error below:

Traceback (most recent call last):
  File "/home/kb/.config/blender/4.2/scripts/addons/blender-addon/__init__.py", line 80, in execute
    features_extra = features_extra.reshape((N, 3, 15))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: cannot reshape array of size 0 into shape (36426,3,15)

I also upload my ply file here, hopefully could solve this problem.

3dgs_tum_dataset.zip

kaixin-bai commented 4 hours ago

I checked the file, and find that the problem is because that there's no attribute name start with "ftest", the testing code is below:

        extra_f_names = [p.name for p in plydata.elements[0].properties if p.name.startswith("f_rest_")]
        extra_f_names = sorted(extra_f_names, key = lambda x: int(x.split('_')[-1]))

        features_extra = np.zeros((N, len(extra_f_names)))
        for idx, attr_name in enumerate(extra_f_names):
            features_extra[:, idx] = np.asarray(plydata.elements[0][attr_name])
        features_extra = features_extra.reshape((N, 3, 15))
In [2]: from plyfile import PlyData, PlyElement

In [3]: filepath = "/home/kb/Downloads/3dgs_tum_dataset.ply"

In [4]: plydata = PlyData.read(filepath)

In [5]: import numpy as np

In [6]: np.asarray(plydata.elements[0]["x"])
Out[6]: 
array([-0.1656777 , -1.6436013 , -0.7537645 , ...,  0.44135675,
       -0.61030936, -0.46284845], dtype=float32)

In [7]: extra_f_names = [p.name for p in plydata.elements[0].properties if p.name.startswith("f_rest_")]

In [8]: extra_f_names = sorted(extra_f_names, key = lambda x: int(x.split('_')[-1]))

In [9]: extra_f_names
Out[9]: []

In [10]: plydata.elements[0].properties
Out[10]: 
(PlyProperty('x', 'float'),
 PlyProperty('y', 'float'),
 PlyProperty('z', 'float'),
 PlyProperty('nx', 'float'),
 PlyProperty('ny', 'float'),
 PlyProperty('nz', 'float'),
 PlyProperty('f_dc_0', 'float'),
 PlyProperty('f_dc_1', 'float'),
 PlyProperty('f_dc_2', 'float'),
 PlyProperty('opacity', 'float'),
 PlyProperty('scale_0', 'float'),
 PlyProperty('scale_1', 'float'),
 PlyProperty('scale_2', 'float'),
 PlyProperty('rot_0', 'float'),
 PlyProperty('rot_1', 'float'),
 PlyProperty('rot_2', 'float'),
 PlyProperty('rot_3', 'float'))