use pytorch

https://pytorch.org/get-started/locally/
1. install pytorch  // use install_pytorch.sh
#!/usr/bin/env bash

###############################################################################
# Copyright 2018 The Apollo Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################

# Fail on first error.
set -e

cd "$(dirname "${BASH_SOURCE[0]}")"

CONDA3_PATH=/usr/local/miniconda3
# The version of Anaconda may be different depending on when you are installing`
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh -b -p ${CONDA3_PATH}
# and follow the prompts. The defaults are generally good.

${CONDA3_PATH}/bin/conda install pytorch torchvision cudatoolkit=10.1 -c pytorch -y

# Clean up.
rm -f Miniconda3-latest-Linux-x86_64.sh
install_pytorch.sh
Q: CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
A: Add the following line to .bashrc 
  if [ -e /usr/local/miniconda3/etc/profile.d/conda.sh ]; then
    source /usr/local/miniconda3/etc/profile.d/conda.sh
  fi
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If your shell is Bash or a Bourne variant, enable conda for the current user with 
    $ echo ". /home/ubuntu/anaconda3/etc/profile.d/conda.sh" >> ~/.bashrc 
or, for all users, enable conda with 
    $ sudo ln -s /home/ubuntu/anaconda3/etc/profile.d/conda.sh /etc/profile.d/conda.sh 
The options above will permanently enable the 'conda' command, but they do NOT
put conda's base (root) environment on PATH.  To do so, run 
    $ conda activate 
in your terminal, or to put the base environment on PATH permanently, run 
    $ echo "conda activate" >> ~/.bashrc 
Previous to conda 4.4, the recommended way to activate conda was to modify PATH in
your ~/.bashrc file.  You should manually remove the line that looks like 
    export PATH="/home/ubuntu/anaconda3/bin:$PATH" 
^^^ The above line should NO LONGER be in your ~/.bashrc file! ^^^
Q: CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
apollo@in_dev_docker:/apollo$ conda activate
(base) apollo@in_dev_docker:/apollo$ python
Python 3.7.4 (default, Aug 13 2019, 20:35:49) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
True
>>> 
(base) apollo@in_dev_docker:/apollo$ conda deactivate
apollo@in_dev_docker:/apollo$
verify the installation
原文地址:https://www.cnblogs.com/cjyp/p/12141580.html