guide
1. Basic situation
python = 3.6.5
pytorch = 1.2.0
torchvision = 0.4.0
tensorwatch = 0.8.7
pydot = 1.4.2
scikit-learn = 0.24.2
pandas = 1.1.5
Say it in advance: matching between versions can avoid a lot Wrong, avoid many detours.
2. Configure the Jupyter Notebook compilation environment
Open the Jupyter Notebook software that was downloaded when installing Anaconda. When creating a new one, I found that the only interpreter that can be used is python in the basic environment, as shown in the figure below (the red graffiti part is the environment I have configured):
But our network structure is based on pytorch, so we need to use the kernel in the pytorch environment. The process is very simple. First, close the Jupyter Notebook software and the relevant interfaces that have been opened, run Anaconda Prompt to enter your own pytorch environment, and run the following codes respectively (note that pt is switched to your own environment name):
pip install ipykernel
python -m ipykernel install --name pt --display-name "pytorch"
After waiting for the installation to be completed, open the Jupyter Notebook software again and you will find that our pytorch environment has appeared. At this time, you can create new packages to call torch, torchvision and other packages.
3. Install dependency packages
3.1 Install Graphviz packages and software
After configuring the Jupyter Notebook environment, install the Graphviz package and software before installing tensorwatch. Enter your own pytorch environment in Anaconda Prompt, run the code and install the graphviz pip install graphviz
dependency package. After successful installation, install the Graphviz software. Download address: https:// www2.graphviz.org/Packages/stable/windows/10/cmake/Release/x64/ , the page content is as follows:
Directly click on the red line to download. After downloading, it will be an .exe executable file. Double-click to enter the installation wizard and proceed in sequence. In the middle step, please check the Add environment variable option, as shown below: After the software installation is completed, check whether it has
been Add environment variables, as shown in the figure. I have added environment variables, indicating that the installation of Graphviz software is complete.
3.2 Install tensorwatch, etc.
After configuring the Jupyter Notebook environment, continue to install the dependency packages we need in your own pytorch environment. The code:
pip install pydot==1.4.2
pip install tensorwatch==0.8.7
pip install scikit-learn==0.24.2
pip install pandas==1.1.5
Of course, you can also install them all at once, depending on your situation.
4. Test whether the installation is successful
Let me start by saying: After you have created a new script in Jupyter Notebook, if you want to add or delete a package in the environment, you must restart the kernel and then run the code. Otherwise, there will be no change if you run the code directly, which is the red button in the picture.
Use the following test code to first test whether the overall configuration is successful. Code:
from torchvision.models import vgg16 # 以 vgg16 为例
from tensorwatch import draw_model
mynet = vgg16() # 实例化网络
draw_model(mynet, [1, 3, 64, 64]) # 输出网络结构
An error will be reported at this time 'Dot' object has no attribute '_repr_svg_'
, see the picture for details:
Solution: Find the file pytorch_draw_model.py
. It is in your own pytorch environment. For example, my pytorch environment name is pt. Then the file I am looking for is in the path. E:\Anaconda3\envs\pt\Lib\site-packages
Open it with an editor such as Notepad or Notepad++ and change line 13. The code is changed to return self.dot.create_svg().decode()
: save and restart the kernel to run the test code. The results are as shown in the figure (a section is taken for display only):
5 Conclusion
It is more intuitive to use Jupyter Notebook + tensorwatch to observe the results of the network, but it takes a long time to configure to a certain extent. The error content reported by different people during installation may also be different, so follow the set that has been configured. Relying on the package version for installation can avoid a lot of errors.