Anaconda + vscode + pytorch environment to build

1, the installation Anaconda

Anaconda refers to is an open source Python release, which contains conda, Python and more than 180 scientific packages and their dependencies. The official website to download https://www.anaconda.com/distribution/ , because the server will be very slow in foreign countries, it is recommended from Tsinghua mirror https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ download.

2, installation VScode

VScode need to install in Anaconda, Anaconda and Microsoft cooperation because of, not to be in VScode configuration.

3, installation Pytorch

Pytorch is facebook's announcement of a famous deep learning framework. In Pytorch official website https://pytorch.org/ command line input window

 

4, fastai

fastai based PyTorch, providing easy to use API interface model to achieve common tasks with less code to build and train.

There are two ways to install fastai

Both are conda and pip Package Manager (automation software to install, update, uninstall a tool)

Conda installation

conda install -c fastai fastai

pip install

pip install fastai

5. Verify successful installation

from fastai.vision Import Models, URLs, ImageDataBunch, cnn_learner, untar_data, Accuracy
 Import Torch 

DEF main (): 
    
    path = untar_data (URLs.MNIST_SAMPLE)   # download data sets, where only a subset MNIST containing only image 3 and 7 will download and unpack (untar named the cause of) to /root/.fastai/data/mnist_sample (if you are the root user), the included training data, test data, contains the label of the csv file 
    data = ImageDataBunch.from_folder (path)   # use ImageDataBunch read the folder, the object returns a ImageDataBunch 
    Learn = cnn_learner (Data, models.resnet18, metrics = Accuracy)   # build cnn model, using the model pre-trained resnet18 
    learn.fit (. 1)   # training an 

IF  the __name__ == ' __main__ ':
    main()

 

Output results:

Guess you like

Origin www.cnblogs.com/Sunnyside-Bao/p/11220688.html