Kubernetes-based remote sensing image semantic segmentation model servitization method
By using Kubernetes cluster and deep learning framework to encapsulate model images in the field of remote sensing, the problems of environmental compatibility and resource utilization efficiency in the service process of remote sensing model are solved, and the general model service interface and automated data processing are realized, which lowers the application threshold. Improve the efficiency of remote sensing data processing.
Patent Information
- Application Number
- CN202411222877.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-03
- Publication Date
- 2024-12-27
AI Technical Summary
Deep learning models in the remote sensing field face problems such as low environmental compatibility, low resource utilization efficiency and high application threshold in the process of service, especially in multi-model deployment and rapid algorithm deployment.
The Kubernetes cluster is used to encapsulate the semantic segmentation model into a container image, and service it through TensorFlow Serving and TorchServe, build YAML file deployment model services, and write remote sensing data processing scripts to realize data preprocessing, model service requests and output post-processing.
It solves the problem of incompatibility of multi-model environments, provides a general model service interface, lowers the application threshold, and improves the efficiency and rapid deployment capabilities of remote sensing data processing.
Smart Images

Figure CN119206445A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of remote sensing data processing and containerization, and in particular to a Kubernetes-based remote sensing image semantic segmentation model service method. Background Art
[0002] In recent years, with the rapid development of aerospace science and technology, remote sensing data has shown obvious "big data" characteristics. In the context of remote sensing big data, more and more semantic segmentation models are being used in the process of remote sensing data processing. In the typical development cycle of a deep learning project, the entire process covers multiple links from data acquisition, preprocessing, feature engineering, model design, training and evaluation. The ultimate goal is to successfully deploy the model online to provide services. Therefore, after the model training phase is completed, the trained model needs to be packaged and deployed so that it can provide model reasoning functions to the outside world as a service. This process is usually referred to as model servitization. In the field of remote sensing, model servitization has gradually become the key to the engineering implementation of these deep learning models used in the remote sensing field.
[0003] However, semantic segmentation models used in remote sensing face the following problems in the process of service-oriented development: (1) Deep learning algorithms in remote sensing are usually developed in a single environment, with low compatibility between different software and hardware environments, making algorithm integration difficult. (2) Due to the complex characteristics of remote sensing images and models, it is usually impossible to directly call deep learning model services. Complex data preprocessing and output post-processing processes are required before the results can be output, which raises the application threshold of remote sensing model services.
[0004] Traditional virtual machine technology (Kernel-based Virtual Machine, KVM) provides a solution that allows model deployment and calculation on a virtual machine with a basic operating system installed. However, deep learning algorithms usually rely on deep learning frameworks such as Tensorflow and PyTorch. When multiple models trained by different development frameworks are run on the same virtual machine at the same time, many conflicts may occur during model runtime due to differences in operating environment and version. At the same time, virtual machines based on hardware virtualization also face problems such as low resource utilization efficiency, slow scheduling and distribution, and difficulty in accessing physical machine GPUs, making it difficult to meet the needs of rapid algorithm deployment and product production in the era of remote sensing big data.
[0005] Therefore, a remote sensing image semantic segmentation model service method based on Kubernetes is provided to solve the above technical problems. Summary of the invention
[0006] The purpose of the present invention is to provide a remote sensing image semantic segmentation model service method based on Kubernetes, which encapsulates the trained semantic segmentation model as a container image and deploys it in a Kubernetes cluster to provide a general model reasoning service to the outside world. In view of the problem that the model service interface cannot be directly called due to the complex characteristics of remote sensing data, a remote sensing data processing script is constructed to realize data preprocessing, model service request and output post-processing.
[0007] The object of the present invention is achieved in that: A remote sensing image semantic segmentation model service method based on Kubernetes, characterized by comprising the following steps: Step S1: Build a Kubernetes cluster; The purpose of building a cluster in step S1 is to provide a deployment environment and a management environment for the container of the semantic segmentation model. This patent will deploy the semantic segmentation model container in the Kubernetes cluster and use the Kubernetes cluster to manage the deployed model container. Step S2. Encapsulate the semantic segmentation model image based on TensorFlow Serving and TorchServe; The purpose of encapsulating the image in step S2 is to provide a template for the model container for step S3. Step S3 will generate the corresponding model container based on the instantiation of the semantic segmentation model image. The image is a read-only template used to create a container. The image contains everything needed for the application to run, including code and variable environment. TensorFlowServing and TorchServe are mainstream deep learning model service frameworks. Building images based on these mainstream frameworks can better meet the model's operating environment; Step S3. Deploy the semantic segmentation model image encapsulated in step S2 to the Kubernetes cluster built in step S1, and build a YAML file to deploy the model service; The purpose of step S3 to deploy the model container is to generate a model container based on the image encapsulated in S2 and deploy it to the Kubernetes cluster built in S1. After the model container is successfully deployed to the cluster, the model container can provide a semantic segmentation model service interface to the outside world, and the model service can be used by remotely calling the model service interface; Step S4. Build a remote sensing data processing script to automatically implement data preprocessing, request model services, and output post-processing. The purpose of building a remote sensing data processing script in step S4 is that the model service interface deployed by S3 receives input in vector form, so data preprocessing is required to convert the input image to be processed into a vector, and then send a request to the model service interface. After the request is completed, the output result is received and then the output is post-processed to convert it into a usable processing result. S4 aims to automate this process in the form of a script.
[0008] The specific operation of step S1 is as follows: Step S1.1 installs the Kubernetes cluster dependency environment of Docker, Kubeadm and Kubectl on each node of the cluster; Step S1.2: Use the Kubeadm tool to initialize the master node, copy the config file to the kube directory of the master node, and configure Kubectl so that the master node can communicate with the Kubernetes API server. Step S1.3: Run the kubeadmjoin command on the computing node to join the computing node to the Kubernetes cluster and complete the Kubernetes cluster construction.
[0009] The specific operation of step S2 is as follows: Step S2.1 For the TensorFlow model, first, convert the trained TensorFlow model into the SavedModel file format; second, write the Dockerfile file, specify TensorFlow Serving as the base image and copy the model file to the specified location in the container; finally, execute the "Docker Build" command to generate a new TensorFlow model image based on the Dockerfile file; Step S2.2: For the Pytorch model, first, convert the trained Pytorch model into the .mar file format; second, write the Dockerfile file, specify TorchServe as the base image, and copy the model file and configuration file to the specified location in the container; finally, execute the "DockerBuild" command to generate a new Pytorch model image according to the Dockerfile file.
[0010] The specific operation of step S3 is as follows: Step S3.1 builds a YAML file that defines the Kubernetes Deployment object, and then executes the Kubectl command to parse the file. The computing node initializes and starts the Pod containing the semantic segmentation model service according to the requirements of the Deployment object, in which the model service container encapsulated above is running; S3.2 builds a YAML file that defines the Kubernetes Service object, and then executes the Kubectl command to parse the file. The API server will create a Service object, aggregate multiple Pods that provide the same service, and provide a unified entry address.
[0011] The specific operation of step S4 is as follows: Step S4.1 Data preprocessing: First, convert the remote sensing image into a multidimensional tensor and adjust the image to the size required by the model input. Then, convert the adjusted image tensor into a data type suitable for model processing, such as floating point type, and serialize it into a transferable format. Finally, package the serialized data and the model signature into a Json data to send an inference request to the model service API. Step S4.2: Request model service: First, define the RestAPI interface of the model service, then send the Json data constructed in step S4.1 to the interface to request the model service to make a prediction; Step S4.3 output post-processing: First, convert the Json data returned by the API into a dictionary object, then parse the prediction results from the dictionary object and convert them into an array. After that, compress the array and convert it into a three-dimensional array. Binarize the predicted values in the array. Finally, multiply the binarized pixel values by 255, convert them into a grayscale image, and save them.
[0012] The beneficial effects of the present invention are as follows: the present invention provides a semantic segmentation model service method based on Kubernetes cluster, solves the problem of environmental incompatibility between multiple algorithm models, and provides a general model service interface to the outside world to support remote calls. In addition, the remote sensing data processing script constructed by the present invention can automatically perform data preprocessing, request model services and output post-processing, which reduces the threshold for applying semantic segmentation models to remote sensing image processing. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 is a flow chart of the present invention; Figure 2 This is a diagram showing the processing results of remote sensing images using the semantic segmentation models of the present invention. DETAILED DESCRIPTION
[0014] The present invention is further described below in conjunction with the accompanying drawings and embodiments.
[0015] A Kubernetes-based remote sensing image semantic segmentation model service method Figure 1 As shown, the following steps are included: Step S1 builds a Kubernetes cluster. The specific operations are as follows: Step S1.1 installs Docker, Kubeadm, and Kubectl on each node of the cluster. In step S1.2, use Kubeadm to initialize the master node and copy the config file to the .kube directory of the master node to configure Kubectl. After that, you can access the Kubernetes API to control the cluster through Kubectl.
[0016] Step S1.3: Run the Kubeadmjoin command on the compute node to join the compute node to the Kubernetes cluster.
[0017] Step S2 encapsulates the semantic segmentation model image based on TensorFlow Serving and TorchServe. The specific operations are as follows: Step S2.1 For the TensorFlow model, first, convert the trained TensorFlow model into the SavedModel file format; second, write the Dockerfile file, specify TensorFlow Serving as the base image and copy the model file to the specified location in the container; finally, execute the "Docker Build" command to generate a new TensorFlow model image based on the Dockerfile file.
[0018] Step S2.2: For the Pytorch model, first, convert the trained Pytorch model into the .mar file format; second, write the Dockerfile file, specify TorchServe as the base image, and copy the model file and configuration file to the specified location in the container; finally, execute the "DockerBuild" command to generate a new Pytorch model image according to the Dockerfile file.
[0019] Step S3 deploys the semantic segmentation model image encapsulated in step S2 to the Kubernetes cluster built in step S1, and builds a YAML file to deploy the model service. The specific operations are as follows: Step S3.1 builds a YAML file that defines a Deployment object, and then executes the "Kubectl apply-f" command to make the YAML file effective, and deploys the encapsulated model service to the Kubernetes cluster; that is, builds a YAML file that defines a Kubernetes Deployment object, and then executes the Kubectl command to parse the file. The computing node will initialize and start the Pod containing the semantic segmentation model service according to the requirements of the Deployment object, in which the model service container that has been encapsulated above is running. Taking the Unt4 model as an example, the main contents of the YAML file that defines the Deployment object to deploy the model are as follows: First, define the replicas parameter to ensure that there are always a fixed number of Unet4 Pods running in the cluster; then, define the image and ports parameters to specify the model image name, version, and port number of the container to be run; finally, define the args parameter to set the startup parameters of TensorFlow Serving, and mount the data volume by defining the volumes parameter so that the computing node can access the model input image on the master node.
[0020] Step S3.2 builds a YAML file that defines the Service object, and then executes the "Kubectl apply-f" command to make the YAML file effective and expose the model service interface deployed in the cluster. Taking the Unet4 model as an example, the main contents of the YAML file that defines the Service object are as follows: First, define the metadata of the Service through metadata, including the name and label; then, define the proxy Pod through selector; finally, define the nodePort parameter to determine the IP that can be accessed outside the cluster, and define the targetPort parameter to determine the port inside the Pod.
[0021] Step S4: Due to the difference between the format of remote sensing images and the input format expected by the deep learning model, it is impossible to directly input the remote sensing images into the model service deployed in step 3 for inference. It is necessary to build a remote sensing data processing script to automatically implement data preprocessing, request model services, and output post-processing. The specific operations are as follows: Step S4.1 builds the data preprocessing process, which mainly includes reading the remote sensing image to be predicted; defining the model prediction interface; performing data preprocessing on each remote sensing image in a loop; that is, first converting the remote sensing image into a multidimensional tensor and adjusting the image to the size required for the model input, then converting the adjusted image tensor into a data type suitable for model processing, such as a floating point type, and serializing it into a transferable format. Finally, the serialized data and the model signature are packaged into a Json data to send an inference request to the model service API. Taking the Unet4 model as an example, the code for reading the remote sensing image to be predicted is: img_dir = ".unet4 / image / *.png"; the code for defining the model prediction interface is: api_url = / v1 / models / unet_4 / predict; the main code for data preprocessing is: img = tf.image.decode_png (img, channels = 3).
[0022] Step S4.2 builds the process of requesting the model service, which mainly includes constructing a model request; sending a request to the model service, that is, first, defining the RestAPI interface of the model service, and then sending the Json data constructed in 4.1 to the interface to request the model service to make a prediction. Taking the Unet4 model as an example, the code for building the model request is: data = {"signature_name":"serving_default", "instances": [{"input_2":img_list}]}; the code for sending a request to the model service is: response = requests.post (api_url, json = data).
[0023] Step S4.3 constructs the output post-processing process, which mainly includes extracting the prediction results; processing the prediction results; and outputting the prediction image, that is, first, converting the Json data returned by the API into a dictionary object, parsing the prediction results from the dictionary object and converting them into an array, then compressing the array, converting it into a three-dimensional array, binarizing the prediction values in the array, and finally multiplying the binarized pixel values by 255, converting it into a grayscale image, and saving it. Taking the Unet4 model as an example, the code for extracting the prediction results is: result = response.json(); the main code for processing the prediction results is pred = np.array(result["predictions"]); the code for outputting the prediction image is: cv2.imwrite(". / pred / "+png.split(' / ')[-1].split('.')[0]+ “.png”, pre_img). Figure 2This is the processing result of remote sensing images by various semantic segmentation models using this method.
[0024] Figure 2 In the figure, the left picture is the original remote sensing image, and the right picture is the output image after the four different semantic segmentation models are processed by the remote sensing data processing script after being serviced by this method. It can be seen that the present invention successfully identifies the landslide area in the original image and displays it in the form of a binary image, which verifies the feasibility and effectiveness of this method.
Claims
1. A Kubernetes-based remote sensing image semantic segmentation model service method, characterized by: The following steps are involved: Step S1: Build a Kubernetes cluster; provide a deployment environment and a management environment for the container of the semantic segmentation model, deploy the semantic segmentation model container in the Kubernetes cluster, and use the Kubernetes cluster to manage the deployed model container; Step S2: Encapsulate the semantic segmentation model image based on TensorFlow Serving and TorchServe to provide a model container template for step S3; Step S3: Deploy the semantic segmentation model image encapsulated in step S2 to the Kubernetes cluster built in step S1, and build a YAML file to deploy the model service; generate a model container according to the image encapsulated in step S2, and deploy it to the Kubernetes cluster built in step S1; after the model container is successfully deployed to the cluster, the model container provides a semantic segmentation model service interface to the outside, that is, the model service is used by remotely calling the model service interface; Step S4: Construct a remote sensing data processing script to automatically implement data preprocessing, request model services, and output post-processing; the model service interface deployed in step S3 receives input in vector form, converts the input image to be processed into a vector after data preprocessing, and then sends a request to the model service interface. After the request is completed and the output result is received, the output is post-processed and converted into a usable processing result; step S4 aims to automate the process in the form of a script.
2. The Kubernetes-based remote sensing image semantic segmentation model service method according to claim 1, characterized in that: The specific operation of step S1 is as follows: Step S1.1 Install the Kubernetes cluster dependency environment of Docker, Kubeadm and Kubectl on each node of the cluster; Step S1.2 Use the Kubeadm tool to initialize the master node, copy the config file to the kube directory of the master node, and configure Kubectl so that the master node can communicate with the Kubernetes API server; Step S1.3 Run the kubeadm join command on the computing node to add the computing node to the Kubernetes cluster and complete the Kubernetes cluster construction.
3. The Kubernetes-based remote sensing image semantic segmentation model service method according to claim 1, characterized in that: The specific operation of step S2 is as follows: Step S2.1 For the TensorFlow model, first, convert the trained TensorFlow model into the SavedModel file format; second, write the Dockerfile file, specify TensorFlow Serving as the base image and copy the model file to the specified location in the container; finally, execute the "Docker Build" command to generate a new TensorFlow model image based on the Dockerfile file; Step S2.2 For the Pytorch model, first, convert the trained Pytorch model into the .mar file format; second, write the Dockerfile file, specify TorchServe as the base image, and copy the model file and configuration file to the specified location in the container; finally, execute the "Docker Build" command to generate a new Pytorch model image according to the Dockerfile file.
4. The Kubernetes-based remote sensing image semantic segmentation model service method according to claim 1, characterized in that: The specific operation of step S3 is as follows: Step S3.1 builds a YAML file that defines the Kubernetes Deployment object, and then executes the Kubectl command to parse the file. The computing node initializes and starts the Pod containing the semantic segmentation model service according to the requirements of the Deployment object, in which the model service container encapsulated above is running; Step S3.2 builds a YAML file that defines the Kubernetes Service object, and then executes the Kubectl command to parse the file. The API server will create a Service object, aggregate multiple Pods that provide the same service, and provide a unified entry address.
5. The Kubernetes-based remote sensing image semantic segmentation model service method according to claim 1, characterized in that: The specific operation of step S4 is as follows: Step S4.1 Data preprocessing: First, convert the remote sensing image into a multidimensional tensor and adjust the image to the size required by the model input. Then, convert the adjusted image tensor into a data type suitable for model processing and serialize it into a transferable format. Finally, package the serialized data and the model signature into a Json data to send an inference request to the model service API. Step S4.2: Request model service: First, define the Rest API interface of the model service, then send the Json data constructed in step S4.1 to the interface to request the model service to make a prediction; Step S4.3 output post-processing: First, convert the Json data returned by the API into a dictionary object, then parse the prediction results from the dictionary object and convert them into an array. After that, compress the array and convert it into a three-dimensional array. Binarize the predicted values in the array. Finally, multiply the binarized pixel values by 255, convert them into a grayscale image, and save them.
