Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the preprocessed data does’nt has attribute [pos_normals] or [neg_normals] #5

Closed
QtEngineer opened this issue Mar 19, 2022 · 12 comments

Comments

@QtEngineer
Copy link

QtEngineer commented Mar 19, 2022

I tried to set [use_precomputed]=false but error still happened cause of :

if sdf_samples_with_normals is None:
    if use_precomputed_init:
        return torch.from_numpy(np.load(initialization_file))  
    else:
        npz = np.load(sdf_filename)
        pos_tensor = deep_sdf.data.remove_nans(torch.from_numpy(np.concatenate([npz["pos"], npz["pos_normals"]], axis=1))).numpy()
        neg_tensor = deep_sdf.data.remove_nans(torch.from_numpy(np.concatenate([npz["neg"], npz["neg_normals"]], axis=1))).numpy()

#----------

import numpy as np
cat=np.load('/user-data/patchnets-master/code/data/SdfSamples/ShapeNetV2/02691156/1a29042e20ab6f005e9e2656aff7dd5b.npz')
cat.files
['pos', 'neg']

@edgar-tr
Copy link
Owner

edgar-tr commented Mar 19, 2022 via email

@QtEngineer
Copy link
Author

Thank you so much! Now I can successfully generate correct data .
However, I noticed that some npz files have suffix of "rejected" because of :

if (wrong_ratio > rejection_criteria_obs || bad_tri_ratio > rejection_criteria_tri) {
std::cout << "mesh rejected" << std::endl;
npyFileName = npyFileName + "____rejected.npz";
//return 1;
}
(in ProprocessMesh.cpp )
It will not happen when using cpp files included in DeepSDF.

I'm confused about it and I want to know whether the npz files were generated correctly.
In addition ,if there is no errors ,should I use these rejected.npz files to train or test , or delete them?

@edgar-tr
Copy link
Owner

edgar-tr commented Mar 22, 2022 via email

@edgar-tr
Copy link
Owner

edgar-tr commented Mar 22, 2022 via email

@QtEngineer
Copy link
Author

Thanks a lot! Up till now I have generated 1110 npz files used sv2_lamps_json and there is 6 rejected mesh. And I generated a part of sofa meshes (about 643 with 13 were rejected).I think it will not make a big difference?

Besides ,I met a problem when I tried to train with some specific npz files(not rejected mesh) ,There is a 【 RuntimeWarning: invalid value encountered in arcsin 】because of :
def _get_euler_angles_from_rotation_matrix(rotation_matrix):
if np.abs(rotation_matrix[2,0]) != 1.:
beta = -np.arcsin(rotation_matrix[2,0])
cosBeta = np.cos(beta)
return np.array([np.arctan2(rotation_matrix[2,1], rotation_matrix[2,2]), beta, np.arctan2(rotation_matrix[1,0], rotation_matrix[0,0])])

I guess it is because the value of rotation_matrix[2,0] is outside the range of [- 1, 1] and it cause an error:
def remove_nans(tensor):
tensor_nan = torch.isnan(tensor[:, 3])
tensor_nan_fixed = torch.isnan(tensor).any(-1)
if (tensor_nan != tensor_nan_fixed).any():
import ipdb; ipdb.set_trace()
return tensor[~tensor_nan, :]
The program paused because 【tensor_nan != tensor_nan_fixed】( for Ipython Debugger ). How can I fix it?

@edgar-tr
Copy link
Owner

edgar-tr commented Mar 22, 2022 via email

@QtEngineer
Copy link
Author

Thank you so much! I replaced ipdb line and trained model successfully. I trained about 900 ShpenetV2obj with 300 epoch , but after reconstructing and evaluating,the result was not so good, (The average chamfer distance is as more than 1.0)
I noticed that while reconstructing ,the code does not use specs and sdffile:
(in reconstruct.py)
(Referrence:)
err, latent = reconstruct(
decoder,
int(args.iterations),
mixture_latent_size,
data_sdf,
0.01, # [emp_mean,emp_var],
0.1,
num_samples=8000,
lr=5e-3,
l2reg=True,
)
(Define:)
def reconstruct(
...,
specs=None,
sdf_filename=None,):

I am not sure whether it will cause error.

@edgar-tr
Copy link
Owner

edgar-tr commented Mar 29, 2022 via email

@edgar-tr
Copy link
Owner

edgar-tr commented Mar 29, 2022 via email

@QtEngineer
Copy link
Author

Thank you so much! I managed to convert latent codes into meshes by using functioon visualize_parts_individually (patches),which generated .obj followed train_split.json.
But when I tried to run useful_scripts.py to Evaluation, an error occured :
error:
......,
File "useful_scripts.py", line 105, in visualize_mixture
_, latent_code = sdf_to_latent(sdf, full_loss=True, latent_init=latent_code, num_samples=3072, num_iterations=1000, sdf_filename=sdf_filename, lr=0.001, adjust_lr_every=200, decrease_lr_by=2)
UnboundLocalError: local variable 'latent_code' referenced before assignment

The function evaluate_patch_network_metrics() includs visualize_mixture()( # full object), in visualize_mixture:(Line 105)
train_latent_codes = torch.load(results_folder + "LatentCodes/" + checkpoint + ".pth")
for i, mesh in enumerate(mesh_files):
if mesh in train_split:
train_id = train_split.index(mesh)
latent_code = train_latent_codes["latent_codes"][train_id,0,:].unsqueeze(0).clone().cuda()
else:
sdf_filename = data_source + mesh + ".npz"
sdf = np.load(sdf_filename)
sdf = (torch.from_numpy(sdf["pos"]), torch.from_numpy(sdf["neg"]))
_, latent_code = sdf_to_latent(sdf, full_loss=True, latent_init=latent_code, num_samples=3072, num_iterations=1000, sdf_filename=sdf_filename, lr=0.001, adjust_lr_every=200, decrease_lr_by=2)

It seems that the variable [latent_code] does not declared at (latent_init=latent_code) in the else branch. How can I fix it?

@edgar-tr
Copy link
Owner

edgar-tr commented Apr 1, 2022 via email

@QtEngineer
Copy link
Author

thanks a lot !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants