日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

visual studio code python环境配置_visual-pushing-grasping环境配置及复现

發(fā)布時間:2025/3/20 python 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 visual studio code python环境配置_visual-pushing-grasping环境配置及复现 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

0. 電腦硬件配置

ThinkpadE580-不帶獨(dú)立顯卡,這款電腦比較坑,有些包就是安裝不上去,比Thinkpad的T系列差多了(小吐一下),VPG的github地址貼一下

andyzeng/visual-pushing-grasping?github.com

作者代碼可在CPU上直接跑,前提安裝的torch和torchvision與作者一致,這樣速度太慢,約150s一個循環(huán)。如果在GPU上跑,就要安裝高版本的torch,因?yàn)镚PU和cuda版本相關(guān),cuda又和torch版本有一定關(guān)聯(lián)

1. Pytorch安裝

  • 安裝Anaconda3,可去清華鏡像源下載.sh文件安裝
  • Tsinghua Open Source Mirror?mirrors.tuna.tsinghua.edu.cn

    Tsinghua Open Source Mirror

    Tsinghua Open Source Mirror?mirrors.tuna.tsinghua.edu.cnbash anaconda文件名.sh

    使用如下命令可以將清華源添加到Anaconda倉庫

    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ conda config --set show_channel_urls yes

    2. 然后使用conda創(chuàng)建python3.6的環(huán)境,vpg為環(huán)境名字

    conda creat -n vpg python=3.6

    3. 安裝pytorch,原文的pytorch版本太老,后來作者更新了安裝代碼,但是不建議使用,因?yàn)閲鴥?nèi)使用外網(wǎng)是一大限制,建議使用下面的代碼安裝:

    Andy的VPG項(xiàng)目中pytorch安裝方法(不建議使用)pip --default-timeout=3600 install -i https://pypi.tuna.tsinghua.edu.cn/simple torch torchvision

    如果要安裝特定torch版本,或者采用Win或OS系統(tǒng),可以參見官網(wǎng)這篇文章(包括cuda版本下的安裝)

    PyTorch?s0pytorch0org.icopy.site

    使用上述辦法安裝的torch1.4.0,torchvision0.5.0(根據(jù)安裝時安裝源的版本確定的)

    1.1 補(bǔ)充內(nèi)容:pip安裝的幾個知識點(diǎn),雖然沒使用,但是直覺告訴我應(yīng)該可以用

    • 將清華源設(shè)為 pip 默認(rèn)源,如果報錯,升級pip
    pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simplepip install pip -U #升級pip#安裝示例 pip install torch===1.3.0 torchvision===0.4.1 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple
    • 解決報錯 Could not find a version that satisfies the requirement torch

    使用如下鏡像網(wǎng)站下載,可以先打開看看有沒有要安裝的包

    http://pypi.doubanio.com/simple/?pypi.doubanio.com

    安裝的命令行如下:

    pip install 安裝包名字 -i http://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com

    1.2 參考鏈接:

    Could not find a version that satisfies the requirement tensorflow問題匯總+解決!!!

    通過清華鏡像源加速下載pytorch--(pip版本)_人工智能_WannaSeaU的博客-CSDN博客

    2. 其它包安裝

    pip --default-timeout=3600 install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy scipy opencv-python matplotlib

    3. 代碼部分流程-training模式

    • 運(yùn)行main()參數(shù) --is_sim --push_rewards --experience_replay --explore_rate_decay --save_visualizations
    • 重啟仿真器 self.restart_sim()
    • 設(shè)置虛擬相機(jī) self.setup_sim_camera()
    • 向仿真環(huán)境添加10個物體 self.add_objects() 通過函數(shù)vrep.simxCallScriptFunction放置物體,其中參數(shù)位置和姿態(tài)都是隨機(jī)的
    • 初始化訓(xùn)練 trainer = Trainer(method, push_rewards.....
    • 創(chuàng)建保存數(shù)據(jù)的目錄 logger
    • 檢查仿真環(huán)境是否正常 if is_sim: robot.check_sim()
    • 獲取相機(jī)圖像 get_camera_data()
    • 得到heightmap utils.get_heightmap()
    • 保存images和heightmap logger.save_images/heightmap()
    • 對heightmap應(yīng)用2x scale
    • 將經(jīng)過旋轉(zhuǎn)后的color和depth圖像變換后送入定義的推和抓的網(wǎng)絡(luò),得到記錄16次旋轉(zhuǎn)的output_prob, interm_feat
    • 檢測兩幅圖像變化
    • 計(jì)算訓(xùn)練labels,然后后向傳播 trainer.backprop
    • 對經(jīng)驗(yàn)回放采樣
    • 保存模型 snapshot
    • 同步動作線程和訓(xùn)練線程

    4. 疑問

    • 利用作者訓(xùn)練的模型測試,無效的pushing太多、抓取點(diǎn)和方位都不是很理想、即便物體分的很開的時候也不能有效抓取
    • 純CPU運(yùn)行,推和抓的準(zhǔn)確性相比GPU會高很多,這是否跟densenet網(wǎng)絡(luò)前加with torch.no_grad()有關(guān)?
    • 隨機(jī)種子作用域?Pushing位置計(jì)算原理?
    • 抓取物體點(diǎn)是以整體物體為單位確定嗎?
    • 推的位置誤差太大,且有些抓取位置計(jì)算也不對,并沒有附著到物體附近
    • 自己訓(xùn)練保存的模型參數(shù)是那幾個變量?

    5. 軟硬件調(diào)試問題

    問題1:加載與訓(xùn)練模型時key值不匹配 Missing key(s) in state_dict:...,這是由于Pytorch版本升級帶來的問題,報錯如下圖

    Missing keys報錯截圖

    問題原因:版本升級帶來的問題,報錯位置norm.1跟norm1的區(qū)別,具體解決辦法如下:

    import re...if args.resume:print("Loading checkpoint from '{}'".format(args.resume))checkpoint = torch.load(args.resume)#modify:# '.'s are no longer allowed in module names, but pervious _DenseLayer# has keys 'norm.1', 'relu.1', 'conv.1', 'norm.2', 'relu.2', 'conv.2'.# They are also in the checkpoints in model_urls. # This pattern is used to find such keys.pattern = re.compile(r'^(.*denselayerd+.(?:norm|relu|conv)).((?:[12]).(?:weight|bias|running_mean|running_var))$')state_dict = checkpoint['state_dict']for key in list(state_dict.keys()):res = pattern.match(key)if res:new_key = res.group(1) + res.group(2)state_dict[new_key] = state_dict[key]del state_dict[key]model.load_state_dict(state_dict)#model.load_state_dict(checkpoint['state_dict'])start_epoch = checkpoint['epoch']

    參考鏈接:

    https://github.com/KaiyangZhou/deep-person-reid/issues/23

    https://github.com/pytorch/vision/blob/50b2f910490a731c4cd50db5813b291860f02237/torchvision/models/densenet.py#L28

    Missing keys的另外一個原因:保存模型使用了nn.DataParallel導(dǎo)致的,解決辦法如下:

    兩種解決辦法

    第二種j解決辦法的代碼示例:參考鏈接

    [solved] KeyError: 'unexpected key "module.encoder.embedding.weight" in state_dict'

    # original saved file with DataParallel state_dict = torch.load('myfile.pth.tar')# create new OrderedDict that does not contain `module.` from collections import OrderedDict new_state_dict = OrderedDict() for k, v in state_dict.items():name = k[7:] # remove `module.`new_state_dict[name] = v# load params model.load_state_dict(new_state_dict)

    這個方法有網(wǎng)友整理了更詳細(xì)的,鏈接如下

    https://blog.csdn.net/qq_32998593/article/details/89343507

    問題2:更新后,現(xiàn)在網(wǎng)上下載代碼已不再適用torch0.3.1版本(已增加with torch.no_grad)

    問題3:robot文件中的代碼 async=False會報錯,作者最新版本的代碼更改為 asynch=False后報錯就消失了,報錯如圖所示:

    問題4:內(nèi)存不夠

    報錯 RuntimeError: $ Torch: not enough memory: you tried to allocate 0GB. Buy new RAM! at /opt/conda/conda-bld/pytorch_1523244252089/work/torch/lib/TH/THGeneral.c:253

    問題5:雙GPU報錯

    RuntimeError: Expected tensor for argument #1 'input' to have the same device as tensor for argument #2 'weight'; but device 0 does not equal 1 (while checking arguments for cudnn_convolution)

    暫時只使用一個GPU解決了本問題

    問題6:配置Intel Realsense D435i 相機(jī)

    安裝librealsense和realsense-ros包,這兩個安裝目錄及方法參照google教程, 注意兩者版本的匹配問題,版本匹配目錄見個人硬盤《Intel realsense設(shè)備驅(qū)動及ROS包版本匹配目錄》

    問題7:pytorch版本升級后需修改地方(作者的代碼torch版本0.3.0較低)

    • 沒有了Variable的概念
    • 類似numpy().[0]的地方要修改
    • with torch.no_grad()設(shè)置包含求解的densenet網(wǎng)絡(luò),會大大提高計(jì)算時間,不至于內(nèi)存溢出;
    《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

    總結(jié)

    以上是生活随笔為你收集整理的visual studio code python环境配置_visual-pushing-grasping环境配置及复现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。