CODE_PYTHON

    • VisualStudio19 and Python

      1. 目前无法从==VisualStudio17==中直接创建Conda环境,但是可以首先通过conda创建好环境后,再利用手动添加配置的方式添加相应的环境
      2. 具体步骤
        • VS17手动添加conda环境
        • 打开(1)Python环境
        • 选择(2)自定义
        • 前缀路径(4)选择conda创建虚拟环境的文件夹
        • (5)选择(4)文件夹中的python.exe
        • (6)选择(4)文件夹中的pythonw.exe
        • (7)选择虚拟环境中的Python版本
        • (8)根据自身机器情况选择
        • (9)忽略,不用填写
      3. 使用如下两行代码在运行时检测Python版本信息

        1
        2
        import platform
        print(platform.python_version())

        PyTorch基础

      4. An open source machine learning framework that accelerates the path from research prototyping to production deployment.
      5. windows 下通过运行

        来查看CUDA 版本
        1
        2
        3
        4
        5
        6
            * ![CUDA-win-version](https://hexo-eu-1259148800.cos.eu-frankfurt.myqcloud.com/CUDA-win-version.png)
        3. Use ```nvcc --version``` to check the cuda versin under Linux
        4. 在Conda创建好的目标环境下,利用官网、手动配置Conda下安装PyTorch包的命令
        * ![Conda下安装PyTorch命令](https://hexo-eu-1259148800.cos.eu-frankfurt.myqcloud.com/Conda%E4%B8%8B%E5%AE%89%E8%A3%85PyTorch%E5%91%BD%E4%BB%A4.png)
        5. Windows下使用Python:
        * ```>= VisualStudio17 | Conda | 其它软件

      6. PyTorch–Features

        1. 如下三个没有测试成功
          • DISTRIBUTED TRAINING
          • C++ FRONT-END
          • CLOUD PARTNERS
      7. PyTorch的torch.nn中包含了各种神经网络层、激活函数、损失函数等等的类。我们通过torch.nn来创建对象,搭建网络。
      8. PyTorch中还有torch.nn.functional,让我们可以通过调用函数的方式,来直接搭建网络,而不用像torch.nn一样要先创建对象
      9. dim)``` this is used to return the max value of special dim of tensor, ```1``` represents the row while ```0```represents col
        1
        2
        3
        10. the ```item()``` in torch used to return the pure value of a tesor whose size if ```1```  
        11. We should not use write.close(), so interupte
        12. 返回每列最大值:```np.max(a, axis = 0)``` ; 返回每行最小值:```np.min(a, axis = 1)

        代码实例

      10. 1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        import numpy as np

        a = np.ones(4)
        # both two can create tensor fraom numpy array
        # but the operations on a only effect c not b
        # I think it is the biggest different
        b = th.tensor(a)
        c = th.from_numpy(a)
        print (a)
        print (b)
        print (c)

        np.add(a, 1, out = a)

        print (a)
        print (b)
        print (c)
      11. 更改数组形状(改变原始数组):

        3)``` ; 更改数组形状(不改变原始数组):```a.reshape(2, 3)```
        1
        4. ```y.data.norm() ``` is equivalent to ```torch.sqrt(torch.sum(torch.pow(y, 2)))

      12. Must be careful during coding, because even a ==,== can cost you ==an hour==