美文网首页
2019-01-08

2019-01-08

作者: 从菜鸟开始 | 来源:发表于2019-01-08 22:39 被阅读0次

    记录一下今天的采坑经验。

    Pytorch 的安装

    由于SATNet项目代码是基于 PyTorch 0.4.0a0+408c84d (Some data structures and functions might be different in other versions)
    注意这里一串字母是github commit的代号,从pytorch只能安装0.4.0版本,所以只能选择从源码编译进行安装。
    pytorch github地址

    通过搜索github版本管理的相关博客,了解到可以先clone 项目,然后通过

    git checkout <commit id>
    

    进入指定的某次commit。那么问题来了,408c84d只是commit id 的前7个字符,需要得到完整的id,意味着需要查找项目的提交历史,对应的指令是:

    $ git log
    

    我写了个简单的python脚本把所有历史保存为txt文件,然后从里面搜索408c84d
    (得到的txt文件挺大的,用vim打开了)

    import os
    import sys
    
    os.system("git log >> commitlig.txt")
    

    得到具体的commit信息 ,一切ok了

    commit 408c84de7c4d852beffb9c64e2351b16cfff8a1f
    Author: Neeraj Pradhan <prad.neeraj@gmail.com>
    Date:   Fri Jan 5 00:45:05 2018 -0800
    
        Supporting logits as parameters in Bernoulli and Categorical (#4448)
    
        * Supporting logits as parameters in Bernoulli and Categorical
    
        * address comments
    
        * fix lint
    
        * modify binary_cross_entropy_with_logits
    
        * address comments
    
        * add descriptor for lazy attributes
    
        * address comments
    

    然后进入到对应分支

    git checkout 408c84de7c4d852beffb9c64e2351b16cfff8a1f
    

    接下来就是跟着从源码安装一步步来就是了。
    中间由于我的cudnn需要设置一下(每次运行前,在terminal中运行此句):

    export LD_LIBRARY_PATH=/home/dlr/Downloads/cuda8_6.1/lib64:$LD_LIBRARY_PATH
    

    在安装时遇到个小问题

    python2.7 setup.py install
    running install
    running build_deps
    Could not find ~/Project/pytorch/pytorch/torch/lib/gloo/CMakeLists.txt
    Did you run 'git submodule update --init'?
    

    执行 git submodule update --init命令,在进行install即可

    最后,我们测试一下安装情况

    >>> import torch
    >>> a=torch.LongTensor([1,2,3])
    >>> print(a)
    
     1
     2
     3
    [torch.LongTensor of size 3]
    
    >>> a=a.cuda()
    >>> print(a)
    
     1
     2
     3
    [torch.cuda.LongTensor of size 3 (GPU 0)]
    
    >>> torch.__version__
    '0.4.0a0+408c84d'
    >>> 
    

    版本一致,CHEERS!

    参考

    https://git-scm.com/book/zh/v1/Git-%E5%9F%BA%E7%A1%80-%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2
    https://blog.csdn.net/skymingst/article/details/42171221#
    https://blog.csdn.net/wsclinux/article/details/54425458
    https://blog.csdn.net/wenwen111111/article/details/52442265
    https://www.fengbohello.top/archives/pytorch-install
    

    相关文章

      网友评论

          本文标题:2019-01-08

          本文链接:https://www.haomeiwen.com/subject/bodirqtx.html