基於Pytorch訓練Pointnet+Windows10


1、前言

最近實驗室購入3D的攝像機,想要應用於圖像識別,鋼哥讓我找一找相應的3D識別項目。

我在github上面找到了pointnet這個項目,但是由於這個項目采用的是Python 2.7, TensorFlow 1.0.1, 我是想找個基於Pytorch框架, Python3.X版本的,所以根據官方提示,我找到了pointnet.pytorch這個版本.

我其實不太懂這個深度學習這一塊,之前有過利用YoloV3的經歷也是在網上搜索相應的教程后,經過相當時間的掙扎、痛苦,然后才成功運行的,我搜索了pointnet相關的教程,卻是沒有找到多少在Windows系統下運行的。多是復現github上的項目,在Linux或是 Ubuntu上運行。奈何我本人對這兩種系統一點也不了解,所以在window10成功運行pointnet.pytorch版本后,做一個記錄.

2、配置環境

Anaconda+Pycharm

Cuda10.2

Cudnn8.1.0

Python3.7

Cuda和Cudnn版本號需要匹配

3、准備工作

3.1、創建虛擬環境

打開Annaconda Promt,創建一個虛擬環境專門應用於Pointnet.Pytorch項目的運行。

conda create -n <虛擬環境的名字> python=<版本號>
conda create -n pointnet python=3.7

image-20210814205535725

成功創建

image-20210814205802523

輸入activate pointnet 激活環境

3.2、下載文件

cd進入E:/lyh文件下

image-20210814205934165

輸入

git clone https://github.com/fxia22/pointnet.pytorch

將github上的項目下載下來,若是網絡不好,也可以先在github上下載完后解壓直接放在指定的目錄下

QQ圖片20210814210757

3.3、下載環境所需要的庫

在anaconda prompt 下輸入進入pointnet.pytorch的命令

QQ圖片20210814223033

輸入pip install -e .(包括后面的句號小點)

pip install -e .

QQ圖片20210814223316

程序會按照setup.py文件里的安排,把python相應的庫下好

QQ圖片20210814223023

這里在下載torch的時候會出現問題比如ReadtimeOut的超時問題(這個問題我是掛梯子解決的)。

下載完以后由於怕torch版本過高,所以我卸載程序自動下載的torch1.9版本,安裝了一個torch1.5.0的版本。

可以選擇離線下載torch庫,在這個網址中查詢與cuda、cudnn、python對應的版本,像我的話由於怕pytorch版本過高,GitHub這個項目原本就只是用了torch1.0.1的版本,所以我選擇了python3.7,cuda10.2所能配置的最低版本

torch-1.5.0-cp37-cp37m-win_amd64.whl

QQ圖片20210814223338

在進入相應路徑下,

pip install torch-1.5.0-cp37-cp37m-win_amd64.whl

安裝torch庫

QQ圖片20210814223409

4、數據集

image-20210814220015491

github文檔中 build.sh下載的是可視化的過程,這個暫時我還不知道怎么處理

download.sh的話是下載數據集,可以直接根據

https://shapenet.cs.stanford.edu/ericyi/shapenetcore_partanno_segmentation_benchmark_v0.zip

進行下載

下載完后解壓在pointnet.pytorch文件夾下即可.

QQ圖片20210814223421

5、運行過程及出現的問題

用pycharm打開pointnet.pytorch,在終端cd utils 進入utils,輸入

python train_classification.py --dataset=E:\lyh\pointnet.pytorch\shapenetcore_partanno_segmentation_benchmark_v0\ --nepoch=5 --dataset_type=shapenet

5.2、問題1

UserWarning: Detected call of `lr_scheduler.step()` before `optimizer.step()`. In PyTorch 1.1.0 and late
r, you should call them in the opposite order: `optimizer.step()` before `lr_scheduler.step()`.  Failure to do this will result in PyTorch skipping the first value of the learning rate schedule.

這是PyTorch1.1.0版本以后會出現的問題,這里需要更改train.classification.py文件里兩句話的位置

image-20210814222255097

5.3、問題二

 if __name__ == '__main__':
                freeze_support()
                ...

​    The "freeze_support()" line can be omitted if the program
​    is not going to be frozen to produce an executable.

將代碼塊置於if __name__ == '__main__':之下

image-20210814222425658

再次輸入對應的命令,即可運行成功!

image-20210814222518533

image-20210814222559066

6、參考

Detected call of lr_scheduler.step() before optimizer.step()

PyTorch:The "freeze_support()" line can be omitted if the program is not going to be frozen

python進程池multiprocessing.Pool運行錯誤:The "freeze_support()" line can be omitted if the program is not g


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM