In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "how to use Python code to achieve batch buckle map", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use Python code to achieve batch buckle map" article.
1. Preparation-install paddlepaddle
Since you have to pretend to be forced, it is necessary to make preparations. As the saying goes, "stand on the shoulders of giants and get twice the result with half the effort". Our "giant" here is paddlepaddle, the Chinese name is "flying oars", so what is this paddlepaddle?
It is "an open source deep learning platform derived from industrial practice, dedicated to making the innovation and application of deep learning technology easier." to put it bluntly, I have helped you implement the underlying framework of deep learning. As long as you are creative, you can easily implement it with a small amount of simple code on my platform. Its official website is https://www.paddlepaddle.org.cn/.
Its installation is relatively simple. There are installation instructions on the home page of the official website. You can find the installation details and precautions of each system through the "installation" menu. As shown in the following figure, we use pip to install the CPU version here according to the installation guidelines of the official website.
This paper takes the MacOS system as an example:
Let's first execute the following command to install (Baidu source is recommended):
Python3-m pip install paddlepaddle-I https://mirror.baidu.com/pypi/simple
Or:
Python3-m pip install paddlepaddle-I https://pypi.tuna.tsinghua.edu.cn/simple
From the installation process, you can see that when you install the paddlepaddle library, you need to install the following dependent libraries:
Installing collected packages: pathlib, click, joblib, regex, tqdm, nltk, gast, rarfile, pyyaml, funcsigs, paddlepaddle Running setup.py install for pathlib... Done Running setup.py install for regex... Done Running setup.py install for nltk... Done Running setup.py install for rarfile... Done Running setup.py install for pyyaml... DoneSuccessfully installed click-7.1.2 funcsigs-1.0.2 gast-0.3.3 joblib-0.14.1 nltk-3.5 paddlepaddle-1.8.0 pathlib-1.0.1 pyyaml-5.3.1 rarfile-3.1 regex-2020.5.7 tqdm-4.46.0
After the installation is successful, we test whether the installation is successful in the python environment (this is also done in accordance with the guidelines of the official website). We switch to the python environment and run the following code:
➜~ python3Python 3.7.4 (default, Jul 9 2019, 18:15:00) [Clang 10.0.0 (clang-1000.11.45.5)] on darwinType "help", "copyright", "credits" or "license" for more information. > > import paddle.fluid > paddle.fluid.install_check.run_check () Running Verify Fluid Program... Your Paddle Fluid works well on SINGLE GPU or CPU.W0512 17 Vane 4131.037240 2844976000 build_strategy.cc:170] fusion_group is not enabled for Windows/MacOS now And only effective when running with CUDA GPU.W0512 17:41:31.043959 2844976000 fuse_all_reduce_op_pass.cc:74] Find all_reduce operators: 2. To make the speed faster, some all_reduce ops are fused during training, after fusion, the number of all_reduce ops is 1.Your Paddle Fluid works well on MUTIPLE GPU or CPU.Your Paddle Fluid is installed successfully! Let's start deep Learning with Paddle Fluid now
If you can see the Your Paddle Fluid is installed successfully, it means that the installation is successful.
two。 Preparation-install paddlehub
In order to realize the one-click batch buttoning requirements in this paper, we need to use the PaddleHub portrait segmentation model to achieve.
PaddleHub is a pre-training model management tool developed based on PaddlePaddle, which can carry out transfer learning more easily with the help of pre-training model. The current pre-training model covers the mainstream models such as image classification, target detection, lexical analysis, semantic model, emotion analysis, video classification, image generation, image segmentation, text review, key point detection and so on.
PaddleHub official website: https://www.paddlepaddle.org.cn/hub
After introducing the project, let's start installing paddlehub online:
Pip install-I https://mirror.baidu.com/pypi/simple paddlehub
Or install according to the specified version:
Pip install paddlehub==1.6.0-I https://pypi.tuna.tsinghua.edu.cn/simple
After the installation is complete, we can start to use it.
3. Code implementation of one-button buckle diagram
Our implementation steps are simple:
Import module
Loading model
Get picture file
Calling module matting
Among them, the button map function mainly adopts PaddleHub DeepLabv3+ model deeplabv3p_xception65_humanseg.
Let's take a look at the specific button code implementation (demo.py):
Import osimport paddlehub as hub # load model humanseg = hub.Module (name='deeplabv3p_xception65_humanseg') base_dir = os.path.abspath (os.path.dirname (_ _ file__)) # get the current file directory path = os.path.join (base_dir 'images/') # get file list files = [path + i for i in os.listdir (path)] print (files) # matting results = humanseg.segmentation (data= {' image': files}) for result in results: print (result)
In the example, I put the picture in the code folder's sibling directory images folder, after running the code, the output matting image will be automatically placed in the code peer directory's humanseg_output directory, the file name is the same as the original picture name, but the file format is png.
Among them, the sample images directory has 9 pictures. In order to take into account the tastes of different readers, the sample pictures include both handsome men and beautiful women, and their thumbnails are enlarged.
We can see that the program identifies the characters in each picture (either one person or multiple people) and scratches them out into a picture with a white background. Although there are still some flaws in some of the details, they look pretty good.
4. Need to pay attention to the pit
When running the sample code, if the model deeplabv3p_xception65_humanseg is not installed separately, it will be installed automatically by default before execution. However, after the installation is completed, the execution result does not generate the button result and the humanseg_output directory.
This can be solved by installing the model separately and specifying the installation version.
Hub install deeplabv3p_xception65_humanseg==1.0.0
The specific reason has not been studied in detail. When the model is installed automatically by default, the version is 1.2.0. It is speculated that it is still caused by the incompatibility of the model version.
The above is about the content of this article on "how to use Python code to realize batch snapping". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.