1. 创建根目录

    1. mkdir project_dir
    2. cd project_dir
  2. 安装tensorflow=2.6

创建conda环境,python=3.8

  1. conda create -n deeplab python=3.8
  2. conda activate deeplab
  3. #首先查看gcc版本是否符合要求
  4. # https://www.tensorflow.org/install/source#tested_build_configurations
  5. gcc --version
  6. nvcc -V
  7. #安装tensorflow环境
  8. pip install -i https://mirror.baidu.com/pypi/simple tensorflow==2.6
  9. # 安装CUDA
  10. conda install cudatoolkit=11.3 #11.2报错,找不到(原因是本地版本的问题)
  11. # 安装Cudnn
  12. conda install cudnn=8.2 # 8.1报错
  13. #测试tf是否可用
  14. import tensorflow as tf
  15. import os
  16. os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
  17. a = tf.constant(1.)
  18. b = tf.constant(2.)
  19. print(a+b)
  20. print('GPU:', tf.test.is_gpu_available())
  21. 上诉查看GPU是否可以的方法在2.6后即将被遗弃,
  22. 使用tf.config.list_physical_devices('GPU')
  23. # 后面会有一个坑。keras版本与tensorflow版本不匹配,
  24. pip install -i https://mirror.baidu.com/pypi/simple keras==2.6

image.png

  1. 安装protobuf

sudo apt-get install protobuf-compiler
Alternatively, you can also download the package from web on other platforms. Please refer to https://github.com/protocolbuffers/protobuf for more details about installation.

  1. other libraries

    1. pip install -i https://mirror.baidu.com/pypi/simple pillow
    2. pip install -i https://mirror.baidu.com/pypi/simple matplotlib
    3. pip install -i https://mirror.baidu.com/pypi/simple cython
    4. pip install -i https://mirror.baidu.com/pypi/simple pycocotools
  2. 安装 Orbit

Orbit is a flexible, lightweight library designed to make it easy to write custom training loops in TensorFlow 2. We used Orbit in our train/eval loops. You need to download the code below:

  1. cd project_dir
  2. git clone https://github.com/tensorflow/models.git
  1. 安装pycocotools

We also use pycocotools for instance segmentation evaluation. Below is the installation guide:

  1. cd project_dir
  2. git clone https://github.com/cocodataset/cocoapi.git
  3. # Compile cocoapi
  4. cd project_dir/cocoapi/PythonAPI
  5. make
  6. cd project_dir
  1. 编译Compilation
  • 添加环境变量 ```python cd project_dir

    deeplab2

    export PYTHONPATH=$PYTHONPATH:pwd

    orbit

    export PYTHONPATH=$PYTHONPATH:${PATH_TO_MODELS}

    pycocotools

    export PYTHONPATH=$PYTHONPATH:${PATH_TO_cocoapi_PythonAPI}

    三者在同一根目录下,可按如下配置

    export PYTHONPATH=$PYTHONPATH:pwd:pwd/models:pwd/cocoapi/PythonAPI
  1. 这个是临时的,需要在.bashrc 文件中添加永久的环境变量。
  2. - 编译protocol Buffers
  3. ```python
  4. # `${PATH_TO_PROTOC}` is the directory where the `protoc` binary locates.
  5. ${PATH_TO_PROTOC} deeplab2/*.proto --python_out=.
  6. # Alternatively, if protobuf compiler is globally accessible, you can simply run:
  7. protoc deeplab2/*.proto --python_out=.
  1. 测试配置—先重启

You can test if you have successfully installed and configured DeepLab2 by running the following commands (requires compilation of custom ops这一步省略了):

  1. # Model training test (test for custom ops, protobuf)
  2. python deeplab2/model/deeplab_test.py
  3. # Model evaluator test (test for other packages such as orbit, cocoapi, etc)
  4. python deeplab2/trainer/evaluator_test.py

也可以在pycharm中测试