How to deploy TensorFlow on Windows
By calling deep learning object under the Windows system to process TensorFlow tasks and converting the results into suitable data types, the problem of large amount of code modification required for TensorFlow deployment is solved, and the compatibility between TensorFlow and Windows systems is achieved.
Patent Information
- Application Number
- CN202011620128.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-31
- Publication Date
- 2024-12-20
- Estimated Expiration
- 2040-12-31
AI Technical Summary
When deploying TensorFlow on Windows systems, existing methods require a lot of code modification, and the upgraded TensorFlow does not support dynamic compilation of library files, resulting in difficulty in deployment.
The deep learning class object is called by the application software. The object is generated by Python code, which processes the pending object and converts the result to a data type suitable for the first language, so as to implement TensorFlow on the Windows system without modifying the original TensorFlow code. Deployment and compatibility.
Reduces the amount of code you need to modify to apply TensorFlow to Windows systems and makes upgraded TensorFlow compatible with Windows systems.
Smart Images

Figure CN112685050B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method for deploying TensorFlow in a Windows system. Background Art
[0002] TensorFlow is a symbolic mathematics system based on data flow programming. It is widely used in the programming implementation of various machine learning algorithms. Traditional TensorFlow is mostly deployed on Linux systems, and less deployed on Windows systems. The deployment on Windows systems mainly relies on compiling TensorFlow's dynamic compilation library on Windows systems and rewriting TensorFlow code through TensorFlow's C extension application programming interface (API). TensorFlow code is mainly implemented in Python language. The workload of rewriting code is large, and after the TensorFlow version is upgraded, the dynamic compilation library files on Windows systems are no longer supported. Therefore, a new method of deploying TensorFlow on Windows systems is urgently needed. Summary of the invention
[0003] The main technical problem solved by this application is to provide a method for deploying TensorFlow under Windows system, which can reduce the amount of code modification required to apply TensorFlow to Windows system.
[0004] To solve the above technical problems, a technical solution adopted in the present application is: to provide a deployment method of TensorFlow under the Windows system, the method comprising: when obtaining an object to be processed, the application software calls a deep learning class object, wherein the application software is an application software developed in a first language, and the deep learning class object is generated by the application software calling python code, and the first language is different from the python language; the application software runs a session according to the address saved in the deep learning class object to process the object to be processed and obtain a first execution result; the application software converts the first execution result into a second execution result to obtain a processing result of the object to be processed.
[0005] To solve the above technical problems, another technical solution adopted in the present application is: providing a computer device, including a processor and a memory, and the computer device is installed with application software, the processor is coupled to the memory, the memory stores program data, and the processor controls the application software to implement the steps in the above method by executing the program data in the memory.
[0006] In order to solve the above technical problem, another technical solution adopted by the present application is: providing a computer-readable storage medium storing a computer program, wherein the computer program can be executed by a processor to implement the steps in the above method.
[0007] The beneficial effect of the present application is that when the method in the present application obtains the object to be processed, the deep learning class object is first called, and the deep learning class object is generated by the application software calling the python code. Then the application software runs the session according to the address saved in the deep learning class object, and uses the running session to process the object to be processed to obtain a first execution result. Since the data type of the first execution result is the data type of python, the first execution result is also converted into a second execution result, so that the final execution result is adapted to the application software developed using the first language, and finally adapted to the Windows system, so that when TensorFlow is deployed under the Windows system, there is no need to use the first language supported by the application software to re-modify the original python code of TensorFlow, which can not only reduce the amount of code modification required to apply TensorFlow to the Windows system, but also make the upgraded TensorFlow compatible with the Windows system. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. Among them:
[0009] Figure 1 This is a flow chart of an implementation method of deploying TensorFlow in Windows system of the present application;
[0010] Figure 2 This is a partial flow chart of an implementation method of deploying TensorFlow in Windows system of this application;
[0011] Figure 3 It is a structural schematic diagram of an implementation method of a computer device of the present application;
[0012] Figure 4 It is a structural schematic diagram of an implementation method of a computer-readable storage medium of the present application. DETAILED DESCRIPTION
[0013] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0014] First of all, it should be noted that the method in this application can be used to deploy TensorFlow to a computer device installed with a Windows system. TensorFlow is a symbolic mathematical system based on data flow programming, which is widely used in the programming implementation of various deep learning algorithms. Currently, the code of TensorFlow is mainly Python code.
[0015] See also Figure 1 , Figure 1 This is a flow chart of an implementation method of deploying TensorFlow in Windows system of the present application, which includes:
[0016] S110: When the object to be processed is obtained, the application software calls the deep learning class object, wherein the application software is an application software developed in a first language, and the deep learning class object is generated by the application software calling python code, and the first language is different from the python language.
[0017] Specifically, the object to be processed may be a picture to be processed, a video to be processed, an audio to be processed, etc., and the application software is software for processing the object to be processed. For example, the application software is a visual application software having a target detection function. The object to be processed is a picture to be processed including a workpiece to be detected. The visual application software is used to identify the picture to be processed to determine whether there are defects on the workpiece to be detected.
[0018] At the same time, the application software is developed in a first language different from the Python language, and the application software developed in the first language can be applied to the Windows system. In one application scenario, the first language is the C language or the C++ language, and in other application scenarios, the first language can also be other languages such as the Java language, which is not limited here.
[0019] The deep learning class object is a class object used to perform deep learning tasks, and deep learning tasks use TensorFlow. At the same time, the TensorFlow code is mainly Python code.
[0020] In an application scenario, in addition to the processing function based on deep learning, the application software also has the processing function not based on deep learning. The user can select the processing function of the application software. At this time, in order to save energy consumption, after receiving the object to be processed, the application software will call the deep learning class object only when it detects that the user chooses to use the processing function based on deep learning to process the object to be processed. Specifically, at this time, step S110 specifically includes: when the object to be processed is obtained, if a selection instruction input by the user is received, the application software calls the deep learning class object. Among them, the selection instruction is an instruction for the user to choose to use the processing function based on deep learning of the application software to process the object to be processed.
[0021] For ease of understanding, we will still use the application software mentioned above as an example:
[0022] The visual application software can identify the image to be processed to determine whether there are defects on the workpiece to be tested. The visual application software processes the image to be processed in two ways, one is a deep learning-based function, and the other is a common, non-deep learning-based function (such as database-based detection). At the same time, it is assumed that the deep learning-based function has two target detection models, one is a first detection model for detecting circular defects on the workpiece to be tested, and the other is a second detection model for detecting square defects on the workpiece to be tested.
[0023] When the user inputs the image to be processed into the application software, if it is detected that the user chooses to use the first detection model or the second detection model to process the image to be processed, it is determined that the selection instruction input by the user is received, and then the application software calls the deep learning class object; if it is detected that the user chooses to use the ordinary function to process the image to be processed, the deep learning class object is not called.
[0024] It is understandable that in other application scenarios, when the application software only has processing functions based on deep learning, after obtaining the object to be processed, the application software will automatically call the deep learning class object without the need for user selection.
[0025] S120: The application software runs a session according to the address stored in the deep learning class object to process the object to be processed and obtain a first execution result.
[0026] Specifically, the address of a session is stored in the deep learning class object, and the application software runs the corresponding session according to the address, and uses the session to process the object to be processed, thereby obtaining a first execution result.
[0027] It is understandable that since the deep learning class object is generated by the application software calling the python code, the data type of the generated first execution result is the python data type. In one application scenario, the data type of the first execution result is the NumPy data type, where NumPy (Numerical Python) is an open source numerical computing extension of Python. This tool can be used to store and process large matrices. It is much more efficient than Python's own nested list structure, and can support a large number of dimensional arrays and matrix operations. In addition, it can also provide a large number of mathematical function libraries for array operations.
[0028] S130: The application software converts the first execution result into a second execution result to obtain a processing result of the object to be processed.
[0029] Specifically, the data type of the second execution result corresponds to the first language. For example, when the first language is C++, the data type of the second execution result is a C++ data type. When the first language is C, the data type of the second execution result is a C data type.
[0030] For example, when the first language is C++, the following code may be used to convert the first execution result into the second execution result:
[0031] Py_object = py_fun(res);
[0032] C_data = func(Py_object)
[0033] The first line of code indicates obtaining the first execution result, and the second line of code indicates converting the first execution result into the second execution result.
[0034] The purpose of converting the first execution result into the second execution result is to make the final processing result compatible with the application software and finally compatible with the Windows system.
[0035] From the above content, it can be seen that when the object to be processed is obtained, the present embodiment first calls the deep learning class object, which is generated by the application software calling the python code, and then the application software runs the session according to the address saved in the deep learning class object, and uses the running session to process the object to be processed to obtain a first execution result. Since the data type of the first execution result is the data type of python, the first execution result is also converted into a second execution result, so that the final execution result is adapted to the application software developed using the first language, and finally to the Windows system, so that when TensorFlow is deployed under the Windows system, there is no need to use the first language supported by the application software to re-modify the original python code of TensorFlow, which can reduce the amount of code modification required to apply TensorFlow to the Windows system, and can also make the upgraded TensorFlow compatible with the Windows system.
[0036] See also Figure 2 , before the application software calls the deep learning class object in step S110, it also includes:
[0037] S140: The application software is initialized and a Python interpreter is generated.
[0038] Specifically, the application software is initialized through the extended application interface officially provided by Python to generate a Python interpreter, wherein the Python interpreter is invisible to the user and faces the application software.
[0039] In an application scenario, when the application software is developed in C++ or C language, the application software is initialized according to the C extension application interface (API, Application Programming Interface) officially provided by Python to generate a Python interpreter.
[0040] In one application scenario, after the application software is opened, it is initialized to generate a python interpreter. That is to say, at this time, regardless of whether the subsequent user chooses to use the deep learning-based processing function of the application software to process the object to be processed, the python interpreter will be generated first.
[0041] In another application scenario, in order to reduce the memory occupied by the Python interpreter in the computer device, the application software will only be initialized and generate the Python interpreter when receiving the selection instruction input by the user. The selection instruction here is the same as the selection instruction mentioned above, and both are instructions for the user to choose to use the application software's deep learning-based processing function to process the object to be processed.
[0042] S150: The application software calls the python code to generate a deep learning class object.
[0043] Specifically, the Python code is the code that implements the deep learning function, and the generated deep learning class object is used to perform deep learning tasks.
[0044] Among them, the application software calls the python code to generate the deep learning class object through the extended application interface officially provided by python. Similar to step S140, when the application software is an application software developed in C++ language or C language, the application software calls the python code to generate the deep learning class object according to the C extended application interface officially provided by python.
[0045] S160: The application software calls the deep learning class object through the Python interpreter to generate a session.
[0046] Specifically, the session generated by the application software calling the deep learning class object through the Python interpreter can be understood as a recognition network based on deep learning, for example, a recognition network for identifying circular defects on workpieces.
[0047] S170: The application software saves the address of the session in the deep learning class object.
[0048] Specifically, the session address is saved in the deep learning class object so that subsequent application software can call the deep learning class object to run the session.
[0049] In one application scenario, in order to improve memory management efficiency and avoid memory leaks, the method of the present application also includes: when receiving a first closing instruction, the application software calls a deep learning class object to close the session.
[0050] Specifically, when the first closing instruction is received, it indicates that the user does not need to use the deep learning-based processing function of the application software. At this time, the deep learning class object is called to close the session.
[0051] Let’s continue with the example mentioned above:
[0052] When the user no longer uses the first detection model or the second detection model to perform target detection on the image to be processed, the user can choose to close the first detection model or the second detection model that has been turned on, and then the application software calls the deep learning class object to close the session, thereby improving the memory management efficiency of the computer device.
[0053] Furthermore, the method of the present application also includes: when receiving the second closing instruction, the application software destructs the memory occupied by the Python interpreter.
[0054] Specifically, the second closing instruction may be an instruction to close the application software, that is, when the user closes the application software, the application software performs a destructuring process on the memory occupied by the Python interpreter to release the resources of the Windows system. The destructuring process refers to releasing the occupied memory.
[0055] It can be seen from the above content that this implementation can, on the one hand, reduce the amount of code that needs to be modified when applying TensorFlow to the Windows system, and on the other hand, improve the management efficiency of the computer device and avoid memory leaks.
[0056] See also Figure 3 , Figure 3 It is a structural diagram of an embodiment of a computer device of the present application, wherein the computer device 200 includes a processor 210 and a memory 220, and the computer device 200 is installed with application software, wherein the processor 210 of the computer device 200 is coupled to the memory 220, and the processor 210 controls the installed application software to implement the steps in any of the above methods by executing the program data in the memory 220, wherein the detailed steps can be found in the above embodiments and will not be repeated here.
[0057] See also Figure 4 , Figure 4 The computer-readable storage medium 300 stores a computer program 310, which can be executed by a processor to implement the steps in any of the above methods.
[0058] Among them, the computer-readable storage medium 300 can specifically be a device that can store the computer program 310, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, or it can also be a server that stores the computer program 310. The server can send the stored computer program 310 to other devices for movement, or it can also move the stored computer program 310 by itself.
[0059] The above description is only an implementation method of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly used in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for deploying TensorFlow in Windows system, characterized in that: The method comprises: When the object to be processed is obtained, the application software calls the deep learning class object, wherein the application software is an application software developed in a first language, and the deep learning class object is generated by the application software calling the python code through the extended application interface officially provided by python, and the first language is different from the python language; The application software runs a session according to the address stored in the deep learning class object to process the object to be processed and obtain a first execution result; The application software converts the first execution result into a second execution result to obtain a processing result of the object to be processed, wherein the second execution result corresponds to the first language.
2. The method according to claim 1, characterized in that Before the application software calls the deep learning class object, it also includes: The application software calls the python code to generate the deep learning class object; The application software calls the deep learning class object through a pre-generated Python interpreter to generate the session; The application software saves the address of the session in the deep learning class object.
3. The method according to claim 2, characterized in that Before the application software calls the python code to generate the deep learning class object, it also includes: The application software is initialized and generates the Python interpreter.
4. The method according to claim 3, characterized in that The method further comprises: When receiving the first closing instruction, the application software calls the deep learning class object to close the session.
5. The method according to claim 3, characterized in that: The method further comprises: When receiving the second closing instruction, the application software destructs the memory occupied by the Python interpreter.
6. The method according to claim 1, characterized in that The step of the application software calling the deep learning class object when the object to be processed is obtained includes: When the object to be processed is obtained, if a selection instruction input by the user is received, the application software calls the deep learning class object.
7. The method according to claim 1, characterized in that The first language is C language.
8. The method according to claim 1, characterized in that The first language is C++ language.
9. A computer device, characterized in that: The computer device comprises a processor and a memory, and application software is installed thereon. The processor is coupled to the memory, program data is stored in the memory, and the processor controls the application software to implement the steps in the method as described in any one of claims 1 to 8 by executing the program data in the memory.
10. A computer-readable storage medium, characterized in that: A computer program is stored, and the computer program can be executed by a processor to implement the steps in the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Method and apparatus to selectively enable operations of a virtual machine monitor on demand
CN105074663A
Software package release method and system based on multi-language environment
CN106528170A
