### Clone and Run Web Example Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/deployment/web/web.md Commands to clone the repository, install dependencies, and start the development server. ```sh # clone Paddle.js git clone https://github.com/PaddlePaddle/PaddleSeg.git # Enter the deploy web example directory and install dependencies cd PaddleSeg/deploy/web/example/ && npm install # Execute npm run dev # Visit http://0.0.0.0:8866/ to experience the application of portrait segmentation and processing ``` -------------------------------- ### Install PaddleLabel ML from Source Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/PaddleLabel/doc/CN/project/interactive_segmentation.md After cloning the repository, navigate to the directory and run the setup script to install the ML extension. This requires Python and setuptools. ```shell cd PaddleLabel-ML python setup.py install ``` -------------------------------- ### Install Dependencies and Copy Frontend Assets Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/PaddleLabel/doc/EN/README.md Install backend dependencies, create a static directory, copy the built frontend assets, and then install PaddleLabel using setup.py. This completes the source installation. ```shell cd PaddleLabel pip install -r requirements.txt mkdir paddlelabel/static/ cp -r ../PaddleLabel-Frontend/dist/* paddlelabel/static/ python setup.py install ``` -------------------------------- ### Start Training (Single-Card) Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/train/train.md This section details how to start model training using a single GPU with PaddleSeg, providing a command-line example and a list of configurable parameters. ```APIDOC ## Start Training (Single-Card) This endpoint demonstrates how to initiate model training on a single GPU using PaddleSeg. ### Method POST ### Endpoint /tools/train.py ### Parameters #### Query Parameters - **config** (string) - Required - Path to the configuration file for training. - **do_eval** (boolean) - Optional - Whether to perform evaluation during training. Defaults to False. - **use_vdl** (boolean) - Optional - Whether to use VisualDL for logging. Defaults to False. - **save_interval** (integer) - Optional - Number of steps between saving model checkpoints. Defaults to 1000. - **save_dir** (string) - Optional - Directory to save model checkpoints and logs. Defaults to 'output'. - **iters** (integer) - Optional - Number of training iterations. Defaults to the value in the config file. - **batch_size** (integer) - Optional - Batch size per GPU. Defaults to the value in the config file. - **learning_rate** (float) - Optional - Initial learning rate. Defaults to the value in the config file. - **num_workers** (integer) - Optional - Number of worker processes for data loading. Defaults to 0. - **log_iters** (integer) - Optional - Interval steps for printing logs. Defaults to 10. - **resume_model** (string) - Optional - Path to a model to resume training from. - **keep_checkpoint_max** (integer) - Optional - Maximum number of recent checkpoints to keep. Defaults to 5. ### Request Example ```shell export CUDA_VISIBLE_DEVICES=0 python tools/train.py --config configs/quick_start/pp_liteseg_optic_disc_512x512_1k.yml --do_eval --use_vdl --save_interval 500 --save_dir output ``` ### Response #### Success Response (200) Training process initiated. Output includes logs and model checkpoints. #### Response Example (No specific response body is defined, output is typically console logs and saved files.) ``` -------------------------------- ### Compile FastDeploy Example Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/deploy/fastdeploy/semantic_segmentation/sophgo/cpp/README.md Compile the FastDeploy C++ example using CMake, specifying the installation directory of the pre-compiled FastDeploy SDK for SOPHGO. ```bash cd build cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-sophgo make ``` -------------------------------- ### Installation Configuration Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/deploy/fastdeploy/semantic_segmentation/rockchip/rv1126/cpp/CMakeLists.txt Sets the installation prefix and defines rules for installing the executable, models, images, and shared libraries. This ensures the built project can be deployed correctly. ```cmake set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/build/install) install(TARGETS infer_demo DESTINATION ./) install(DIRECTORY models DESTINATION ./) install(DIRECTORY images DESTINATION ./) file(GLOB_RECURSE FASTDEPLOY_LIBS ${FASTDEPLOY_INSTALL_DIR}/lib/lib*.so*) file(GLOB_RECURSE ALL_LIBS ${FASTDEPLOY_INSTALL_DIR}/third_libs/install/lib*.so*) list(APPEND ALL_LIBS ${FASTDEPLOY_LIBS}) install(PROGRAMS ${ALL_LIBS} DESTINATION lib) ``` -------------------------------- ### Install FastDeploy and Prepare Environment Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/deploy/fastdeploy/semantic_segmentation/cpu-gpu/python/README.md Install the FastDeploy Python package and configure Conda for CUDA and cuDNN. This is a prerequisite for running the deployment examples. ```bash pip install fastdeploy-gpu-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html conda config --add channels conda-forge && conda install cudatoolkit=11.2 cudnn=8.2 ``` -------------------------------- ### Download Example Assets Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/SegmentAnything/README.md Commands to fetch the demo image and vocabulary file required for the segmentation examples. ```bash wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png wget https://bj.bcebos.com/paddleseg/dygraph/bpe_vocab_16e6/bpe_simple_vocab_16e6.txt.gz ``` -------------------------------- ### Install Paddle Serving Client Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/deployment/serving/serving.md Install the paddle-serving-client package. Ensure paddle-serving-app is 0.6.0 or higher. ```shell pip3 install paddle-serving-app==0.6.0 pip3 install paddle-serving-client==0.6.0 ``` -------------------------------- ### Install PaddleSeg from Source Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/install.md Commands to install dependencies and install PaddleSeg in editable mode for development. ```bash cd PaddleSeg pip install -r requirements.txt pip install -v -e . ``` -------------------------------- ### Start Single-Card Training Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/train/train.md Use this script to start training a model on a single GPU. Ensure PaddleSeg is installed and you are in the PaddleSeg directory. Set the CUDA_VISIBLE_DEVICES environment variable to specify the GPU. ```shell export CUDA_VISIBLE_DEVICES=0 # Set 1 usable card # If you are using windows, please excute following script: # set CUDA_VISIBLE_DEVICES=0 python tools/train.py \ --config configs/quick_start/pp_liteseg_optic_disc_512x512_1k.yml \ --do_eval \ --use_vdl \ --save_interval 500 \ --save_dir output ``` -------------------------------- ### YAML Configuration Example Source: https://context7.com/paddlepaddle/paddleseg/llms.txt Example of a model configuration file using inheritance and specific training parameters. ```yaml # configs/my_custom_model/custom_deeplabv3p.yml _base_: '../_base_/cityscapes.yml' batch_size: 4 iters: 80000 model: type: DeepLabV3P backbone: type: ResNet50_vd output_stride: 8 pretrained: https://bj.bcebos.com/paddleseg/dygraph/resnet50_vd_ssld_v2.tar.gz num_classes: 19 backbone_indices: [0, 3] aspp_ratios: [1, 12, 24, 36] aspp_out_channels: 256 align_corners: False pretrained: null train_dataset: type: Cityscapes dataset_root: data/cityscapes transforms: - type: ResizeStepScaling min_scale_factor: 0.5 max_scale_factor: 2.0 scale_step_size: 0.25 - type: RandomPaddingCrop crop_size: [1024, 512] - type: RandomHorizontalFlip - type: RandomDistort brightness_range: 0.5 contrast_range: 0.5 saturation_range: 0.5 - type: Normalize mode: train val_dataset: type: Cityscapes dataset_root: data/cityscapes transforms: - type: Normalize mode: val optimizer: type: SGD momentum: 0.9 weight_decay: 0.0001 lr_scheduler: type: PolynomialDecay learning_rate: 0.01 end_lr: 0 power: 0.9 loss: types: - type: CrossEntropyLoss coef: [1] ``` -------------------------------- ### Install Environment Dependencies Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/DomainAdaptation/README.md Commands to clone the repository and install necessary dependencies for the domain adaptation module. ```bash git clone https://github.com/PaddlePaddle/PaddleSeg.git cd contrib/DomainAdaptation/ pip install -r requirments.txt python -m pip install paddlepaddle-gpu==2.2.0 -i https://mirror.baidu.com/pypi/simple ``` -------------------------------- ### Install PaddlePaddle and PaddleX Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/PaddleLabel/doc/CN/training/PdLabel_PdX.md Commands to install the required deep learning framework and the PaddleX toolkit. ```bash # 您的机器安装的是 CUDA9 或 CUDA10,请运行以下命令安装 pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple # 您的机器是CPU,请运行以下命令安装 # pip install paddlepaddle ``` ```bash pip install "paddlex<=2.0.0" -i https://mirror.baidu.com/pypi/simple ``` -------------------------------- ### Install and Configure Pre-commit Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/pr/pr/pr.md Installs the pre-commit tool to enforce code formatting and quality standards. ```shell pip install pre-commit pre-commit install ``` -------------------------------- ### Install PaddleSlim Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/test_tipc/docs/test_train_pact_inference_python.md Install the PaddleSlim library, which is required for quantization tasks. Ensure you are using a compatible version. ```bash pip install paddleslim==2.2.0 ``` -------------------------------- ### Finetune Configuration Example Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/Matting/docs/full_develop_en.md Example YAML configuration for finetuning. Modify dataset paths and pretrained model location. It's recommended to reduce the learning rate for finetuning. ```yaml train_dataset: type: MattingDataset dataset_root: path/to/your/dataset # Path to your own dataset mode: train val_dataset: type: MattingDataset dataset_root: path/to/your/dataset # Path to your own dataset mode: val model: type: PPMattingV2 backbone: type: STDC1 pretrained: https://bj.bcebos.com/paddleseg/dygraph/PP_STDCNet1.tar.gz decoder_channels: [128, 96, 64, 32, 16] head_channel: 8 dpp_output_channel: 256 dpp_merge_type: add pretrained: pretrained_models/ppmattingv2-stdc1-human_512.pdparams # The pretrained model file just downloaded lr_scheduler: type: PolynomialDecay learning_rate: 0.001 # lr is recommended to be reduced end_lr: 0 power: 0.9 warmup_iters: 1000 warmup_start_lr: 1.0e-5 ``` -------------------------------- ### Install LabelMe Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/data/marker/LabelMe.md Installs a specific version of the LabelMe library. Recommended for compatibility. ```shell $ pip install labelme==3.16.5 ``` -------------------------------- ### Download Deployment Example Code Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/deploy/fastdeploy/semantic_segmentation/sophgo/cpp/README.md Clone the PaddleSeg repository to obtain the C++ deployment example code for SOPHGO hardware. Ensure you are on the develop branch if the code is not found in the current branch. ```bash git clone https://github.com/PaddlePaddle/PaddleSeg.git # 注意:如果当前分支找不到下面的fastdeploy测试代码,请切换到develop分支 # git checkout develop cd PaddleSeg/deploy/fastdeploy/semantic_segmentation/sophgo/cpp ``` -------------------------------- ### Install OpenCV Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/deployment/inference/cpp_inference_linux.md Execute the shell script to download, compile, and install OpenCV dependencies. ```bash sh install_opencv.sh ``` -------------------------------- ### Install PaddleSeg Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/api_example.md Install the PaddleSeg library using pip. This is the first step before using any of its functionalities. ```python !pip install paddleseg ``` -------------------------------- ### Install Dependencies and Download Data Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/MedicalSeg/visualize.ipynb Install required Python packages and download the sample prediction dataset. ```python # Install dependencies for this example # Note: This does not include itkwidgets, itself import sys !{sys.executable} -m pip install scipy !wget https://bj.bcebos.com/paddleseg/paddleseg3d/lung_coronavirus/vnet_lung_coronavirus_128_128_128_15k_1e-3/prediction.npz ``` -------------------------------- ### Install and Configure PaddleSeg Environment Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/SegmentAnything/README.md Commands to clone the repository, install dependencies, and navigate to the SegmentAnything directory. ```bash git clone https://github.com/PaddlePaddle/PaddleSeg.git cd PaddleSeg pip install -r requirements.txt pip install ftfy regex cd contrib/SegmentAnything/ ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/test_tipc/docs/test_train_pact_inference_python.md Install all necessary Python dependencies listed in the requirements.txt file to ensure the project runs correctly. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install PaddleSlim (Develop) Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/deploy/slim/act/readme.md Clone the PaddleSlim repository and install the develop version. This is required for automatic compression. ```shell git clone https://github.com/PaddlePaddle/PaddleSlim.git & cd PaddleSlim python setup.py install ``` -------------------------------- ### Install System Dependencies Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/deployment/inference/cpp_inference_linux.md Execute shell scripts to install Yaml, Gflags, and Glog libraries required for the deployment. ```bash sh install_yaml.sh sh install_gflags.sh sh install_glog.sh ``` -------------------------------- ### Install Panoptic Segmentation Toolkit Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/PanopticSeg/docs/full_features_en.md Navigate to the PanopticSeg contrib directory and install its dependencies and the toolkit in editable mode. ```shell cd PaddleSeg/contrib/PanopticSeg pip install -r requirements.txt pip install -e . ``` -------------------------------- ### Install Paddle Serving Server (CPU) Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/deployment/serving/serving.md Install the CPU version of paddle-serving-server. Ensure PaddlePaddle version is 2.0 or higher and paddle-serving-app is 0.6.0 or higher. ```shell pip3 install paddle-serving-app==0.6.0 # CPU pip3 install paddle-serving-server==0.6.0 ``` -------------------------------- ### Run PP-Matting Deployment Examples Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/deploy/fastdeploy/matting/cpu-gpu/python/README.md Commands to clone the repository, download necessary assets, and execute inference on different hardware devices. ```bash # 下载部署示例代码 git clone https://github.com/PaddlePaddle/PaddleSeg.git # 注意:如果当前分支找不到下面的fastdeploy测试代码,请切换到develop分支 # git checkout develop cd PaddleSeg/deploy/fastdeploy/matting/cpp-gpu/python # 下载PP-Matting模型文件和测试图片 wget https://bj.bcebos.com/paddlehub/fastdeploy/PP-Matting-512.tgz tar -xvf PP-Matting-512.tgz wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_input.jpg wget https://bj.bcebos.com/paddlehub/fastdeploy/matting_bgr.jpg # CPU推理 python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device cpu # GPU推理 python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu # GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待) python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device gpu --use_trt True # 昆仑芯XPU推理 python infer.py --model PP-Matting-512 --image matting_input.jpg --bg matting_bgr.jpg --device kunlunxin ``` -------------------------------- ### Prepare Test Image Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/deploy/fastdeploy/semantic_segmentation/sophgo/cpp/README.md Download a sample image and copy it to the 'images' directory for testing the deployment example. ```bash wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png cp cityscapes_demo.png ./images ``` -------------------------------- ### Run SOPHGO Deployment Example Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/deploy/fastdeploy/semantic_segmentation/sophgo/python/README.md Commands to clone the repository, download test images, and execute the inference script on SOPHGO hardware. ```bash # 下载部署示例代码 git clone https://github.com/PaddlePaddle/PaddleSeg.git # 注意:如果当前分支找不到下面的fastdeploy测试代码,请切换到develop分支 # git checkout develop cd PaddleSeg/deploy/fastdeploy/semantic_segmentation/sophgo/python # 下载图片 wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png # PaddleSeg模型转换为bmodel模型 将Paddle模型转换为SOPHGO bmodel模型,转换步骤参考[文档](../README_CN.md) # 推理 python3 infer.py --model_file ./bmodel/pp_liteseg_1684x_f32.bmodel --config_file ./bmodel/deploy.yaml --image cityscapes_demo.png # 运行完成后返回结果如下所示 运行结果保存在sophgo_img.png中 ``` -------------------------------- ### Start Paddle Serving Server Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/deployment/serving/serving.md Start the RPC service using paddle_serving_server.serve. Specify the model directory, number of threads, port, and enable IR optimization. ```shell python -m paddle_serving_server.serve \ --model serving_server \ --thread 10 \ --port 9292 \ --ir_optim ``` -------------------------------- ### Get Segmentation Mask Source: https://context7.com/paddlepaddle/paddleseg/llms.txt Retrieves the visualization of the segmentation mask. No specific setup or imports are mentioned in the context. ```python mask = controller.get_visualization() ``` -------------------------------- ### C++ Deployment Example for PaddleSeg on RV1126 Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/deploy/fastdeploy/semantic_segmentation/rockchip/rv1126/README.md This is a C++ deployment example for PaddleSeg models on RV1126. It requires the FastDeploy library and a pre-exported or custom-quantized model. ```cpp #include "fastdeploy/vision/segmentation/pp_liteseg/paddle_lite_engine.h" #include "fastdeploy/vision/segmentation/preprocess.h" #include "fastdeploy/vision/segmentation/postprocess.h" #include "fastdeploy/core/base/model.h" #include #include #include int main() { // Model path std::string model_dir = "ppliteseg.tar.gz"; // Input image path std::string image_path = "test.jpg"; // Load the model auto model = fastdeploy::vision::segmentation::PaddleLiteEngine::Infer(model_dir); // Read image cv::Mat im = cv::imread(image_path); if (im.empty()) { std::cerr << "imread the test image failed." << std::endl; return -1; } // Preprocess the image fastdeploy::vision::SegmentationResult res; model.Predict(im, &res); // Postprocess the result cv::Mat result_image = fastdeploy::vision::segmentation::Visualize(im, res); // Save or display the result cv::imwrite("output.jpg", result_image); std::cout << "The result image is saved to output.jpg." << std::endl; return 0; } ``` -------------------------------- ### Run Script Configuration Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/MedicalSeg/README.md Example bash script configuration for setting GPU devices, paths, and model save directories. ```bash # set your GPU ID here export CUDA_VISIBLE_DEVICES=0 # set the config file name and save directory here yml=lung_coronavirus/vnet_lung_coronavirus_128_128_128_15k # relative path to your yml from config dir config_name = vnet_lung_coronavirus_128_128_128_15k # name of the config yml save_dir_all=saved_model # overall save dir save_dir=saved_model/${config_name} # savedir of this exp ``` -------------------------------- ### Install PaddleDetection and Dependencies Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/PaddleLabel/doc/CN/training/PdLabel_PdDet.md Clone the PaddleDetection repository and install its dependencies. This includes installing the package itself. ```bash git clone https://gitee.com/paddlepaddle/PaddleDetection cd PaddleDetection pip install -r requirements.txt python setup.py install ``` -------------------------------- ### View Training Help Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/LaneSeg/README.md Run this command to see all available parameters for the training script. ```shell python train.py --help ``` -------------------------------- ### CMake Project Setup and FastDeploy Integration Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/deploy/fastdeploy/semantic_segmentation/rockchip/rv1126/cpp/CMakeLists.txt Configures the CMake project, finds the FastDeploy SDK, and sets up include directories. Ensure FASTDEPLOY_INSTALL_DIR is correctly set. ```cmake PROJECT(infer_demo C CXX) CMAKE_MINIMUM_REQUIRED (VERSION 3.10) option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.") include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake) include_directories(${FASTDEPLOY_INCS}) include_directories(${FastDeploy_INCLUDE_DIRS}) ``` -------------------------------- ### Install paddlepaddle (CPU) Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/PaddleLabel/doc/CN/training/PdLabel_PdX.md Install the CPU-only version of paddlepaddle. Use this if your machine does not have a compatible GPU or CUDA installed. ```bash # pip install paddlepaddle ``` -------------------------------- ### Install PaddleSeg and Dependencies Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/Matting/docs/quick_start_cn.md Navigate to the PaddleSeg directory and install the required packages. Ensure you have the correct PaddlePaddle version installed. ```shell cd PaddleSeg/Matting pip install "paddleseg>=2.5" pip install -r requirements.txt ``` -------------------------------- ### View Training Script Help Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/Matting/docs/full_develop_en.md Run this command to see all available parameters and options for the training script. ```shell python tools/train.py --help ``` -------------------------------- ### Install PaddlePaddle with GPU Support Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/PaddleLabel/doc/CN/training/PdLabel_PdDet.md Install the GPU-enabled version of PaddlePaddle. Ensure your system has CUDA 9 or CUDA 10 installed. ```bash pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple ``` -------------------------------- ### Run QAT Training Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/test_tipc/configs/segformer_b0/train_pact_infer_python.txt Executes the QAT training process using the specified configuration file and hardware settings. ```bash deploy/slim/quant/qat_train.py --config test_tipc/configs/segformer_b0/segformer_b0_cityscapes_1024x1024_160k.yml --device gpu --save_interval 500 --seed 100 --num_workers 8 ``` -------------------------------- ### Project Configuration and Options Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/test_tipc/cpp/CMakeLists.txt Initializes the project and defines build options for MKL, GPU, static libraries, and TensorRT support. ```cmake project(seg_system CXX C) option(WITH_MKL "Compile demo with MKL/OpenBlas support, default use MKL." ON) option(WITH_GPU "Compile demo with GPU/CPU, default use CPU." OFF) option(WITH_STATIC_LIB "Compile demo with static/shared library, default use static." ON) option(WITH_TENSORRT "Compile demo with TensorRT." OFF) SET(PADDLE_LIB "" CACHE PATH "Location of libraries") SET(OPENCV_DIR "" CACHE PATH "Location of libraries") SET(CUDA_LIB "" CACHE PATH "Location of libraries") SET(CUDNN_LIB "" CACHE PATH "Location of libraries") SET(TENSORRT_DIR "" CACHE PATH "Compile demo with TensorRT") set(DEMO_NAME "seg_system") ``` -------------------------------- ### Clone PaddleSeg and Install Dependencies Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/PP-HumanSeg/README.md Clone the PaddleSeg repository and install the required Python packages using pip. Ensure you have PaddlePaddle and Python installed. ```shell git clone https://github.com/PaddlePaddle/PaddleSeg cd PaddleSeg pip install -r requirements.txt ``` -------------------------------- ### Execute PPMatting Training Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/test_tipc/configs/ppmatting/train_infer_python.txt Command to initiate model training using the specified configuration file and hardware settings. ```bash Matting/tools/train.py --config test_tipc/configs/ppmatting/modnet_mobilenetv2.yml --device gpu --save_interval 500 --seed 100 --num_workers 24 ``` -------------------------------- ### Install PaddleLabel ML Extension via PIP Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/PaddleLabel/doc/CN/project/interactive_segmentation.md Use this command to install the PaddleLabel ML extension for interactive segmentation functionality. Ensure you have pip installed. ```shell pip install paddlelabel-ml ``` -------------------------------- ### Install CityscapesScripts Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/PanopticDeepLab/README.md Install the required Cityscapes evaluation scripts. ```shell pip install git+https://github.com/mcordts/cityscapesScripts.git ``` -------------------------------- ### Verify Node.js Installation Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/deployment/web/web.md Check if Node.js is correctly installed on your system. ```sh # Display the installed node version number, which means successful installation node -v ``` -------------------------------- ### Start VisualDL Service Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/train/train.md Launches the VisualDL service on the local host to enable web-based visualization of logs located in the specified directory. ```bash visualdl --logdir output/ ``` -------------------------------- ### Install Dependencies Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/EISeg/docs/install_en.md Install the required Python packages listed in the requirements file. ```bash pip install -r requirements.txt ``` -------------------------------- ### OpenCV Installation Directory Structure Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/test_tipc/docs/test_inference_cpp.md Expected file structure after a successful OpenCV installation. ```text opencv3/ |-- bin :可执行文件 |-- include :头文件 |-- lib64 :库文件 |-- share :部分第三方库 ``` -------------------------------- ### Install PaddleSlim Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/deployment/slim/distill/distill.md Commands to clone and install the PaddleSlim library required for model distillation. ```shell git clone https://github.com/PaddlePaddle/PaddleSlim.git # checkout to special commit git reset --hard 15ef0c7dcee5a622787b7445f21ad9d1dea0a933 # install python setup.py install ``` -------------------------------- ### Prepare Sample Model Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/deployment/inference/python_inference.md Download and extract the sample inference model in the PaddleSeg root directory. ```shell # In the root of PaddleSeg cd PaddleSeg wget https://paddleseg.bj.bcebos.com/dygraph/demo/pp_liteseg_infer_model.tar.gz tar zxvf pp_liteseg_infer_model.tar.gz ``` -------------------------------- ### Clone and Install PaddleSeg Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/PanopticDeepLab/README.md Commands to clone the repository and install the package in editable mode. ```shell git clone https://github.com/PaddlePaddle/PaddleSeg ``` ```shell cd PaddleSeg pip install -e . ``` ```shell cd contrib/PanopticDeepLab ``` -------------------------------- ### Configure Math Libraries (MKL-DNN/OpenBLAS) Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/LaneSeg/deploy/cpp/CMakeLists.txt Sets up include directories and library paths for MKL-DNN or OpenBLAS based on the WITH_MKL flag and platform. Ensures correct library files are identified for linking. ```cmake if(WITH_MKL) set(MATH_LIB_PATH "${PADDLE_LIB_THIRD_PARTY_PATH}mklml") include_directories("${MATH_LIB_PATH}/include") if(WIN32) set(MATH_LIB ${MATH_LIB_PATH}/lib/mklml.lib) set(MKLDNN_LIB ${MATH_LIB_PATH}/lib/mkldnn.dll) else() set(MATH_LIB ${MATH_LIB_PATH}/lib/libmklml${CMAKE_STATIC_LIBRARY_SUFFIX}) set(MKLDNN_LIB ${MATH_LIB_PATH}/lib/libiomp5${CMAKE_SHARED_LIBRARY_SUFFIX}) endif() set(MKLDNN_PATH "${PADDLE_LIB_THIRD_PARTY_PATH}mkldnn") if(EXISTS ${MKLDNN_PATH}) include_directories("${MKLDNN_PATH}/include") if(WIN32) set(MKLDNN_LIB ${MKLDNN_PATH}/lib/mkldnn.lib) else(WIN32) set(MKLDNN_LIB ${MKLDNN_PATH}/lib/libmkldnn.so.0) endif(WIN32) endif() else() set(OPENBLAS_LIB_PATH "${PADDLE_LIB_THIRD_PARTY_PATH}openblas") include_directories("${OPENBLAS_LIB_PATH}/include/openblas") if(WIN32) set(MATH_LIB ${OPENBLAS_LIB_PATH}/lib/openblas${CMAKE_STATIC_LIBRARY_SUFFIX}) else() set(MATH_LIB ${OPENBLAS_LIB_PATH}/lib/libopenblas${CMAKE_STATIC_LIBRARY_SUFFIX}) endif() endif() ``` -------------------------------- ### Initialize OHEM Cross Entropy Loss Source: https://context7.com/paddlepaddle/paddleseg/llms.txt OHEM (Online Hard Example Mining) Cross Entropy Loss focuses training on harder examples. Parameters include a threshold and minimum number of examples to keep. ```python import paddle from paddleseg.models.losses import OhemCrossEntropyLoss ohem_loss = OhemCrossEntropyLoss( thresh=0.7, min_kept=100000, ignore_index=255 ) ``` -------------------------------- ### Online Composition train.txt Example Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/Matting/docs/data_prepare_en.md In 'train.txt', list foreground image paths in the first column and background image paths in the second column. ```text train/fg/fg1.jpg bg/bg1.jpg train/fg/fg2.jpg bg/bg2.jpg train/fg/fg3.jpg bg/bg3.jpg ... ``` -------------------------------- ### Verify PaddleSeg Installation Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/install.md Command to run the installation check script from the root of the PaddleSeg directory. ```bash cd PaddleSeg sh tests/install/check_predict.sh ``` -------------------------------- ### C++ Inference Demo Build Configuration Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/test_tipc/docs/test_inference_cpp.md Example content of a build.sh script for configuring the C++ demo build. ```bash OPENCV_DIR=your_opencv_dir LIB_DIR=your_paddle_inference_dir CUDA_LIB_DIR=your_cuda_lib_dir CUDNN_LIB_DIR=your_cudnn_lib_dir TENSORRT_DIR=your_tensorrt_lib_dir BUILD_DIR=build rm -rf ${BUILD_DIR} mkdir ${BUILD_DIR} cd ${BUILD_DIR} cmake .. \ -DPADDLE_LIB=${LIB_DIR} \ -DWITH_MKL=ON \ -DDEMO_NAME=run_seg \ -DWITH_GPU=OFF \ -DWITH_STATIC_LIB=OFF \ -DWITH_TENSORRT=OFF \ -DTENSORRT_DIR=${TENSORRT_DIR} \ -DOPENCV_DIR=${OPENCV_DIR} \ -DCUDNN_LIB=${CUDNN_LIB_DIR} \ -DCUDA_LIB=${CUDA_LIB_DIR} \ make -j ``` -------------------------------- ### Install PaddlePaddle GPU Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/install.md Command to install the GPU version of PaddlePaddle for Linux with CUDA 10.2. ```bash python -m pip install paddlepaddle-gpu==2.4.2 -i https://pypi.tuna.tsinghua.edu.cn/simple ``` -------------------------------- ### Online Composition val.txt Example with Trimap Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/Matting/docs/data_prepare_en.md For 'val.txt', include foreground, background, and optionally trimap image paths. If trimap is absent, the system will generate it automatically. ```text val/fg/fg1.jpg bg/bg1.jpg val/trimap/trimap1.jpg val/fg/fg2.jpg bg/bg2.jpg val/trimap/trimap2.jpg val/fg/fg3.jpg bg/bg3.jpg val/trimap/trimap3.jpg ... ``` -------------------------------- ### Example Training List Format Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/LaneSeg/README.md Illustrates the expected format for 'train_list.txt', mapping image file paths to their corresponding label file paths. ```text /train_set/clips/0313-1/6040/20.jpg /train_set/labels/0313-1/6040/20.png /train_set/clips/0313-1/5320/20.jpg /train_set/labels/0313-1/5320/20.png /train_set/clips/0313-1/23700/20.jpg /train_set/labels/0313-1/23700/20.png ... ``` -------------------------------- ### Training Configuration Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/test_tipc/configs/ocrnet_hrnetw48/train_pact_infer_python.txt Command for executing QAT training using the specified configuration file and device settings. ```bash deploy/slim/quant/qat_train.py --config test_tipc/configs/ocrnet_hrnetw48/ocrnet_hrnetw48_cityscapes_1024x512.yml --device gpu --save_interval 500 --seed 100 --num_workers 8 ``` -------------------------------- ### View Export Help Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/LaneSeg/README.md Run this command to see all available parameters for the export script. ```shell python export.py --help ``` -------------------------------- ### Install GDAL Dependency on Linux/Mac Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/EISeg/docs/remote_sensing_en.md Install the GDAL package using the conda package manager. ```bash conda install gdal ``` -------------------------------- ### Directory Structure for Configuration Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/MedicalSeg/documentation/tutorial.md This is an example of the configuration directory structure for a dataset. It includes base configurations, dataset-specific settings, and model-related configurations. ```bash ├── _base_ │ └── global_configs.yml ├── lung_coronavirus │ ├── lung_coronavirus.yml │ ├── README.md │ └── vnet_lung_coronavirus_128_128_128_15k.yml ``` -------------------------------- ### Example Output Directory Structure Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/test_tipc/docs/test_train_inference_python.md Shows the expected file structure in test_tipc/output after running a training and inference chain. ```text test_tipc/output/[model name]/ |- results_python.log # 运行指令状态的日志 |- norm_train_gpus_0_autocast_null/ # GPU 0号卡上正常训练的训练日志和模型保存文件夹 |- pact_train_gpus_0_autocast_null/ # GPU 0号卡上量化训练的训练日志和模型保存文件夹 ...... |- python_infer_cpu_usemkldnn_True_threads_1_precision_fp32_batchsize_1.log # CPU上开启Mkldnn线程数设置为1,测试batch_size=1条件下的fp32精度预测日志 |- python_infer_gpu_usetrt_True_precision_fp16_batchsize_1.log # GPU上开启TensorRT,测试batch_size=1的半精度预测日志 ...... ``` -------------------------------- ### Install EISeg via PIP Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/EISeg/docs/install_en.md Install the EISeg package directly from the Python Package Index. ```bash pip install eiseg ``` -------------------------------- ### Install GDAL Dependency on Windows Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/EISeg/docs/remote_sensing_en.md Install the specific GDAL wheel file using pip. ```bash pip install GDAL‑3.3.3‑cp39‑cp39‑win_amd64.whl ``` -------------------------------- ### Create build directory Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/deployment/inference/cpp_inference_windows_cn.md Create a build directory and navigate into it for compilation artifacts. ```bash mkdir build cd build ``` -------------------------------- ### Launch PaddleSeg Simple Serving Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/deploy/fastdeploy/semantic_segmentation/serving/simple_serving/README.md Launch the FastDeploy simple serving application. Customize configurations in server.py for hardware and backend selection. Use --host and --port to specify the IP and port. ```bash fastdeploy simple_serving --app server:app ``` -------------------------------- ### Install PaddlePaddle CPU Version Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/test_tipc/docs/test_train_amp_inference_python.md Install the CPU version of PaddlePaddle. Ensure you have version 2.2 or higher. ```bash pip install paddlepaddle==2.2.2 ``` -------------------------------- ### Detailed Model Training with Logging and Evaluation Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/PanopticSeg/docs/full_features_en.md This command demonstrates a typical training setup with specified configuration, logging frequency, number of workers, and enabling both semantic and instance evaluation during training. Output is piped to a log file. ```shell TAG='mask2former' python tools/train.py \ --config configs/mask2former/mask2former_resnet50_os16_coco_1024x1024_bs4_370k.yml \ --log_iters 50 \ --num_workers 4 \ --do_eval \ --eval_sem \ --eval_ins \ --save_dir "output/${TAG}" \ 2>&1 \ | tee "output/train_${TAG}.log" ``` -------------------------------- ### Install PaddlePaddle GPU Version Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/test_tipc/docs/test_train_amp_inference_python.md Install the GPU version of PaddlePaddle. Ensure you have version 2.2 or higher. ```bash pip install paddlepaddle-gpu==2.2.2 ``` -------------------------------- ### MKL and Math Library Setup Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/test_tipc/cpp/CMakeLists.txt Configures MKL or OpenBLAS math libraries and MKLDNN paths. ```cmake if(WITH_MKL) include_directories("${PADDLE_LIB}/third_party/install/mklml/include") if (WIN32) set(MATH_LIB ${PADDLE_LIB}/third_party/install/mklml/lib/mklml.lib ${PADDLE_LIB}/third_party/install/mklml/lib/libiomp5md.lib) else () set(MATH_LIB ${PADDLE_LIB}/third_party/install/mklml/lib/libmklml_intel${CMAKE_SHARED_LIBRARY_SUFFIX} ${PADDLE_LIB}/third_party/install/mklml/lib/libiomp5${CMAKE_SHARED_LIBRARY_SUFFIX}) execute_process(COMMAND cp -r ${PADDLE_LIB}/third_party/install/mklml/lib/libmklml_intel${CMAKE_SHARED_LIBRARY_SUFFIX} /usr/lib) endif () set(MKLDNN_PATH "${PADDLE_LIB}/third_party/install/mkldnn") if(EXISTS ${MKLDNN_PATH}) include_directories("${MKLDNN_PATH}/include") if (WIN32) set(MKLDNN_LIB ${MKLDNN_PATH}/lib/mkldnn.lib) else () set(MKLDNN_LIB ${MKLDNN_PATH}/lib/libmkldnn.so.0) endif () endif() else() if (WIN32) set(MATH_LIB ${PADDLE_LIB}/third_party/install/openblas/lib/openblas${CMAKE_STATIC_LIBRARY_SUFFIX}) else () ``` -------------------------------- ### Install GPU PaddlePaddle for Naive Method Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/docs/deployment/inference/python_inference.md Install the GPU-enabled version of PaddlePaddle for CUDA 10.1 environments. ```bash # CUDA10.1 PaddlePaddle python -m pip install paddlepaddle-gpu==2.1.2.post101 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html ``` -------------------------------- ### Basic Model Training Command Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/contrib/PanopticSeg/docs/full_features_en.md Use this command to start model training. The `--config` argument specifies the configuration file path. Command-line arguments have higher precedence than configuration file settings. ```shell python tools/train.py \ --config {CONFIG_PATH} ``` -------------------------------- ### Install PaddlePaddle (CPU) Source: https://github.com/paddlepaddle/paddleseg/blob/release/2.10/deploy/slim/act/readme.md Install the CPU version of PaddlePaddle for Linux. Ensure you are using the develop branch. ```shell python -m pip install paddlepaddle==0.0.0 -f https://www.paddlepaddle.org.cn/whl/linux/cpu-mkl/develop.html ```