本科毕业论文中已经对算法各个模块进行了详细的拆解和讲述,本文主要用于记录服务器上执行的命令,包括数据预处理执行python程序

Data Preprocessing

制作特定格式数据集:

在更换数据集在 ImmFusion 代码上运行时,需要制作符合 ImmFusion dataloader 格式的数据集。

---LiDARCap
 |---train
   |---sequence_1
     |---image_0
     |---image
     |---img_feat
     |---img_feat_1
     |---img_feat_2
     |---mesh
     |---radar
   |---.....
 |---test

每个 sequence 里包括:原始图像、resize 成 224x224 后的图像、分别用 DINOv2、HRNet、ResNet 提取的图像特征、gt SMPL 参数(关节旋转或者顶点和关节点的坐标)、激光雷达点云

1. 创建文件夹

首先进入以下文件夹:

forder1/ImmFusion-main/ImmFusion-main/datasets/lidarcap/train

for i in 1 2 3 4 5; do
    mkdir -p "sequence_$i"/{radar,image,mesh,image_0,img_feat,img_feat_1,img_feat_2}
done

-p 确保父目录不存在也能创建子目录

for i in 42 40 39 38 37 36 35 34 33 32 31; do
    rm -r "sequence_$i"/img_feat
done
for i in 6 8; do
    mv "sequence_$i/old" "sequence_$i/new"
done

2. image_0制作

for i in 6 8; do
    cp -R /data/zy/lidarhuman26M/images/$i/* /data/liumengyin/forder1/ImmFusion-main/ImmFusion-main/datasets/lidarcap/train/sequence_$i/image_0
done

把源文件夹中的图片全部拷贝到目标文件夹下,i 的取值可修改(注意这时的图像可能还不是 224x224 尺寸的

3. img 预提取特征 & resize

首先进入如下目录:

/forder1/ImmFusion-main/ImmFusion-main

python test.py
python test_2.py
python test_3.py
# process img_feat & resize

import os
from mmpretrain import get_model
import cv2
import numpy as np
import torch

def preprocess(directory, img_des_path, feat_des_path, feat_extractor, device):
    cnt = 0
    for root, directories, files in os.walk(directory):
        for file in files:
            file_path = os.path.join(root, file)
            img = cv2.imread(file_path)
            # print(file)
            img = cv2.resize(img, (224, 224))
            
            if not os.path.exists(img_des_path + file):
                cv2.imwrite(img_des_path + file, img) 
                # print('img, ', img_des_path + file)
            
            img = np.transpose(img.astype('float32'), (2,0,1))/255.0
            img = torch.tensor(img.reshape(1, 3, 224, 224)).to(device)
            feat = feat_extractor(img)
            
            if not os.path.exists(feat_des_path + file[:6] + '.npy'):
                np.save(feat_des_path + file[:-4] + '.npy', feat[0].detach().cpu().numpy())
                # np.save(feat_des_path + file[:6] + '.npy', feat[0].detach().cpu().numpy())  # lidarcap
                # print('feat, ', feat_des_path + file[:6] + '.npy')
                
            # print(feat_des_path + file[:6] + '.npy')
            cnt += 1
            if cnt % 1000 == 0:
                print(cnt)

             
torch.cuda.set_device(5)  # gpu_idx
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

feat_extractor = get_model('vit-large-p14_dinov2-pre_3rdparty', pretrained=True)

base_path = '/data/liumengyin/forder1/ImmFusion-main/ImmFusion-main/datasets/reli11d/train/sequence_'

# base_path = '/data/liumengyin/forder1/ImmFusion-main/ImmFusion-main/datasets/lidarcap/test/sequence_'

idxes = [3]

for idx in idxes:
    print(str(idx) + ' begins!')
    img_path = base_path + str(idx) + '/image_0/'
    img_des_path = base_path + str(idx) + '/image/'
    feat_des_path = base_path + str(idx) + '/img_feat/'
    preprocess(img_path, img_des_path, feat_des_path, feat_extractor.to(device), device)
    print(str(idx) + ' is done!\n')

test_2.py 中:

feat_extractor = get_model('hrnet-w64_3rdparty_8xb32_in1k', pretrained=True)

test_3.py 中:

feat_extractor = get_model('resnet152_8xb32_in1k', pretrained=True)

4. radar 制作

for i in 6 8; do
    cp -R /data/zy/lidarhuman26M/labels/3d/segment/$i/* /data/liumengyin/forder1/ImmFusion-main/ImmFusion-main/datasets/lidarcap/train/sequence_$i/radar
done

5. mesh 制作

cd src/modeling/SMPL

修改:源目录地址; 目标目录地址; train or test; seq_idxes

python smpl_np.py

作用是把 .pkl / .json 内容取出来,塞给 SMPL 模型,得到 joints & vertices,并存储到指定目录下

Run .py

Train

第一次训去掉 resume checkpoint

nohup python -u run_3_immfusion.py  --output_dir output/lidarcap_m_8/lidarcap_7  --dataset lidarcap  --data_path datasets/lidarcap  --mesh_type smpl  --model Net_1  --per_gpu_train_batch_size 48 --per_gpu_eval_batch_size 48  --train   --seq_idxes 37,38,39,40,41,42,36,35,34,32,31,30,29,28,27,26,25,24,8,5   --input_feat_dim 1027,256,64  --hidden_feat_dim 512,128,32 --gpu_idx 0 --data_for_train_ratio 0.9 > output/lidarcap_m_8/output_7.txt 2>&1 &
python -u run_immfusion_m.py  --output_dir output/lidarcap_m/lidarcap_1  --dataset lidarcap  --data_path datasets/lidarcap  --mesh_type smpl  --model MyNet_3  --per_gpu_train_batch_size 8  --train   --seq_idxes [5] --input_feat_dim 1027,256,64  --hidden_feat_dim 512,128,32   

Test

python ./run_2_immfusion.py  --resume_checkpoint output/lidarcap_m_8/lidarcap_6/checkpoint/checkpoint-50-174100    --dataset lidarcap     --data_path datasets/lidarcap     --mesh_type smpl     --test_scene sequence_33  --gpu_idx 5

默认 batch_size 为 1

可视化

首先进入以下目录:

E:/py_files/smplx/examples

smplx:

python demo.py --model-folder E:/py_files/smplx/models/smplx/SMPLX_NEUTRAL.npz

smpl:

python demo.py --model-folder E:/py_files/smplx/models/smpl/smpl_f.pkl --ext pkl --model-type smpl