--- title: 環境版本 tags: Environment --- ## 1. 環境版本對應 ### 碩二暑假(2020.07) * Python - TensorFlow - Keras - Cuda - Cudnn > Python: 3.7.7 > TensorFlow-gpu: 2.1.0 > Keras: 2.3.1 ( 2.2.0 也可以 ) > Cuda: 10.1 > Cudnn: v7.6.5.32 > (bonus) Pytorch: 1.5.0 (+cu101) ### 碩二上(2020.10) * Python - TensorFlow - Cuda - Cudnn > Python: 3.6.8 > TensorFlow-gpu: 1.10.0 > Cuda: 9.0 > Cudnn: v7.6.5 > 用於做[FPN-tensorflow](https://github.com/DetectionTeamUCAS/FPN_Tensorflow) 的環境。 :::warning 可搭配參考此[網址](https://github.com/fo40225/tensorflow-windows-wheel)。 ::: ## 2. python原始 > python > setuptools > wheel --- :::danger * 顯示目前python版本 > python --version > #或是 > python -V * 顯示目前有哪些套件 > pip list * 更新pip > python -m pip install --upgrade pip * 若無發執行,則: > easy_install -U pip * 更新setuptools > pip install –upgrade setuptools ::: ## 3. 建立虛擬環境指令 1. 先建立一個虛擬環境 ```terminal= python -m venv 資料夾名稱 (ex:venv) .\資料夾名稱\Scripts\activate ``` 2. 然後開始pip install 你需要的套件==版本 3. 之後可以輸出requirements.txt ```terminal= pip freeze > requirements.txt ``` ## 4. 下載Pytorch * [torchvision](https://github.com/pytorch/vision/) that matches the PyTorch installation. You can install them together at [pytorch.org](https://pytorch.org/) to make sure of this. * 我目前使用的torch版本是 1.6.0+cu101、torchvision版本是 0.7.0+cu101。 ```python= pip install torch==1.6.0+cu101 torchvision==0.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html ``` ## 5. 下載TensorFlow * 對於版本參考可以看[這裡](https://www.tensorflow.org/install/source_windows?hl=zh-tw)。 ```terminal= # CPU pip install tensorflow==版本 # GPU pip install tensorflow-gpu==版本 ``` 測試Tensorflow ```python= import tensorflow as tf print(tf.add(1, 2)) ``` output: ```python= tf.Tensor(3, shape=(), dtype=int32) ``` ## 6. 測試Cuda * cuda 版本 ``` nvcc --version # 或是 nvcc -V ``` ![version](https://2.bp.blogspot.com/--gZiARFlwYw/XKd_VQGotkI/AAAAAAAATL4/hUI9-5TIXLMC20immu9JDmNkRUNx21tmgCLcBGAs/s1600/56518224_2225401700870047_8531126469559058432_n.png) * 測試 cuda 內容 ``` nvidia-smi ``` ![smi](https://1.bp.blogspot.com/-_MNXdgFj0xM/XKd_cIleGSI/AAAAAAAATL8/8aVUrO4-PjwQXSIvHMT8dFUP7Z54SW4DgCLcBGAs/s640/56435164_282659419292601_1004380004840112128_n.png) :::danger #持續print使用狀況 nvidia-smi -l ::: * 測試 cuda 版本是否可行 * 方法1 : ``` > python > import torch > torch.cuda.is_available() ``` ![available](https://1.bp.blogspot.com/-NA-X-sDZ4GM/XKd_iy-hJwI/AAAAAAAATMA/PwLB1ssy5R8ZM-9PLuZiRTRd7RqzMCc8gCLcBGAs/s640/56958804_2250234348368888_262914425864847360_n.png) * 方法2 : ``` > import tensorflow as > tf.test.is_gpu_available( cuda_only=False, min_cuda_compute_capability=None ) ``` ![](https://i.imgur.com/qKBHP0u.png) > 此版本為: > python: 3.7.7 > tensorflow: 1.15.0 > cuda: 10.0 > cudnn: v7.6.4 > [name=2020.10.17 doing for FPN] * 方法3 : 可以參考此[文章](https://medium.com/@minhplayer95/how-to-install-tensorflow-with-gpu-support-on-windows-10-with-anaconda-4e80a8beaaf0) (含path的部分)。 :::danger :warning:**記得還要加上 Microsoft Visual Studio 的開發套件。** :::