CN111897574B - DNN program document automatic generation method - Google Patents

DNN program document automatic generation method Download PDF

Info

Publication number
CN111897574B
CN111897574B CN202010661093.8A CN202010661093A CN111897574B CN 111897574 B CN111897574 B CN 111897574B CN 202010661093 A CN202010661093 A CN 202010661093A CN 111897574 B CN111897574 B CN 111897574B
Authority
CN
China
Prior art keywords
dnn
layer
template
information
parameter
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010661093.8A
Other languages
Chinese (zh)
Other versions
CN111897574A (en
Inventor
陈星�
陈序展
陈佳晴
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fuzhou University
Original Assignee
Fuzhou University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fuzhou University filed Critical Fuzhou University
Priority to CN202010661093.8A priority Critical patent/CN111897574B/en
Publication of CN111897574A publication Critical patent/CN111897574A/en
Application granted granted Critical
Publication of CN111897574B publication Critical patent/CN111897574B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/166Editing, e.g. inserting or deleting
    • G06F40/186Templates
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/75Structural analysis for program understanding

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Library & Information Science (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Stored Programmes (AREA)

Abstract

The invention provides a DNN program document automatic generation method, which comprises the following steps: step S1: traversing DNN model program codes, and extracting DNN model information, including layer division and parameter information; step S2: according to the layer type, calculating the inter-layer transmission data quantity; step S3: filling out the DNN program document template. The method can extract the information of the DNN model under the condition of no mark, calculate and analyze the extracted information according to a corresponding rule formula, and fill the DNN information into a pre-designed DNN program document page template, so that the DNN program document is automatically generated, and a beginner in the deep learning field can better understand and master the DNN model.

Description

DNN program document automatic generation method
Technical Field
The invention belongs to the field of machine learning and computer programs, and particularly relates to a DNN program document automatic generation method.
Background
In recent years, artificial intelligence techniques typified by machine learning and computer vision have been rapidly developed and widely used. With the richness of application scenes, the increase of training data, the enhancement of computing power and the maturity of learning algorithms, deep learning in the field of artificial intelligence is concerned by more and more people as a popular research field. Deep learning is a machine learning method that employs a deep architecture such as a deep neural network. Deep Neural Networks (DNNs) refer to Neural Networks with more than two layers of depth, and the DNN model has a large number of layers, a complex interlayer relationship and a large number of parameters in the layers, which are not beneficial to being mastered by beginners in the field of Deep learning, so that it is very meaningful to develop a system capable of automatically generating DNN program documents.
At present, no mature solution for automatic generation of DNN program documents exists. The automatic generation method of the program document which is related and named is a Java technology provided by Sun company, and the Java technology mainly analyzes Java programs to generate Java program documents. The Javadoc technology adopts a self-documentation method, namely notes are injected during code writing, and although the product is accurate, the code invasion is strong, and the learning cost of a user is high.
Disclosure of Invention
In order to overcome the defects and shortcomings of the prior art, the invention provides a DNN program document automatic generation method based on a program static analysis technology, which is mainly oriented to a DNN model realized based on a Caffe framework, and can extract relevant parameter information such as in-layer parameters and inter-layer transfer data volume in the DNN model (realized based on the Caffe framework for example) by a reverse engineering method and perform calculation analysis of the relevant parameters under the condition of not needing to inject annotation, so as to realize the automatic generation of the DNN program document.
The invention specifically adopts the following technical scheme:
a DNN program document automatic generation method is characterized by comprising the following steps:
step S1: traversing DNN model program codes, and extracting DNN model information, including layer division and parameter information;
step S2: according to the layer type, calculating the inter-layer transmission data quantity;
step S3: filling out the DNN program document template.
Preferably, the DNN model is a Caffe framework DNN model.
Preferably, step S2A is further included between step S1 and step S2: and carrying out standard verification on Caffe codes.
Preferably, step S1 specifically includes the following steps:
step S11: find starting position of layer:
traversing the DNN model program code, when the character string of the current line contains a layer, marking the character string as a new specific layer, setting the bracket number brace as 1, and using the value to judge whether the reading of one layer is finished; adding 1 to the number of layers;
step S12: determining whether a particular layer is read intact:
after entering a specific layer, continuing to read the character string of the line according to the line, adding 1 to the number of brackets when the character string of the current line is checked to contain "{", subtracting 1 from the number of brackets when the character string of the current line is checked to contain "}", and judging that a specific layer is completely read when the value of the brackets is 0;
step S13: and extracting the model parameter information according to the matching of the parameter keywords:
in the traversing process, if the content of a certain row of character strings can be matched with a certain parameter, and the row describes the information of the parameter of the layer, storing the layer to which the parameter belongs and the parameter information.
Preferably, step S2A specifically includes the following steps:
and according to the matched specific layer type, combining the specific code specification of the type layer under the Caffe framework to check the code specification.
Preferably, step S2 is specifically realized by the following method:
and calculating the input blob and the output blob according to the parameter information extracted from the DNN model.
Preferably, step S3 is implemented by a template method provided by freemarker technology.
Preferably, step S3 specifically includes the following steps:
step S31: creating a freeMarker configuration example;
step S32: obtaining a template path: obtaining a TEMPLATE according to TEMPLATE _ PATH;
step S33: creating a data model: creating a data model dataMap; writing parameter information Parameters extracted from the DNN model into a data model dataMap by a put method;
step S34: loading a template file: calling a jar package of a freemarker to load a template file;
step S35: generating data: calling jar packets of a freemarker to generate data;
step S36: outputting a file: and calling jar package output files of freemarker.
Compared with the prior art, the invention and the preferred scheme thereof have the following beneficial effects:
the DNN program document automatic generation technology based on the program static analysis technology can extract information of a DNN model (the DNN model based on a Caffe frame has the best effect) under the condition of no mark, the extracted information is calculated and analyzed according to a corresponding rule formula, and then DNN information is filled into a pre-designed DNN program document page template, so that the automatic generation of the DNN program document is realized, and beginners in the deep learning field can better understand and master the DNN model.
Drawings
The invention is described in further detail below with reference to the following figures and detailed description:
FIG. 1 is a schematic overall flow chart of an embodiment of the present invention;
FIG. 2 is a schematic diagram of a DNN model partial source code according to an embodiment of the present invention;
FIG. 3 is a diagram illustrating a DNN program document generated by an embodiment of the present invention.
Detailed Description
In order to make the features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in detail as follows:
as shown in fig. 1, in the embodiment provided by the present invention, a reading and converting process from DNN source code (implemented based on Caffe framework) to a specific layer, and a process of generating a program document according to the extracted and analyzed model information and the program document template are given.
The method provided by the embodiment is a method for automatically generating DNN program documents based on a program static analysis technology. Firstly, reading a DNN model, extracting and analyzing DNN model information, designing and writing a program document page template, and finally combining the extracted and analyzed information with the page template to generate a DNN program document. Through the steps, the automatic generation of the DNN program document is realized.
Specifically, the following are included:
1. definition of
Definition 1: the set of inputs is Input ═ Vi1,Vi2……Vin}。VinRepresenting the nth layer in the DNN model.
Definition 2: the set of outputs is Output ═ Li1,Li2……Lin}。LinRepresenting the nth layer in the DNN model with the addition of computational analysis information.
Definition 3: the set of Parameter information is Parameters ═ { Parameter ═ Parameter1,Parameter2,…ParameternTherein, ParameteriRepresents the i-th parameter of the DNN model. Parameteri{ layerld, value } where layerld: represents Id of the layer to which the parameter belongs, and value represents the value of the parameter.
Definition 4: the set of layer Types is Type ═ Type1,Type2,…Typen}, of which TypeiRepresents the ith layer type of the DNN model.
Definition 5: the set of data amount information is Blobs ═ { Blob ═ Blob1,Blob2,…BlobnIn which BlobiRepresenting the amount of data for layer i of the DNN model. BlobiN, c, h, w, where n: number of representative images, c: number of channels representing image, h: height of the representation image, w: representing the width of the image.
Definition 6: the set of program document templates is dataMap ═ Parameters, wherein the Parameters represent the placeholders corresponding to the Parameters in the ftl file; parameterss represents the parametric information extracted from the DNN model.
DNN model information extraction
For a DNN model implemented based on the Caffe framework, the source code is directly accessible because they are user-specified. For the parameter information of the DNN model, extraction can be performed from DNN model codes implemented based on the Caffe framework. In this embodiment, DNN model information is extracted by the following algorithm:
Algorithm 1 DNN model information extraction
Figure BDA0002579582720000041
go through and read each line in the code until the last line, divide into 3 steps to get Parameters, and the Algorithm is as shown in Algorithm 1:
first, divide layer according to input information (lines 2-4)
When the character string of the current line is checked to contain layer, the description starts from the line to enter a new specific layer, the bracket number brace is set to 1, and the value is used for judging whether the reading of one layer is finished. While adding 1 to the number of layers numberOfLayer.
Second, determine if a particular layer is read intact (lines 5-11)
After entering a specific layer, continuing to read the character string of the line according to the line, when the character string of the current line is checked to contain "{" the number of brackets is added with 1, when the character string of the current line is checked to contain "}", the number of brackets is subtracted with 1, a bracket matching method is adopted to judge whether the reading of the specific layer is finished, when the value of the brace is 0, the occurrence times of "{" and "}" are consistent, and according to the code specification of a Caffe frame, the specific layer is completely read.
Thirdly, the extraction of the model parameter information is achieved according to the matching of the parameter keywords (lines 12-15)
If the content in a certain line of character string can match a ParameternIf the line describes the information of the parameter of the layer, the layer and the parameter value information of the parameter are stored.
For a given DNN model, the embodiment can extract the model information by the above method to obtain the parameter information of a specific layer.
Canffe code normalization verification
Since the Caffe framework has certain specification standards. After the parameter information of the DNN model is extracted, the normalization of the Caffe code can be verified to some extent according to the extracted parameter information, and the quality level of the code is improved. The algorithm for Caffe code normative verification is as follows:
Algorithm 2 Normative validation of Caffe code
Figure BDA0002579582720000051
Figure BDA0002579582720000061
verification of the Caffe code specification is performed by checking the parameter information extracted from the DNN model. The embodiment passes the verification of Caffe code specification by 2 steps, and the Algorithm is as shown in Algorithm 2:
first, layer type determination (line 2)
By utilizing the value of type in the parameter information, the specific layer type to which a certain layer belongs is judged, so that the later verification of code normalization according to the specification of the specific layer is facilitated.
Second, normative validation (3-8 rows)
According to the matched specific layer type, in combination with the specific code specification of the type layer, for example, the parameter values of the num _ output and kernel _ size parameters of the Convolume type layer cannot be null, the code specification is checked.
4. Inter-layer transfer data volume calculation
Considering that the structure of the data store in the Caffe framework is a blob, it holds both the data used for forward propagation and the gradient of backward propagation. Through the parameter information extracted from the DNN model, the present embodiment may perform calculation of input blob and output blob, and the Algorithm is as shown in Algorithm 3:
Algorithm 3 Calculate the amount of data transferred between layers
Figure BDA0002579582720000062
the amount of data transferred between layers is calculated by 2 steps, and the Algorithm is shown as Algorithm 3:
first, layer type determination (line 2)
By utilizing the value of type in the parameter information, the specific layer type to which a certain layer belongs is judged, so that the calculation rule and the formula of the data amount can be selected according to the specific layer conveniently.
Second, interlayer data volume calculation (line 3)
And selecting a corresponding data volume calculation formula to calculate the data volume according to the matched specific layer type.
5. Filling out DNN program document template
In the method, the actual parameter information is transmitted into the template and displayed in a combined manner by mainly using a template method provided by a freemarker technology to fill the DNN program document template. The DNN program document template is filled out by the following algorithm:
Algorithm 4 Fill in the DNN program document template
Input:Parameters={Parameter1,Parameter2,…Paramatern}
Output:dataMap=<parameters,Parameters>
configuration () is set to new Configuration (); // create freeMarker configuration example
Setting DirectryForTemplateLoading (New File _ PATH)); // get template path
Map < String, Object > dataMap ═ newHashMap < String, Object > (); // creating a data model
4:for i in Parameters.size do
5:dataMap.put(parameteri,Parameteri);
6:end
7:configuration.setObjectWrapper(…);
Template ("dnn.ftl"); // load template file
9 File docFile ═ new File (…); // generating data
10:out1=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(docFile)));
Process (dataMap, out 1); // output File
The above procedure is divided into 6 parts for filling out the DNN procedure document template. The Algorithm is shown as Algorithm 4:
first, create a freeMarker configuration instance
A configuration instance of freeMarker is created as shown by the algorithm.
Second, obtain the template path
And obtaining the TEMPLATE according to TEMPLATE _ PATH.
Third, create data model (lines 3-6)
A data model dataMap is created as a bridge to fill information into the template. Parameter information Parameters extracted from the DNN model is written into the data model dataMap through a put method.
Fourth, load template file (lines 7-8)
And calling a related method in a jar package of freemarker to load a template file as shown by an algorithm.
Fifth, generate data (lines 9-10)
And calling a related method in a jar packet of freemarker to generate data as shown in an algorithm.
Sixth, output File (line 11)
And calling a related method in a jar package of freemarker to output a file as shown by an algorithm.
Through the above design method, the present embodiment develops a specific program based on the Java language and the Eclipse platform, and is divided into three parts, namely, DNN model information extraction analysis, program document page template design, and DNN program document generation by combining the two. The storage address of the DNN model file is input by the user, and the DNN model can be automatically read by the system.
And after the model is successfully read, extracting information of the read DNN model, calculating information such as data quantity transmitted between layers by combining with relevant rules, filling all the extracted and analyzed information into a program document page template which is well designed and compiled, and automatically generating the DNN program document.
Verification tests of DNN program document automatic generation are carried out on 9 DNN models such as AlexNet and CaffeNet, and all the DNN program documents can be generated correctly. The results of the verification are shown in the following table:
DNN model Whether or not to generate a program document Whether the generation program document is correct
AlexNet Is that Is that
CaffeNet Is that Is that
nin_imagenet Is that Is that
ZynqNet Is that Is that
YOLONet Is that Is that
SqueezeNet Is that Is that
VGG 16 Layers Is that Is that
Network in Network Is that Is that
GoogLeNet Is that Is that
As can be seen from the above table, the DNN program document generation technique is highly reliable. Under the condition that the input DNN model conforms to Caffe framework specifications, the technology can better generate DNN program documents and provide accurate model information.
Correctness: in the embodiment, the information extracted from the DNN model is stored and analyzed and then is filled into the programmed document page template, so that the DNN programmed document is automatically generated. The model source code (part) and the generated DNN program document interface for implementing the automatic generation of the DNN program document for the cafnenet model are shown in fig. 2 and 3.
Through the verification result, the DNN model source code and the finally generated DNN program document, the fact that parameter information in a layer displayed in the DNN program document is consistent with parameter information identified in the DNN model source code can be found, meanwhile, the DNN model source code can be imported to generate a correct DNN program document under most conditions, and the validity and the accuracy of the method can be satisfied.
The present invention is not limited to the above preferred embodiments, and other various automatic DNN program document generation methods can be derived by anyone based on the teaching of the present invention.

Claims (5)

1. A DNN program document automatic generation method is characterized by comprising the following steps:
step S1: traversing a program code of the deep neural network model, and extracting information of the deep neural network model, wherein the information comprises layer division and parameter information;
step S2: according to the layer type, calculating the inter-layer transmission data quantity;
step S3: filling in a deep neural network program document template;
step S1 specifically includes the following steps:
step S11: find starting position of layer:
when the program code of the traversal deep neural network model checks that the character string of the current line contains a layer, the program code is marked as a new specific layer, the number brace of brackets is set to be 1, and the value is used for judging whether the reading of one layer is finished; adding 1 to the number of layers;
step S12: determining whether a particular layer is read intact:
after entering a specific layer, continuing to read the character string of the line according to the line, adding 1 to the number of brackets when the character string of the current line is checked to contain "{", subtracting 1 from the number of brackets when the character string of the current line is checked to contain "}", and judging that a specific layer is completely read when the value of the brackets is 0;
step S13: and extracting the model parameter information according to the matching of the parameter keywords:
in the traversing process, if the content of a certain row of character strings can be matched with a certain parameter, the row describes the information of the parameter of the layer, and the layer to which the parameter belongs and the parameter information are stored;
step S3 is realized by a template method provided by a freemarker technology;
step S3 specifically includes the following steps:
step S31: creating a freeMarker configuration example;
step S32: obtaining a template path: obtaining a TEMPLATE according to TEMPLATE _ PATH;
step S33: creating a data model: creating a data model dataMap; writing parameter information Parameters extracted from the deep neural network model into a data model dataMap through a put method;
step S34: loading a template file: calling a jar package of a freemarker to load a template file;
step S35: generating data: calling jar packets of a freemarker to generate data;
step S36: outputting a file: and calling jar package output files of freemarker.
2. The method for automatically generating a DNN program document according to claim 1, characterized in that: the deep neural network model is a Caffe framework deep neural network model.
3. The method for automatically generating a DNN program document according to claim 2, characterized in that: step S2A is further included between step S1 and step S2: and carrying out standard verification on Caffe codes.
4. The method of automatically generating a DNN program document according to claim 3, characterized in that: step S2A specifically includes the following steps:
and according to the matched specific layer type, combining the specific code specification of the type layer under the Caffe framework to check the code specification.
5. The method for automatically generating a DNN program document according to claim 1, characterized in that: step S2 is specifically implemented by the following method:
and calculating the input blob and the output blob according to the parameter information extracted from the deep neural network model.
CN202010661093.8A 2020-07-10 2020-07-10 DNN program document automatic generation method Active CN111897574B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010661093.8A CN111897574B (en) 2020-07-10 2020-07-10 DNN program document automatic generation method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010661093.8A CN111897574B (en) 2020-07-10 2020-07-10 DNN program document automatic generation method

Publications (2)

Publication Number Publication Date
CN111897574A CN111897574A (en) 2020-11-06
CN111897574B true CN111897574B (en) 2021-09-28

Family

ID=73192406

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010661093.8A Active CN111897574B (en) 2020-07-10 2020-07-10 DNN program document automatic generation method

Country Status (1)

Country Link
CN (1) CN111897574B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106325969A (en) * 2016-08-23 2017-01-11 上海创景计算机系统有限公司 Requirement change reverse tracking system
CN109491708A (en) * 2018-11-21 2019-03-19 北京锐安科技有限公司 Document structure tree method, system, equipment and medium
CN109783079A (en) * 2018-12-21 2019-05-21 南京航空航天大学 A kind of code annotation generation method based on program analysis and Recognition with Recurrent Neural Network

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7620607B1 (en) * 2005-09-26 2009-11-17 Quintura Inc. System and method for using a bidirectional neural network to identify sentences for use as document annotations
US10606566B2 (en) * 2017-06-03 2020-03-31 Apple Inc. Integration of learning models into a software development system
CN110162296A (en) * 2019-04-15 2019-08-23 平安科技(深圳)有限公司 Generation method, device and the terminal device of application programming interface document

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106325969A (en) * 2016-08-23 2017-01-11 上海创景计算机系统有限公司 Requirement change reverse tracking system
CN109491708A (en) * 2018-11-21 2019-03-19 北京锐安科技有限公司 Document structure tree method, system, equipment and medium
CN109783079A (en) * 2018-12-21 2019-05-21 南京航空航天大学 A kind of code annotation generation method based on program analysis and Recognition with Recurrent Neural Network

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
Deep Learning-based Extraction of Algorithmic Metadata in FullText;Iqra Safde;《Information Processing and Management》;20200530;全文 *
基于深度学习的程序理解研究进展;刘芳等;《计算机研究与发展》;20190831;全文 *
程序理解中文档生成技术的研究;王艳春;《中国优秀硕士学位论文全文数据库》;20080811;全文 *

Also Published As

Publication number Publication date
CN111897574A (en) 2020-11-06

Similar Documents

Publication Publication Date Title
CN109902171B (en) Text relation extraction method and system based on hierarchical knowledge graph attention model
CN107766324B (en) Text consistency analysis method based on deep neural network
CN105843801B (en) The structure system of more translation Parallel Corpus
CN109670191B (en) Calibration optimization method and device for machine translation and electronic equipment
CN106855853A (en) Entity relation extraction system based on deep neural network
CN110059188A (en) A kind of Chinese sentiment analysis method based on two-way time convolutional network
CN111259772B (en) Image labeling method, device, equipment and medium
CN102609406B (en) Learning device, judgment means, learning method and determination methods
CN105868187B (en) The construction method of more translation Parallel Corpus
CN108460019A (en) A kind of emerging much-talked-about topic detecting system based on attention mechanism
WO2016115944A1 (en) Method and device for establishing webpage quality model
CN110008309A (en) A kind of short phrase picking method and device
CN109710933A (en) Acquisition methods, device, computer equipment and the storage medium of training corpus
CN111309313A (en) Method for quickly generating HTML (hypertext markup language) and storing form data
CN103488627A (en) Method and system for translating integral patent documents
CN107122492A (en) Lyric generation method and device based on picture content
CN111160020A (en) Chinese word vector generation method with multiple kinds of submodule information
CN106815215A (en) The method and apparatus for generating annotation repository
CN113836894B (en) Multi-dimensional English composition scoring method and device and readable storage medium
CN105677639A (en) English word sense disambiguation method based on phrase structure syntax tree
CN111897574B (en) DNN program document automatic generation method
CN112801217B (en) Text similarity judgment method and device, electronic equipment and readable storage medium
CN116975206B (en) Vertical field training method and device based on AIGC large model and electronic equipment
CN113900654A (en) Code plagiarism detection method and system based on program language teaching practice platform
CN114048282A (en) Text tree local matching-based image-text cross-modal retrieval method and system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant