###### tags: `Anaconda` `AItutorials` # Anaconda AI環境安裝紀錄 **由於TensorFlow-GPU 需要 NVIDIA 的 CUDA 和 cuDNN 來使用 GPU。 請查看您的 TensorFlow 版本對應的 CUDA 和 cuDNN 版本,並確保您的系統已經安裝了對應版本的這兩個軟體。** * **安裝 Anaconda** https://www.anaconda.com/products/individual * **參考顯卡版本對照表安裝CUDA:** https://developer.nvidia.com/cuda-gpus * **CUDA CUDNN tensorflow_gpu版本對照** https://tensorflow.google.cn/install/source_windows?hl=en#gpu * **下載CUDA,選Base Installer**,https://developer.nvidia.com/cuda-downloads * **安裝完CUDA後檢查有無自動新增環境變數如下圖:**  * **下載對應CUDA版本的CUDNN** https://developer.nvidia.com/rdp/cudnn-download * **將cuDNN解壓縮後,裡面有三個資料夾,將這三個資料夾複製到剛才安裝CUDA的資料夾覆蓋**  **安裝CUDA的資料夾預設位置`C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA`**  * **建議安裝完CUDA跟顯卡驅動後,將電腦重開機比較不會有後續成程式抓不到顯示卡的問題** # 安裝pytorch 可參考官網版本 https://pytorch.org/get-started/previous-versions/ ``` pip3 install torchvision ``` ``` # conda conda install pytorch==2.0.0 torchvision==0.15.0 torchaudio==2.0.0 -c pytorch ``` ``` pip install torch==1.10.0+cu113 torchvision==0.11.1+cu113 torchaudio===0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html ``` **測試GPU是否啟用** ``` python ``` ``` import torch tensor = torch.rand(3,4) print(f"Device tensor is stored on: {tensor.device}") ``` **此處如果顯示**:` Device tensor is stored on: cpu` 可以使用 `tf.device` 上下文管理器來指定運算應該在哪個裝置上運行。 ``` with tf.device('/GPU:0'): ``` ``` print(torch.cuda.is_available()) ``` 應該會顯示: `#True` ``` tensor = tensor.to('cuda') print(f"Device tensor is stored on: {tensor.device}") ``` 如果 `print(f"Device tensor is stored on: {tensor.device}")` 打印的結果是 `"Device tensor is stored on: cuda:0"`,表示您的 `Tensor` 已經儲存在 `GPU` 上,並且 `TensorFlow` 正在使用您的**第一顆 GPU (索引從 0 開始)** 來進行運算。 **測試完成後ctrl z 退出程式** # 安裝其他插件 ``` pip install --upgrade pip ``` ``` conda install matplotlib -y ``` ``` conda install pandas -y ``` ``` pip install tsmoothie ``` ``` conda install scipy -y ``` ``` pip install -U scikit-learn ``` ``` python -m pip install statsmodels ``` ``` pip install sktime ``` ``` pip install tslearn ``` # 下載IDE ``` conda install spyder -y ``` ``` Conda install Jupyter Notebook -y ``` # 開啟IDE ``` spyder ``` ``` Jupyter Notebook ``` # 如果被字體所困擾可以參考此教學 https://alexanderlabwhoi.github.io/post/2021-03-missingfont/ **安裝字體包** ``` conda install -c conda-forge mscorefonts ``` 刪除的緩存matplotlib文件夾。如果您已經conda安裝,它應該位於您的主目錄中 ``` bash ``` ``` rm ~/.cache/matplotlib -rf ``` 現在,應該可以根據需要在筆記本中指定字體: ``` import matplotlib matplotlib.rcParams['font.family'] = "sans-serif" matplotlib.rcParams['font.sans-serif'] = "Comic Sans MS" ``` 或者利用以下程式碼把把印出的佔存刪除 ``` import matplotlib print(matplotlib.get_cachedir()) ``` **請注意,在刪除快取檔案前,請確保所有使用 matplotlib 的 Python 程式都已經結束,否則可能會導致未定義的行為。**
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up