程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

PYthon deep learning is based on Pytorch study notes

編輯:Python

        This blog post is studying the books of Wu Maogui and others《Python深度學習基於Pytorch》(英文名為《Deep Learning with Python and Pytorch》)的時候,some notes taken,There are also problems that may occur when the version is updated.
        The version of the book in my hand is2019年10First printing of the first edition of the month,已經過去兩年了,I don't know what problems will be encountered in learning.我的Python版本是3.7.7.Will update if there is a problem,Although some of the books I was reading before were updated synchronously,Some pigeons,But believe me I can.

  1. 書中第18頁,1.6Section Generic Functions,1.math與numpy函數的性能比較.The function used for timing here istime.clock()記錄開始和結束時間,and use this as an estimate.However, this prompt will appearDeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead,意思是說在3.8版本之後time.clock將會消失,所以使用time.process_time()to be replaced.
    另外,The record on my computer,math.sin和numpy.sin的時間對比,可以看到numpy.sin比math.sin運行速度快了14倍.
  2. in accordance with the book25頁資料(第2.2.2節),使用conda安裝pytorch的時候,During the installation process, you will encounter that the name cannot be foundconda的module,after the error,原本的condaenvironment is also unavailable.The problem seems to be because if the default is inbase環境下面安裝pytorch的時候,will overwrite thepython包,resulting in a version number mismatch.解決方案是使用rm -rf ./anaconda3,先把anacondaThe environment is completely uninstalled(because I don't knowanacondaInternal exactly where there is a problem,Can only be completely uninstalled).
    接下來使用conda create pytorchenv python=3.7Create an installation specificallypytorch環境的conda環境.and switch environmentsconda activate pytorchenv,在這個環境中安裝torch即可conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c nvidia.
  3. 書中27頁(第2.3節),Configure Local Access ServerJupyter Notebook的時候,Encountered a problem that the machine and the computer server cannot be connected.The reason may be that the firewall of the server is turned on,A connection needs to be established between the local machine and the serverssh安全連接.sshThe secure connection command isssh 服務器的用戶名@服務器IP -L 127.0.0.1:1234:127.0.0.1:8888 -p 端口號
    The overall access process is as follows:First adjust on the serverjupyter的配置文件,包括端口號/密碼/允許遠程訪問/allow allip訪問/Close the browser window by default.Next, you need to establish and server on this machinejupyter notebook的ssh連接,Note the port number for specifying the server connection,Otherwise it will be inaccessible due to firewall denial.Finally, in the native browser throughip:端口就可以訪問.
  4. 書中46頁(第2.8節),嘗試使用Tensorflowwhen reproducing,發現tensorflow裡面沒有placeholder這個模塊.原因是使用conda install tensorflow默認安裝的是tensorflow 2.4版本的內容,而placeholder占位符是tensorflow 版本1的內容了.解決方案是:
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
  1. 繪圖的時候,If you do not want to add the values ​​of the abscissa and ordinate,可以使用plt.xticks([])來禁用.
  2. 繪圖的時候,when drawing an image,plt.scatter(x, y, label='something')直接添加label.without having to draw additionally after this.
  3. 當使用datasets.ImageFolder(路徑名)的時候,The system will display all the pictures under the folder,Sort and label by folder,Only need to put one class of file/Pictures are placed in the same folder,就可以使用datasets.ImageFolderThe batch build file data set.
  4. The following is a brief introduction to how to use the local browser,查看服務器端的tensorboard可視化樣例.
    tensorboardX在WebThe method of displaying on the terminal is as follows;
    1).在服務器端使用conda activate pytorchenv,進入pytorch環境下.
    2).tensorboard --logdir=~/logs/logs --port 6006,It's made herelog地址之後,使用pythonAlso need to be output to the corresponding taglog文件夾下面.
    3).使用sshcommand to establish a connection between the machine and the server.ssh 用戶名@IP地址 -L 127.0.0.1:6006:127.0.0.1:6006 -p 6138
    4).Login in native browserlocalhost:6006即可.
  5. 如果想要刪除tensorboardsome images in,Just need to clicklogs文件夾,Delete the corresponding label file.只有重啟tensorboard服務之後,to find out that this image has been deleted.
  6. 有一個疑問,is about the normalization problem.The mean is subtracted and divided by the standard deviation during training,The subtraction should be the mean and standard deviation of the training dataset.During the testing phase and the evaluation phase,Should also need to subtract the mean and divide by the standard deviation,Which mean and standard deviation should I use??mean and standard deviation of the training set,Or the mean and standard deviation of the test set??
    Chapter 5 of this book5.3.2Section corresponding code,The method shown is,在預測的時候,Also subtract the mean and standard deviation on the training data set,Not sure if this is the right way to do it.
#對訓練數據進行標准化
mean=X_train.mean(axis=0)
std=X_train.std(axis=0)
X_train-=mean
X_train/=std
X_test-=mean
X_test/=std
  1. 在書中86page place,Do a batch regularization、Batch random zeroing operation,Used to show that using these methods improves generalization properties.But after my actual verification,After discovering that using these methods,The loss function drops slower.Not sure if this is consistent with what is presented in the book.

    In the test data set to get the loss value calculation

    The loss value obtained by the operation on the training data set
    But the result of running in the book is as follows:dropoutthe loss value obtained,is significantly smaller thanoriginal原始數據的.這就有點讓人費解了.

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved