Use pvnet to train a self-made data set

Friends who are interested in 6D pose estimation can add me and join the pose estimation exchange group. The group will organize video exchanges and sharing of literature, code and technology from time to time.

portal

1. UseODT method to generate data set

Insert image description here

2. Create a new folder under the data folder of pvnet named custom

Insert image description here

3. Adjust custom file format

(1)将1中的JPEGImage、mask、transforms、Gold6.ply、intrinsics.json复制到custom文件夹下;

(2)将JPEGImage文件夹名称修改为rgb

(3)将transforms文件夹名称改为pose

(4) ① 新建diameter.txt文件
	  ② 跑diameter.py文件,得到diameter,并把这个数值填入diameter.txt中
	
(5) ① 新建camera.txt文件
	  ② 把intrinsics.json中相机内参复制到camera.txt中

(6)把1中的Gold6.ply改为model.ply,注意用meshlab打开一下,观察目标是不是在坐标系中心,同时打开作者提供的小猫的ply文件,对比一下模型的尺度是否在一个数量级上

(7)此时custom文件夹下面的文件如下图所示

Original intrinsics.json file

Insert image description here

custom folder contents

diameter.py

from plyfile import PlyData
import os
import numpy as np
model_path = os.path.join('./Linemod_preprocessed/models/model.ply')
ply = PlyData.read(model_path)
data = ply.elements[0].data
x = data['x']
y = data['y']
z = data['z']
x_size = np.max(x)-np.min(x)
y_size = np.max(y)-np.min(y)
z_size = np.max(z)-np.min(z)

print("Diameter:", np.sqrt(x_size**2 + y_size**2 + z_size**2))

4. Modify the handle_custom_dataset.py file parameters

(1)将pose_path = os.path.join(pose_dir, "pose{}.npy .format(ind))修改为pose_path = os.path.join(pose_dir, "{}.npy .format(ind))
(2)在pose = np.load(pose_path)下面一行添加
	  pose = pose[:3,:]   # 因为pose中的最后一行为0 0 0 1,pvnet代码中只需要输入前三行

Insert image description here
Insert image description here

5. Modify the path in helper.py and run it to check whether the pose is correct.

6. Run the following code under Training on the custom object in README.md to generate fps.txt and train.json files

python run --type custom

Insert image description here

7. Run under Training on the custom object in README.md

python train_net.py --cfg file configs/custom.yaml train.batch size 4

Insert image description here

8. The trained weights are stored in the data/model/pnvet/custom folder

Insert image description here

9. You can view the training results by running the following code in Training on the custom object in README.md

python run.py --type visualize--cfg_file configs/custom.yaml

Insert image description here

10. It should be noted that the test set and training set in pvnet are one data set, so during testing, the input file needs to be rewritten.

Guess you like

Origin blog.csdn.net/weixin_41837701/article/details/134764284