czq142857 / IM-NET-pytorch

PyTorch 1.2 implementation of IM-NET.
Other
197 stars 27 forks source link

Train imnet using other data #22

Closed lun22u closed 2 years ago

lun22u commented 2 years ago

Dear ZhiqinChen: Thank you for sharing your code and I'm sorry to bother you And I'm sorry for my suck English, if you have difficult in reading my questions, I can email you in Chinese. I met some problems when preparing training data. I want to use IMNet-pytorch version to train my model, using dataset named PartNet V0(https://shapenet.org/download/parts), I met some problems when preprocessing models and pictures: I have seen early questions about acquiring binvox file in your project, and use command: "binvox -bb -0.5 -0.5 -0.5 0.5 0.5 0.5 -d 64 -e input.obj" to get binvox file ,then I use vox2pointvaluepair_from_binvox to get h5 file of voxel, because I don't know how to get voxels with 256^3 resolution.(I have also seen HSP data, its 'b' voxels seem meaningless, so I have no idea about how to creat my own mat file.) Then I use 3_gather_img to gather my rendering views of models (although every model has only one view and I hope it won't influent my training work.) so here are my questions: 1.Can I just use 64^3 resolution binvox file to train pytorch version IMNet? 2.When I prepareing rendering views, I found my png files have no alphe channel, can I use these png files and how to rewrite the code? If not , how can I get the right png files for training work? Thank you and I'm sorry about bothering you again. Thanks Zh T

czq142857 commented 2 years ago
  1. Yes, but you need to change the line
    self.data_points = (data_dict['points_'+str(self.sample_vox_size)][:].astype(np.float32)+0.5)/256-0.5

    To

    self.data_points = (data_dict['points_'+str(self.sample_vox_size)][:].astype(np.float32)+0.5)/self.sample_vox_size-0.5

    I haven't tried it myself so let me know if there is a bug.

If you need 256^3 voxels, just use binvox to generate them. You only need to change the shape loader to load binvox files instead of mat files. You can do that using binvox_rw.py:

voxel_model_256 = binvox_rw.read_as_3d_array("example.binvox").data.astype(np.uint8)

Note that you need to make sure the top direction of the shape is pointing Y(j) positive direction. Otherwise, the z-carving in the code does not work.

  1. You can use image files without alpha channels.
    img = cv2.imread("example.png")
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    hdf5_file["pixels"][idx,t,:,:] = img
lun22u commented 2 years ago

I'm very grateful for your replying.So: 1.If I want to use 256^3 voxel, can I just change command: binvox -bb -0.5 -0.5 -0.5 0.5 0.5 0.5 -d 64 -e input.obj to: binvox -bb -0.5 -0.5 -0.5 0.5 0.5 0.5 -d 256 -e input.obj 2.Considering line 89 in 3_gather_img: imgo = img[:,:,:3] which raises error when running code because my png has no alpha channel.How to rewrite this line to get imgo to run line: img = cv2.cvtColor(imgo, cv2.COLOR_BGR2GRAY) in your replying? By the way, Should I use 137x137 png to prepare my training data? I'm sorry about bothering you again. Thanks Zh T

czq142857 commented 2 years ago
  1. Yes. Remember to normalize the shapes first. The shape should be zero-centered and the diagonal of the bounding box needs to be 1.

  2. Make sure your image has 3 channels and just run cv2.cvtColor(img, cv2.COLOR_BGR2GRAY).

  3. The provided code assumes images are 137x137. But during training the images are cropped to 128x128. If you do not want to change the code, use 137x137.

lun22u commented 2 years ago

Thank you very much,now I have no problem temporarily.

lun22u commented 2 years ago

It works in training (using 256^3binvox and RGB single view image),thank you very much !

zhaoyj96 commented 1 year ago

Hello, lun22u. I want to ask how to get rendering views images used in https://github.com/czq142857/IM-NET/blob/master/point_sampling/3_gather_img.py? Are they generated from https://github.com/czq142857/IM-NET/blob/master/point_sampling/2_test_hdf5.py?

lun22u commented 1 year ago

no,you need to download dataset from shapenet.org or prepare your own dataset

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2023年4月18日(星期二) 中午1:32 收件人: @.>; 抄送: @.>; "State @.>; 主题: Re: [czq142857/IM-NET-pytorch] Train imnet using other data (Issue #22)

Hello, lun22u. I want to ask how to get rendering views images used in https://github.com/czq142857/IM-NET/blob/master/point_sampling/3_gather_img.py? Are they generated from https://github.com/czq142857/IM-NET/blob/master/point_sampling/2_test_hdf5.py?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you modified the open/close state.Message ID: @.***>

zhaoyj96 commented 1 year ago

Thank you for your reply, lun22u. I have successfully rendered my multi-view images. But there is a problem in normalizing the voxels. Could you tell me how to make the voxel centered and its diagonal of the bounding box to 1.