【代码复现】jointlearningretrievaldeformation,CVPR21_Joint Learning of 3D Shape Retrieval and Deformation

Run joint_learning_retrieval_deformation
CVPR21_Joint Learning of 3D Shape Retrieval and Deformation
因为evaluation的部分,我run的时候发现出现了dimension不匹配的问题,就想着自己重新训练一下模型,看一下是什么情况,以下是训练过程中的一些步骤

1. 克隆仓库

git clone https://github.com/mikacuy/joint_learning_retrieval_deformation

2. 安装环境

mv joint_learning_retrieval_deformation jlrd
cd jlrd
conda env create -f environment.yml

但是因为我在执行第二条命令时总是报错,我的目的是运行Training-IDO (Ours),遇到什么就安装什么吧

3. 安装所需包

pip install numpy==1.18.5
pip install h5py==2.10.0
pip install torch==1.5.1 torchvision torchaudio
pip install trimesh==3.7.7
# 下边一步是回到code的上一个文件夹下载pytorch3d v0.2.0
cd ..
wget https://github.com/facebookresearch/pytorch3d/archive/refs/tags/v0.2.0.tar.gz
tar -zxvf v0.2.0.tar.gz && rm v0.2.0.tar.gz
cd pytorch3d-0.2.0
# 因为我预先缺少g++环境,所以用下面的命令安装一下
apt-get install build-essential
pip install -e .

4. 从项目主页下载所需要的文件

在这里插入图片描述
相关包下载完毕后,就需要从项目主页下载一些文件,这里提示我们需要下载generated_datasplits/chair_500.pickle。
反观项目主页,pickle文件下载链接如下图所示:
在这里插入图片描述

# 回到code和pytorch3d的上一层文件夹并创建datasets,将数据下至datasets文件夹中
cd .. && mkdir datasets && cd datasets
wget http://download.cs.stanford.edu/orion/joint_embedding_deformation/generated_datasplits.tar
tar -zxvf generated_datasplits.tar

展开后可知,我们所需的文件在/orion/u/mikacuy/part_deform/generated_datasplits/
先回到code、pytorch3d、datasets的上一层文件夹
随后将generated_datasplits移动到代码文件夹中:

mkdir jlrd/generated_datasplits
mv datasets/orion/u/mikacuy/part_deform/generated_datasplits/ jlrd/ && rm datasets/generated_datasplits.tar
cd jlrd
# 继续run code
python train_region_final.py --logdir=log/ --dump_dir=dump/ --to_train=1 --init_deformation=1 --loss_function=regression --distance_function=mahalanobis --use_connectivity=1 --use_src_encoder_retrieval=1 --category=chair --model_init=df_chair_pc/ --selection=retrieval_candidates --use_keypoint=1 --use_symmetry=1

接下来报
在这里插入图片描述

5. 解决一些报错

去代码里看对应的行,发现是DATA_SPLIT没指定,我根据红框内的结果设置DATA_SPLIT为“train”
在这里插入图片描述
接着根据filename的路径(改完代码后跑一跑会发现提示“(unable to open file: name = '/home/xx/codes/jlrd/data_aabb_constraints_keypoint/chair/h5/43617_leaves.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)”),发现我们还缺少训练数据,就去github上下载:
在这里插入图片描述
复制目标链接,通过命令下载:

cd ../datasets
wget http://download.cs.stanford.edu/orion/joint_embedding_deformation/data_aabb_constraints_keypoint.tar

按我这里的网速大概要下24h(110k+/s)左右,如果是用的付费服务器,还是直接在电脑上下下来(可能爬梯子会更快一些),然后通过类似Xftp的工具传上去,可能会比较快。
但是我这里用的是学校的服务器,所以就不管了,放着让它下载即可。
结果最后大概是下载了6h的样子:
在这里插入图片描述
解压:

tar -zxvf data_aabb_constraints_keypoint.tar

这里会报一个错:gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now
那么我们将命令修改成:

tar -xvf data_aabb_constraints_keypoint.tar

即可。
因为上边我们知道报错的原因是因为找不到jlrd/data_aabb_constraints_keypoint/chair/h5/43617_leaves.h5,先观察一下大致的目录结构:
在这里插入图片描述
我们需要将该目录及目录下所有文件夹转移到/jlrd

cd ..
mv /home/xx/codes/datasets/orion/u/mikacuy/part_deform/data_aabb_constraints_keypoint/ jlrd/
rm -rf datasets/orion
# 继续试着运行代码
python train_region_final.py --logdir=log/ --dump_dir=dump/ --to_train=1 --init_deformation=1 --loss_function=regression --distance_function=mahalanobis --use_connectivity=1 --use_src_encoder_retrieval=1 --category=chair --model_init=df_chair_pc/ --selection=retrieval_candidates --use_keypoint=1 --use_symmetry=1

此时又提示:
在这里插入图片描述
这应该是我们还有没有下载的东西
于是:

cd datasets
wget http://download.cs.stanford.edu/orion/joint_embedding_deformation/pretrained_models.tar
tar -zxvf pretrained_models.tar

解压后可以看到里面的文件内容:
在这里插入图片描述
因为我们只需要df_chair_pc,所以将df_chair_pc移去jlrd/下就可以了

cd ..
mv datasets/pretrained_models/df_chair_pc/ jlrd/
cd jlrd
# 继续试着运行代码
python train_region_final.py --logdir=log/ --dump_dir=dump/ --to_train=1 --init_deformation=1 --loss_function=regression --distance_function=mahalanobis --use_connectivity=1 --use_src_encoder_retrieval=1 --category=chair --model_init=df_chair_pc/ --selection=retrieval_candidates --use_keypoint=1 --use_symmetry=1

这时候报错:RuntimeError: cuda runtime error (803) : system has unsupported display driver / cuda driver combination at /pytorch/aten/src/THC/THCGeneral.cpp:47
一拍脑袋,发现没安装cuda啊……

https://developer.nvidia.com/cuda-11-4-0-download-archive?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=runfile_local中参照着Base Installer进行安装。
详见:ubuntu20.04安装cuda库
因为安装了高版本的cuda,原本的pytorch库就不匹配了
这里可以不用这个博主给的环境变量配置,用下边的:

export CUDA_HOME=/usr/local/cuda
export PATH="$CUDA_HOME/bin:$PATH"
export LD_LIBRARY_PATH="$CUDA_HOME/lib64:$LD_LIBRARY_PATH"

然后建立一个软链接(CUDA的版本就写你下载的版本)

sudo ln -s /usr/local/cuda-10.2 /usr/local/cuda

就可以了。
这里如果pytorch3d用不了的话,在安装好CUDA后再重新按之前的步骤安装一遍就好了。
pytorch也是同理的,用不了就重新安装

6、训练过程展示

在这里插入图片描述

7、进行evaluate

按照项目主页所说的,我们需要进行render的安装才能够进行evaluate。

wget https://github.com/mhsung/libigl-renderer

接着按上边的wget去走一遍就可以了。
在这里插入图片描述
修改data_utils.py里的Render路径:
在这里插入图片描述
修改evaluate.py里的model.pth路径至训练结果的model:
在这里插入图片描述

8、一些result的展示

在这里插入图片描述
请添加图片描述
请添加图片描述
请添加图片描述请添加图片描述
请添加图片描述

Gatys et al. (2016) proposed an algorithm for style transfer, which can generate an image that combines the content of one image and the style of another image. The algorithm is based on the neural style transfer technique, which uses a pre-trained convolutional neural network (CNN) to extract the content and style features from the input images. In this algorithm, the content and style features are extracted from the content and style images respectively using the VGG-19 network. The content features are extracted from the output of one of the convolutional layers in the network, while the style features are extracted from the correlations between the feature maps of different layers. The Gram matrix is used to measure these correlations. The optimization process involves minimizing a loss function that consists of three components: the content loss, the style loss, and the total variation loss. The content loss measures the difference between the content features of the generated image and the content image. The style loss measures the difference between the style features of the generated image and the style image. The total variation loss is used to smooth the image and reduce noise. The optimization is performed using gradient descent, where the gradient of the loss function with respect to the generated image is computed and used to update the image. The process is repeated until the loss function converges. The code for this algorithm is available online, and it is implemented using the TensorFlow library. It involves loading the pre-trained VGG-19 network, extracting the content and style features, computing the loss function, and optimizing the generated image using gradient descent. The code also includes various parameters that can be adjusted, such as the weight of the content and style loss, the number of iterations, and the learning rate.
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值