From a0ad9298191f02949c5efc47547debfffff07133 Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 06:48:16 +0000 Subject: [PATCH 01/22] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20Advanced=5FEast=5Ffo?= =?UTF-8?q?r=5FACL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/.keep diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/.keep b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/.keep new file mode 100644 index 000000000..e69de29bb -- Gitee From 9b4c60c5da07588bc0f6c274aef1b6913a71e4c0 Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 06:48:32 +0000 Subject: [PATCH 02/22] update. --- .../built-in/cv/Advanced_East_for_ACL/LICENSE | 674 ++++++++++++++++++ .../cv/Advanced_East_for_ACL/README.md | 104 +++ .../cv/Advanced_East_for_ACL/requirements.txt | 0 3 files changed, 778 insertions(+) create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/LICENSE create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/requirements.txt diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/LICENSE b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/LICENSE new file mode 100644 index 000000000..f288702d2 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md new file mode 100644 index 000000000..4aece44c7 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md @@ -0,0 +1,104 @@ +# ID0130_AdvancedEAST +AdvancedEAST 是一种用于场景图像文本检测的算法,主要基于 EAST:An Efficient and Accurate Scene Text Detector,并进行了重大改进,使长文本预测更加准确。 +## 训练环境 + +* TensorFlow 1.15.0+ +* Python 3.7.0+ + +## 代码及路径解释 + +``` +AdvancedEAST_ID0130_for_ACL +├── nms.py 预测用到的一个函数 +├── cfg.py 参数配置 +├── cfg_bank.py 参数配置 +├── advanced_east.py 参数配置 +├── image_util.py 参数配置 +├── label.py 参数配置 +├── network_add_bn.py 参数配置 +├── icpr 数据集位置 +│ └── image_10000 图像文件 +│ └── txt_10000 标签文件 +├── demo 样例图片 +│ └── 001.png +├── image_test_bin 图片转为bin存放位置 +├── image_test_output msame推理结果bin文件存放位置 +├── preprocess.py 图片预处理 +├── image2bin.py 推理数据预处理:将image_test中的image文件转换为bin并进行其他图片预处理 +├── h5_to_pb.py h5模型固化为pb +├── atc.sh act工具 pb==》om 转换命令 +├── msame.sh msame工具:om离线推理命令 +├── postprocess.py 后处理 +├── predict.py 精度预测 +``` + + +## 数据集 tianchi ICPR MTWI 2018 + +测试集下载地址:链接: 提取码:1234 + +精度验证链接: https://tianchi.aliyun.com/competition/entrance/231685/rankingList + +## 图片预处理 +```shell +python3.7.5 preprocess.py +``` + +## 将测试集图片转为bin文件 + +```shell +python3.7.5 image2bin.py +``` + +## 模型文件 +包括初始h5文件,固化pb文件,以及推理om文件 +h5模型下载地址:链接: 提取码: +pb模型下载地址:链接: 提取码: + +## pb模型 + +模型固化 +```shell +python3.7.5 h5_to_pb.py +``` +## 生成om模型 + +使用ATC模型转换工具进行模型转换时可参考如下指令 atc.sh: +```shell +atc --model=model.pb --input_shape="input_img:1,736,736,3" --framework=3 --output=model --soc_version=Ascend310 --input_format=NHWC +``` +具体参数使用方法请查看官方文档。 + +## 使用msame工具推理 + +使用msame工具进行推理时可参考如下指令 msame.sh +```shell +./msame --model $MODEL --input $INPUT --output $OUTPUT --outfmt BIN +``` +参考 https://gitee.com/ascend/tools/tree/master/msame, 获取msame推理工具及使用方法。 + +## 执行predict +```shell +python3.7.5 predict.py +``` + +## 精度 +* 论文精度: + +| Score | Precision | Recall | +| :--------: | ---------- | ------ | +| 0.611 | 0.809 | 0.492 | + +* GPU目标精度: + +| Score | Precision | Recall | +| :--------: | ---------- | ------ | +| 0.554 | 0.760 | 0.436 | + +* Ascend推理精度: + +| Score | Precision | Recall | +| :--------: | ---------- | ------ | +| 0.632 | 0.849 | 0.513 | + + diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/requirements.txt b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/requirements.txt new file mode 100644 index 000000000..e69de29bb -- Gitee From da413124f04a7326147a36d17a5a8dcf99dd23d0 Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 06:49:11 +0000 Subject: [PATCH 03/22] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20Benchmark?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/.keep diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/.keep b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/.keep new file mode 100644 index 000000000..e69de29bb -- Gitee From 44d6793fd4860da55857b87c63ffd4c8543e5a3a Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 06:49:37 +0000 Subject: [PATCH 04/22] update. --- .../Benchmark/CMakeLists.txt | 41 + .../Benchmark/infer_engine.cpp | 814 ++++++++++++++++++ .../Advanced_East_for_ACL/Benchmark/main.cpp | 534 ++++++++++++ .../Benchmark/post_process.cpp | 131 +++ .../Advanced_East_for_ACL/Benchmark/util.cpp | 214 +++++ 5 files changed, 1734 insertions(+) create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/CMakeLists.txt create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/infer_engine.cpp create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/main.cpp create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/post_process.cpp create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/util.cpp diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/CMakeLists.txt b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/CMakeLists.txt new file mode 100644 index 000000000..17dc38b8a --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/CMakeLists.txt @@ -0,0 +1,41 @@ +# Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. +# CMake lowest version requirement +cmake_minimum_required(VERSION 3.5.1) +# project information +project(ascendcl) +# Compile options +add_compile_options(-std=c++11) +# Specify target generation path +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../outputs") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "../outputs") +set(CMAKE_INSTALL_PREFIX "../../../") +set(CMAKE_OUTPUT_DIR "out") +set(CMAKE_CXX_FLAGS_RELEASE "-fPIC -O2 -g -Wall") + +ADD_DEFINITIONS("-DENABLE_DVPP_INTERFACE -D_GLIBCXX_USE_CXX11_ABI=0") + +# Header path +include_directories( +inc +#/usr/include/gflags +$ENV{install_path}/acllib/include +$ENV{install_path}/driver/kernel/libc_sec/include +/usr/include +) + +# add host lib path +link_directories($ENV{install_path}/acllib/lib64/stub) +#link_directories(/usr/local/Ascend/driver/lib64) +#link_directories(/usr/local/Ascend/atc/lib64) +#link_directories(/usr/local/lib) +link_directories(../thirdpart_lib) + +# 设置需要编译的源文件 +add_executable(benchmark main.cpp util.cpp post_process.cpp infer_engine.cpp) + +# 设置共享库 RC为待扩展的offline模型 +#target_link_libraries(benchmark acl_dvpp ascendcl pthread protobuf cryptopp) +target_link_libraries(benchmark acl_dvpp ascendcl pthread) + +install(TARGETS benchmark DESTINATION ${CMAKE_OUTPUT_DIR}) + diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/infer_engine.cpp b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/infer_engine.cpp new file mode 100644 index 000000000..4cbff1383 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/infer_engine.cpp @@ -0,0 +1,814 @@ +/* * +* Copyright 2020 Huawei Technologies Co., Ltd +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* */ + +#include "acl/acl.h" +#include "infer_engine.h" +#include "acl/acl_mdl.h" +#include "acl/acl_rt.h" +#include +#include +//#include +#include "acl/ops/acl_dvpp.h" +using namespace std; + +std::unordered_map dvppTime; +extern Resnet50Result resnet50Res; +extern Config cfg; +extern aclError ret; +extern int processedCnt; +extern long long inferTime; +aclrtContext context; +uint32_t modelId; +aclmdlDesc* modelDesc; +std::vector files; +DataFrame inputDataframe; +DataFrame outputDataframe; +aclDataBuffer* yoloImgInfo; +aclrtStream stream = nullptr; +acldvppChannelDesc* dvpp_channel_desc = nullptr; +std::unordered_map> imgSizes; + +#define RESIZE_MIN 256 + +uint32_t resizedWidth; +uint32_t resizedHeight; +uint32_t resizedWidthAligned; +uint32_t resizedHeightAligned; +uint32_t resizedOutputBufferSize; + + +void getImgResizeShape() +{ + if (ACL_FORMAT_NCHW == cfg.inputInfo[0].Format) + { + resizedHeight = cfg.inputInfo[0].dims[2]; + resizedWidth = cfg.inputInfo[0].dims[3]; + + } + else if (ACL_FORMAT_NHWC == cfg.inputInfo[0].Format) + { + resizedHeight = cfg.inputInfo[0].dims[1]; + resizedWidth = cfg.inputInfo[0].dims[2]; + } +} + +aclError InitContext(const char* configPath) +{ + LOG("context init start\n"); + ret = aclInit(configPath); + CHECK_ACL_RET("acl init failed", ret); + + ret = aclrtSetDevice(cfg.deviceId); + CHECK_ACL_RET("open device failed ret", ret); + + ret = aclrtCreateContext(&context, cfg.deviceId); + CHECK_ACL_RET("create context failed", ret); + + cfg.context = context; + LOG("context init done\n"); + + return ACL_ERROR_NONE; +} + +aclError UnInitContext() +{ + ret = aclrtDestroyContext(context); + CHECK_ACL_RET("destory context failed", ret); + LOG("destory context done\n"); + + ret = aclrtResetDevice(cfg.deviceId); + CHECK_ACL_RET("reset device failed", ret); + + ret = aclFinalize(); + CHECK_ACL_RET("finalize failed", ret); + LOG("reset device done\n"); + + return ACL_ERROR_NONE; +} + + + +aclError LoadModel() +{ + LOG("load model start\n"); + size_t memSize; + size_t weightsize; + uint32_t modelSize = 0; + std::string modelPath = cfg.om; + + cfg.modelData_ptr = ReadBinFile(modelPath, modelSize); + CHECK_WITH_RET(cfg.modelData_ptr != nullptr, ACL_ERROR_READ_MODEL_FAILURE, "can't read model"); + + aclError ret = aclmdlQuerySizeFromMem(cfg.modelData_ptr, modelSize, &memSize, &weightsize); + CHECK_ACL_RET("query memory size failed", ret); + + ret = aclrtMalloc(&(cfg.devMem_ptr), memSize, ACL_MEM_MALLOC_HUGE_ONLY); + CHECK_ACL_RET("alloc dev_ptr failed", ret); + ret = aclrtMalloc(&(cfg.weightMem_ptr), weightsize, ACL_MEM_MALLOC_HUGE_ONLY); + CHECK_ACL_RET("alloc weight_ptr failed", ret); + + ret = aclmdlLoadFromMemWithMem(cfg.modelData_ptr, modelSize, &modelId, cfg.devMem_ptr, memSize, cfg.weightMem_ptr, weightsize); + CHECK_ACL_RET("load model from memory failed", ret); + LOG("Load model success. memSize: %lu, weightSize: %lu.\n", memSize, weightsize); + + modelDesc = aclmdlCreateDesc(); + CHECK_WITH_RET(modelDesc != nullptr, ACL_ERROR_READ_MODEL_FAILURE, "create model desc failed"); + ret = aclmdlGetDesc(modelDesc, modelId); + CHECK_ACL_RET("get model desc failed", ret); + + cfg.modelDesc = modelDesc; + cfg.modelId = modelId; + + LOG("load model done\n"); + return ACL_ERROR_NONE; +} + + +aclError DvppSetup() +{ + ret = aclrtSetCurrentContext(context); + if (ret != ACL_ERROR_NONE) + { + LOG("Set context failed\n"); + return ret; + } + + ret = aclrtCreateStream(&stream); + if (ret != ACL_ERROR_NONE) + { + LOG("create dvpp stream failed\n"); + return ret; + } + + dvpp_channel_desc = acldvppCreateChannelDesc(); + if (dvpp_channel_desc == nullptr) + { + ret = ACL_ERROR_OTHERS; + LOG("create dvpp channel desc failed\n"); + return ret; + } + + ret = acldvppCreateChannel(dvpp_channel_desc); + if (ret != ACL_ERROR_NONE) + { + LOG("create dvpp channel failed\n"); + return ret; + } + + resizedWidthAligned = (resizedWidth + 15) / 16 * 16; + resizedHeightAligned = (resizedHeight + 1) / 2 * 2; + + resizedOutputBufferSize = resizedWidthAligned * resizedHeightAligned * 3 / 2; + LOG("resizedWidth %d resizedHeight %d resizedWidthAligned %d resizedHeightAligned %d resizedOutputBufferSize %d\n", resizedWidth, resizedHeight, resizedWidthAligned, resizedHeightAligned, resizedOutputBufferSize); + + return ACL_ERROR_NONE; +} + + + +acldvppPicDesc* createDvppPicDesc(void *dataDev, acldvppPixelFormat format, uint32_t width, uint32_t height, uint32_t widthStride, uint32_t heightStride, uint32_t size){ + acldvppPicDesc* picDesc = acldvppCreatePicDesc(); + if (picDesc == nullptr){ + LOG("failed to create pic desc\n"); + return nullptr; + } + + ret = acldvppSetPicDescData(picDesc, dataDev); + if (ret != ACL_ERROR_NONE){ + LOG("failed to set desc data\n"); + return nullptr; + } + ret = acldvppSetPicDescSize(picDesc, size); + if (ret != ACL_ERROR_NONE){ + LOG("failed to set desc size\n"); + return nullptr; + } + + ret = acldvppSetPicDescFormat(picDesc, format); + if (ret != ACL_ERROR_NONE){ + LOG("failed to set desc format\n"); + return nullptr; + } + + + ret = acldvppSetPicDescWidth(picDesc, width); + if (ret != ACL_ERROR_NONE){ + LOG("failed to set desc width\n"); + return nullptr; + } + + + ret = acldvppSetPicDescHeight(picDesc, height); + if (ret != ACL_ERROR_NONE){ + LOG("failed to set desc height\n"); + return nullptr; + } + + + ret = acldvppSetPicDescWidthStride(picDesc, widthStride); + if (ret != ACL_ERROR_NONE){ + LOG("failed to set desc widthStride\n"); + return nullptr; + } + + + ret = acldvppSetPicDescHeightStride(picDesc, heightStride); + if (ret != ACL_ERROR_NONE){ + LOG("failed to set desc heightStride\n"); + return nullptr; + } + return picDesc; + +} + + +aclError InitInput(std::vector files) +{ + LOG("init input batch %d start\n", processedCnt); + ret = aclrtSetCurrentContext(context); + if (ret != ACL_ERROR_NONE) { + LOG("Set context failed, ret[%d]\n", ret); + return ret; + } + + size_t modelInputSize = cfg.inputInfo[0].size; + size_t imgSize = modelInputSize / cfg.batchSize; + + + void* dst; + ret = aclrtMalloc(&dst, modelInputSize, ACL_MEM_MALLOC_NORMAL_ONLY); + if (ret != ACL_ERROR_NONE) { + LOG("Malloc device failed, ret[%d]\n", ret); + return ret; + } + LOG("dst = %p, size = %ld\n", dst, modelInputSize); + + char* ptr = (char*)dst; + inputDataframe.fileNames.clear(); + for (int i = 0; i < files.size(); i++) { + + std::string fileLocation = cfg.dataDir + "/" + files[i]; + FILE* pFile = fopen(fileLocation.c_str(), "r"); + + if (pFile == nullptr) { + ret = ACL_ERROR_OTHERS; + LOG("open file %s failed\n", fileLocation.c_str()); + return ret; + } + + fseek(pFile, 0, SEEK_END); + size_t fileSize = ftell(pFile); + + if (fileSize > imgSize) { + ret = ACL_ERROR_OTHERS; + LOG("%s fileSize %lu * batch %lu don't match with model inputSize %lu\n", fileLocation.c_str(), fileSize, cfg.batchSize, modelInputSize); + return ret; + } + + void* buff = nullptr; + ret = aclrtMallocHost(&buff, fileSize); + if (ret != ACL_ERROR_NONE) { + LOG("Malloc host buff failed[%d]\n", ret); + return ret; + } + + rewind(pFile); + fread(buff, sizeof(char), fileSize, pFile); + fclose(pFile); + + void* dstTmp = (void*)ptr; + ret = aclrtMemcpy(dstTmp , fileSize, buff, fileSize, ACL_MEMCPY_HOST_TO_DEVICE); + ptr += fileSize; + LOG("input addr %p, len %ld\n", dstTmp, fileSize); + if (ret != ACL_ERROR_NONE) { + LOG("init input %d, Copy host to device failed, ret[%d]\n", i, ret); + LOG("input addr %p, len %ld\n", dstTmp, fileSize); + + aclrtFreeHost(buff); + return ret; + } + + aclrtFreeHost(buff); + + inputDataframe.fileNames.push_back(files[i]); + } + + aclDataBuffer* inputData = aclCreateDataBuffer((void*)dst, modelInputSize); + if (inputData == nullptr) { + ret = ACL_ERROR_OTHERS; + LOG("aclCreateDataBuffer failed\n"); + return ret; + } + + aclmdlDataset* input = aclmdlCreateDataset(); + ret = aclmdlAddDatasetBuffer(input, inputData); + if (ret != ACL_ERROR_NONE) { + LOG("ACL_ModelInputDataAdd failed, ret[%d]\n", ret); + aclmdlDestroyDataset(input); + return ret; + } + + inputDataframe.dataset = input; + LOG("init input batch %d done\n", processedCnt); + return ACL_ERROR_NONE; + +} + +aclError GetImageSize(std::string file) +{ + std::string fileLocation = cfg.dataDir + "/" + file; + FILE *pFile = fopen(fileLocation.c_str(), "r"); + + if (pFile == nullptr) + { + ret = ACL_ERROR_OTHERS; + LOG("open file %s failed\n", fileLocation.c_str()); + return ret; + } + + fseek(pFile, 0, SEEK_END); + size_t fileSize = ftell(pFile); + + void *buff = nullptr; + ret = aclrtMallocHost(&buff, fileSize); + if (ret != ACL_ERROR_NONE) + { + LOG("Malloc host buff failed[%d]\n", ret); + return ret; + } + + rewind(pFile); + fread(buff, sizeof(char), fileSize, pFile); + fclose(pFile); + + uint32_t width, height; + int32_t components; + ret = acldvppJpegGetImageInfo(buff, fileSize, &width, &height, &components); + if( ret != ACL_ERROR_NONE) + { + LOG("acldvppJpegGetImageInfo failed"); + aclrtFreeHost(buff); + } + printf("==============fileName=%s, W=%d, H=%d===============\n", file.c_str(), width, height); + auto size = std::make_pair(width, height); + imgSizes[file] = std::move(size); + + aclrtFreeHost(buff); + + return ret; +} + +acldvppRoiConfig *InitCropRoiConfig(uint32_t width, uint32_t height) +{ + uint32_t right = 0; + uint32_t bottom = 0; + acldvppRoiConfig *cropConfig; + + if (width % 2 == 0) + { + right = width - 1; + } + else + { + right = width; + } + + if (height % 2 == 0) + { + bottom = height - 1; + } + else + { + bottom = height; + } + printf("InitCropRoiConfig right=%d, bottom=%d \n", right, bottom); + cropConfig = acldvppCreateRoiConfig(0, right, 0, bottom); + if (cropConfig == nullptr) + { + std::cout << "[ERROR][Vision] acldvppCreateRoiConfig failed " << std::endl; + return nullptr; + } + + return cropConfig; +} + +acldvppRoiConfig *InitCropCenterRoiConfig(uint32_t InputWidth, uint32_t InputHeight, uint32_t cropInputWidth, uint32_t cropInputHeight) +{ + uint32_t left = 0; + uint32_t right = 0; + uint32_t top = 0; + uint32_t bottom = 0; + uint32_t amount_to_be_cropped_w = 0; + uint32_t amount_to_be_cropped_h = 0; + uint32_t left_half = 0; + uint32_t top_half = 0; + printf("CentralCrop InputWidth=%d InputHeight=%d cropInputWidth=%d cropInputHeight=%d \n",InputWidth,InputHeight,cropInputWidth,cropInputHeight); + + acldvppRoiConfig *centerCropConfig = nullptr; + + amount_to_be_cropped_w = InputWidth - cropInputWidth; + left_half = amount_to_be_cropped_w / 2; + amount_to_be_cropped_h = InputHeight - cropInputHeight; + top_half = amount_to_be_cropped_h / 2; + + + left = (left_half % 2 == 0) ? (amount_to_be_cropped_w / 2) : (amount_to_be_cropped_w / 2 + 1); + top = (top_half % 2 == 0) ? (amount_to_be_cropped_h / 2) : (amount_to_be_cropped_h / 2 + 1); + + right = left + cropInputWidth - 1; + bottom = top + cropInputHeight - 1; + + centerCropConfig = acldvppCreateRoiConfig(left, right, top, bottom); + if (centerCropConfig == nullptr) + { + std::cout << "[ERROR][Vision] InitCropCenterRoiConfig acldvppCreateRoiConfig failed " << std::endl; + return nullptr; + } + + return centerCropConfig; +} + +aclError DvppInitInput(std::vector files) +{ + struct timeval func_start; + struct timeval func_end; + struct timeval process_start; + struct timeval process_end; + std::string funcName; + long long costTime; + funcName = "DvppTotalProcess"; + gettimeofday(&process_start, NULL); + void *dst; + //ret = aclrtMalloc(&dst, cfg.batchSize * resizedOutputBufferSize, ACL_MEM_MALLOC_HUGE_ONLY); + ret = acldvppMalloc(&dst, cfg.inputInfo[0].size); + if (ret != ACL_ERROR_NONE) + { + LOG("Malloc device failed, ret[%d]\n", ret); + return ret; + } + + LOG("DvppInitInput dvpp malloc dst size:%d\n", cfg.inputInfo[0].size); + + char *ptr = (char *)dst; + inputDataframe.fileNames.clear(); + + for (int i = 0; i < files.size(); i++) + { + + ret = GetImageSize(files[i]); + + uint32_t W = imgSizes[files[i]].first; + uint32_t H = imgSizes[files[i]].second; + uint32_t W_Aligned = (W + 127) / 128 * 128; + uint32_t H_Aligned = (H + 15) / 16 * 16; + uint32_t outputBuffSize = W_Aligned * H_Aligned * 3 / 2; + std::string fileLocation = cfg.dataDir + "/" + files[i]; + + FILE *pFile = fopen(fileLocation.c_str(), "r"); + if (pFile == nullptr) + { + ret = ACL_ERROR_OTHERS; + LOG("open file %s failed\n", fileLocation.c_str()); + return ret; + } + + fseek(pFile, 0, SEEK_END); + uint64_t fileSize = ftell(pFile); + + void *buff = nullptr; + ret = aclrtMallocHost(&buff, fileSize); + if (ret != ACL_ERROR_NONE) + { + LOG("Malloc host buff failed[%d]\n", ret); + return ret; + } + + rewind(pFile); + fread(buff, sizeof(char), fileSize, pFile); + fclose(pFile); + + // 分配device图片输入内存 + void *jpeg_dev_mem_in_ptr = nullptr; + ret = acldvppMalloc(&jpeg_dev_mem_in_ptr, fileSize + 8); + if (ret != ACL_ERROR_NONE) + { + LOG("Malloc dvpp in buff failed[%d]\n", ret); + return ret; + } + + // host内存拷贝至device输入内存 + ret = aclrtMemcpy(jpeg_dev_mem_in_ptr, fileSize + 8, buff, fileSize, + ACL_MEMCPY_HOST_TO_DEVICE); + if (ret != ACL_ERROR_NONE) + { + LOG("copy host to device failed[%d]\n", ret); + return ret; + } + + aclrtFreeHost(buff); + // 分配device图片解码内存 + void *jpeg_dev_mem_out_ptr = nullptr; + ret = acldvppMalloc(&jpeg_dev_mem_out_ptr, outputBuffSize); + if (ret != ACL_ERROR_NONE) + { + LOG("Malloc dvpp in buff failed[%d]\n", ret); + return ret; + } + + acldvppPicDesc *jpeg_output_desc = nullptr; + acldvppPicDesc *resize_output_desc = nullptr; + + funcName = "DvppPicDescCreate_output"; + gettimeofday(&func_start, NULL); + + jpeg_output_desc = createDvppPicDesc(jpeg_dev_mem_out_ptr, PIXEL_FORMAT_YUV_SEMIPLANAR_420, W, H, W_Aligned, H_Aligned, outputBuffSize); + if (jpeg_output_desc == nullptr) + { + ret = ACL_ERROR_OTHERS; + LOG("create jpeg_output_desc failed\n"); + return ret; + } + gettimeofday(&func_end, NULL); + + LOG("file[%s] jpeg picDesc info: W=%d, H=%d, W_Aligned=%d, H_Aligned=%d, outBufSize=%d, format=%d\n", \ + files[i] + .c_str(), + W, H, W_Aligned, H_Aligned, outputBuffSize, PIXEL_FORMAT_YUV_SEMIPLANAR_420); + + costTime = (func_end.tv_sec - func_start.tv_sec) * 1000000 + (func_end.tv_usec - func_start.tv_usec); + + dvppTime[funcName] += costTime; + + funcName = "DvppRoiConfigCreate"; + gettimeofday(&func_start, NULL); + + gettimeofday(&func_end, NULL); + costTime = (func_end.tv_sec - func_start.tv_sec) * 1000000 + (func_end.tv_usec - func_start.tv_usec); + dvppTime[funcName] += costTime; + + funcName = "DvppJpegDecode"; + gettimeofday(&func_start, NULL); + ret = acldvppJpegDecodeAsync(dvpp_channel_desc, jpeg_dev_mem_in_ptr, fileSize + 8, jpeg_output_desc, stream); + if (ret != ACL_ERROR_NONE) + { + LOG(" dvppJpegDecodeAsync failed\n"); + return ret; + } + gettimeofday(&func_end, NULL); + costTime = (func_end.tv_sec - func_start.tv_sec) * 1000000 + (func_end.tv_usec - func_start.tv_usec); + dvppTime[funcName] += costTime; + + //Crop original image and Resize [256, 256] + aclrtSynchronizeStream(stream); + acldvppRoiConfig *cropConfig = nullptr; + acldvppPicDesc *cropOutputDesc = nullptr; // resize output desc + cropConfig = InitCropRoiConfig(W, H); + void *cropOutBufferDev = nullptr; + uint32_t cropOutBufferSize = 256 * 256 * 3 / 2; + ret = acldvppMalloc(&cropOutBufferDev, cropOutBufferSize); + if (ret != ACL_ERROR_NONE) + { + std::cout << "[ERROR][Vision] AcldvppMalloc cropOutBufferDev_ failed, ret = " << ret << " cropOutBufferSize_ = " << cropOutBufferSize << endl; + return ret; + } + cropOutputDesc = createDvppPicDesc(cropOutBufferDev, PIXEL_FORMAT_YUV_SEMIPLANAR_420, 256, 256, 256, 256, cropOutBufferSize); + if (cropOutputDesc == nullptr) + { + ret = ACL_ERROR_OTHERS; + LOG("create cropOutputDesc failed\n"); + return ret; + } + ret = acldvppVpcCropAsync(dvpp_channel_desc, jpeg_output_desc, cropOutputDesc, cropConfig, stream); + if (ret != ACL_ERROR_NONE) + { + std::cout << "[ERROR][Vision] crop acldvppVpcCropAsync failed, ret = " << ret << std::endl; + return ret; + } + + //Central crop [224 224] + aclrtSynchronizeStream(stream); + acldvppRoiConfig *centralcropConfig = nullptr; + acldvppPicDesc *centralcropOutputDesc = nullptr; // resize output desc + uint32_t centralcropOutBufferSize = 224 * 224 * 3 / 2; + centralcropConfig = InitCropCenterRoiConfig(256, 256, 224, 224); + void *dstTmp = (void *)ptr; + centralcropOutputDesc = createDvppPicDesc(dstTmp, PIXEL_FORMAT_YUV_SEMIPLANAR_420, 224, 224, 224, 224, centralcropOutBufferSize); + if (cropOutputDesc == nullptr) + { + ret = ACL_ERROR_OTHERS; + LOG("create cropOutputDesc failed\n"); + return ret; + } + ptr += centralcropOutBufferSize; + ret = acldvppVpcCropAsync(dvpp_channel_desc, cropOutputDesc, centralcropOutputDesc, centralcropConfig, stream); + if (ret != ACL_ERROR_NONE) + { + std::cout << "[ERROR][Vision] acldvppVpcCropAsync failed, ret = " << ret << std::endl; + return ret; + } + + + funcName = "StreamSynchronize"; + gettimeofday(&func_start, NULL); + + ret = aclrtSynchronizeStream(stream); + + gettimeofday(&func_end, NULL); + costTime = (func_end.tv_sec - func_start.tv_sec) * 1000000 + (func_end.tv_usec - func_start.tv_usec); + dvppTime[funcName] += costTime; + if (ret != ACL_ERROR_NONE) + { + LOG("dvpp invoke failed.\n"); + } + + ret = acldvppFree(jpeg_dev_mem_in_ptr); + if (ret != ACL_ERROR_NONE) + { + LOG("jpeg_dev_mem_in_ptr free failed\n"); + return ret; + } + + ret = acldvppFree(jpeg_dev_mem_out_ptr); + if (ret != ACL_ERROR_NONE) + { + LOG("jpeg_dev_mem_out_ptr free failed\n"); + } + + ret = acldvppFree(cropOutBufferDev); + if (ret != ACL_ERROR_NONE) + { + LOG("cropOutBufferDev free failed\n"); + return ret; + } + + acldvppDestroyPicDesc(jpeg_output_desc); + acldvppDestroyPicDesc(cropOutputDesc); + acldvppDestroyPicDesc(centralcropOutputDesc); + + + acldvppDestroyRoiConfig(cropConfig); + acldvppDestroyRoiConfig(centralcropConfig); + + + inputDataframe.fileNames.push_back(files[i]); + } + + funcName = "DvppTotalProcess"; + gettimeofday(&process_end, NULL); + costTime = (process_end.tv_sec - process_start.tv_sec) * 1000000 + (process_end.tv_usec - process_start.tv_usec); + dvppTime[funcName] += costTime; + + aclmdlDataset *input = aclmdlCreateDataset(); + aclDataBuffer *inputData = aclCreateDataBuffer((void *)dst, cfg.inputInfo[0].size); + + if (inputData == nullptr) + { + ret = ACL_ERROR_OTHERS; + LOG("aclCreateDataBuffer failed\n"); + return ret; + } + + ret = aclmdlAddDatasetBuffer(input, inputData); + + if (ret != ACL_ERROR_NONE) + { + LOG("ACL_ModelInputDataAdd failed, ret[%d]\n", ret); + aclmdlDestroyDataset(input); + return ret; + } + + inputDataframe.dataset = input; + return ACL_ERROR_NONE; +} + + +aclError Inference() +{ + LOG("inference batch %d start\n", processedCnt); + ret = aclrtSetCurrentContext(context); + + if (ret != ACL_ERROR_NONE) { + LOG("Set infer context failed\n"); + return ret; + } + + struct timeval startTmp, endTmp; + long long timeUse; + + + if (inputDataframe.fileNames.size() == 0) { + ret = ACL_ERROR_OTHERS; + LOG("No file found\n"); + return ret; + } + + aclmdlDataset* output = aclmdlCreateDataset(); + if (output == nullptr) { + ret = ACL_ERROR_OTHERS; + LOG("Create Output Dataset failed\n"); + return ret; + } + + std::vector outputDevPtrs; + + for (size_t i = 0; i < cfg.outputNum; ++i) { + size_t buffer_size = cfg.outputInfo[i].size; + void* outputBuffer = nullptr; + ret = aclrtMalloc(&outputBuffer, (size_t)buffer_size, ACL_MEM_MALLOC_NORMAL_ONLY); + //LOG("NN output addr %ld, len %ld ",size_t(outputBuffer), size_t(buffer_size)); + + if (ret != ACL_ERROR_NONE) { + LOG("Malloc output host failed, ret[%d]\n", ret); + return ret; + } + //LOG("output%ld: addr %ld, size %ld\n", i, size_t(outputBuffer) , size_t(buffer_size)); + outputDevPtrs.push_back(outputBuffer); + aclDataBuffer* outputData = aclCreateDataBuffer(outputBuffer, buffer_size); + + if (outputData == nullptr) { + ret = ACL_ERROR_OTHERS; + LOG("Create output data buffer failed\n"); + return ret; + } + + ret = aclmdlAddDatasetBuffer(output, outputData); + + if (ret != ACL_ERROR_NONE) { + LOG("Add output model dataset failed, ret[%d]\n", ret); + return ret; + } + + } + + gettimeofday(&startTmp, NULL); + ret = aclmdlExecute(modelId, inputDataframe.dataset, output); + gettimeofday(&endTmp, NULL); + timeUse = (endTmp.tv_sec-startTmp.tv_sec)*1000000+(endTmp.tv_usec-startTmp.tv_usec); + LOG("%s inference time use: %lld us\n",inputDataframe.fileNames[0].c_str(), timeUse); + inferTime += timeUse; + + if (ret != ACL_ERROR_NONE) { + LOG("%s inference failed.\n",inputDataframe.fileNames[0].c_str()); + FreeDevMemory(inputDataframe.dataset); + aclmdlDestroyDataset(inputDataframe.dataset); + return ret; + } + + outputDataframe.fileNames = inputDataframe.fileNames; + outputDataframe.dataset = output; + + uint32_t dvppFlag; + (cfg.useDvpp) ? dvppFlag = 1: dvppFlag = 0; + + ret = DestroyDatasetResurce(inputDataframe.dataset, dvppFlag); + if (ret != ACL_ERROR_NONE){ + LOG("DestroyDatasetResurce failed\n"); + return ret; + } + + + LOG("inference batch %d done\n", processedCnt); + return ACL_ERROR_NONE; + +} + +aclError UnloadModel() +{ + LOG("unload model start\n"); + ret = aclmdlUnload(modelId); + CHECK_ACL_RET("unload model failed", ret); + LOG("unload model done\n"); + + aclmdlDestroyDesc(cfg.modelDesc); + + if (nullptr != cfg.devMem_ptr) { + aclrtFree(cfg.devMem_ptr); + cfg.devMem_ptr = nullptr; + } + + if (nullptr != cfg.weightMem_ptr) { + aclrtFree(cfg.weightMem_ptr); + cfg.weightMem_ptr = nullptr; + } + + if (nullptr != cfg.modelData_ptr) { + delete[] cfg.modelData_ptr; + cfg.modelData_ptr = nullptr; + } + return ACL_ERROR_NONE; +} + + diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/main.cpp b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/main.cpp new file mode 100644 index 000000000..144356343 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/main.cpp @@ -0,0 +1,534 @@ +/* * +* Copyright 2020 Huawei Technologies Co., Ltd +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* */ + +#include "util.h" +#include "infer_engine.h" +#include "acl/acl_base.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "acl/acl.h" +#include "acl/acl_mdl.h" +#include "acl/acl_rt.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + + + +using namespace std; +using std::cout; +using std::endl; + + +Resnet50Result resnet50Res; +Config cfg; +aclError ret; +int processedCnt; +long long dataProcTime = 0; +long long inferTime = 0; +float avgTime = 0; +float avgPreTime = 0; + +extern std::unordered_map dvppTime; +extern DataFrame outputDataframe; + +void getCommandLineParam(int argc, char** argv, Config& config) +{ + while (1) + { + int option_index = 0; + struct option long_options[] = + { + {"om", 1, 0, 'a'}, + {"dataDir", 1, 0, 'b'}, + {"outDir", 1, 0, 'c'}, + {"batchSize", 1, 0, 'd'}, + {"deviceId", 1, 0, 'e'}, + {"loopNum", 1, 0, 'f'}, + {"modelType", 1, 0, 'g'}, + {"imgType", 1, 0, 'h'}, + {"framework", 1, 0, 'i'}, + {"useDvpp", 1 , 0 , 'j'}, + {0, 0, 0, 0} + + + }; + + int c; + c = getopt_long(argc, argv, "a:b:c:e:f:j:k:l:m:n:u:t:", long_options, &option_index); + if (c == -1) + { + break; + } + + switch (c) + { + case 'a': + config.om = std::string(optarg); + printf("[INFO]om = %s\n", config.om.c_str()); + break; + case 'b': + config.dataDir = std::string(optarg); + printf("[INFO]dataDir = %s\n", config.dataDir.c_str()); + break; + case 'c': + config.outDir = std::string(optarg); + printf("[INFO]outDir = %s\n", config.outDir.c_str()); + break; + case 'd': + config.batchSize = atoi(optarg); + printf("[INFO]batchSize = %d\n", config.batchSize); + break; + case 'e': + config.deviceId = atoi(optarg); + printf("[INFO]deviceId = %d\n", config.deviceId); + break; + case 'f': + config.loopNum = atoi(optarg); + printf("[INFO]loopNum = %d\n", config.loopNum); + break; + case 'g': + config.modelType = std::string(optarg); + printf("[INFO]modelType = %s\n", config.modelType.c_str()); + break; + case 'h': + config.imgType = std::string(optarg); + printf("[INFO]imgType = %s\n", config.imgType.c_str()); + break; + case 'i': + config.framework = std::string(optarg); + printf("[INFO]framework = %s\n", config.framework.c_str()); + break; + case 'j': + config.useDvpp = atoi(optarg); + printf("[INFO]useDvpp = %d\n", config.useDvpp); + break; + default: + break; + } + } + +} + +// 只校验必须的参数 +aclError ParseParams(int argc, char** argv, Config& config, std::string& errorMsg) +{ + getCommandLineParam(argc, argv, config); + + LOG("parase params start\n"); + + if (config.om.empty() || !FileExists(config.om)) { + LOG("om is empty\n"); + errorMsg = "om path is invalid"; + return ACL_ERROR_PARSE_PARAM_FAILED; + } + + if (config.dataDir.empty() || !FolderExists(config.dataDir)) { + errorMsg = "data Dir is invalid"; + return ACL_ERROR_PARSE_PARAM_FAILED; + } + LOG("dataDir %s \n", config.dataDir.c_str()); + + + if (!config.outDir.empty() && !FolderExists(config.outDir)) { + LOG("output dir %s not exists, try to make dir.\n", config.outDir.c_str()); + mkdir(config.outDir.c_str(), 0755); + LOG("outDir %s \n", config.outDir.c_str()); + } + + if(config.batchSize <= 0){ + errorMsg = "batch Size should be > 0"; + return ACL_ERROR_PARSE_PARAM_FAILED; + } + LOG("batchSize %zd \n", config.batchSize); + + if (config.modelType.empty()) + { + LOG("FLAGS_modelType is empty\n"); + errorMsg = "modelType is invalid"; + return ACL_ERROR_PARSE_PARAM_FAILED; + } + LOG("modelType %s \n", config.modelType.c_str()); + + if (config.imgType.empty()) + { + LOG("imgType is empty\n"); + errorMsg = "imgType is invalid"; + return ACL_ERROR_PARSE_PARAM_FAILED; + } + LOG("imgType %s \n", config.imgType.c_str()); + + LOG("useDvpp is %d \n", config.useDvpp); + + LOG("parase params done\n"); + return ACL_ERROR_NONE; +} + +aclError Process() +{ + std::vector fileNames; + ret = GetFiles(cfg.dataDir, fileNames); + CHECK_RET(ret); + size_t fileNum = fileNames.size(); + LOG("***********fileNum:%zd\n",fileNames.size()); + struct timeval startTmp, endTmp; + + //get img resize weight and height + getImgResizeShape(); + + if(cfg.useDvpp){ + ret = DvppSetup(); + CHECK_RET(ret); + } + + size_t inferCnt = 0; + size_t loopCnt = 0; + while(loopCnt < cfg.loopNum) + { + LOG("loopCnt %d, loopNum %d\n", loopCnt, cfg.loopNum); + for(size_t i = 0; i< fileNum/cfg.batchSize; i++) + { + gettimeofday(&startTmp, NULL); + std::vector batchFileNames; + for (int j = 0; j < cfg.batchSize; j++) { + batchFileNames.push_back(fileNames[i*cfg.batchSize+j]); + } + processedCnt++; + + if(cfg.useDvpp){ + ret = DvppInitInput(batchFileNames); + } + else{ + ret = InitInput(batchFileNames); + } + gettimeofday(&endTmp, NULL); + dataProcTime += (endTmp.tv_sec-startTmp.tv_sec)*1000000+(endTmp.tv_usec-startTmp.tv_usec); + CHECK_RET(ret); + + ret = Inference(); + CHECK_RET(ret); + + ret = SaveBinPostprocess(); + CHECK_RET(ret); + } + + //last img + if (0 != fileNum % cfg.batchSize) + { + std::vector batchFileNames; + for(size_t i = (fileNum - fileNum % cfg.batchSize); i< fileNum; i++) + { + batchFileNames.push_back(fileNames[i]); + } + + gettimeofday(&startTmp, NULL); + processedCnt++; + + if(cfg.useDvpp){ + ret = DvppInitInput(batchFileNames); + } + else{ + ret = InitInput(batchFileNames); + } + gettimeofday(&endTmp, NULL); + dataProcTime += (endTmp.tv_sec-startTmp.tv_sec)*1000000+(endTmp.tv_usec-startTmp.tv_usec); + CHECK_RET(ret); + + ret = Inference(); + CHECK_RET(ret); + + ret = SaveBinPostprocess(); + CHECK_RET(ret); + } + loopCnt++; + } + return ACL_ERROR_NONE; +} + +void SaveResult(){ + ofstream outfile("test_perform_static.txt"); + #if 0 + std::string model_name; + int dex = (cfg.om).find_last_of("/"); + model_name = cfg.om.substr(dex+1); + + std:: string title = "model_name total batch top1 top5 pre_avg/ms pre_imgs/s infer_avg/ms infer_imgs/s mAP"; + outfile << title << endl; + + outfile << model_name << " "; + outfile << processedCnt*cfg.batchSize << " "; + outfile << cfg.batchSize << " "; + if(cfg.postprocessType == "resnet"){ + outfile << 1.0*resnet50Res.top1/resnet50Res.total << " " << 1.0*resnet50Res.top5/resnet50Res.total << " "; + } + else{ + + outfile << "NA" << " " << "NA" << " "; + } + + outfile << avgPreTime << " " << 1.0*1000/avgPreTime << " "; + outfile << avgTime << " " << 1.0*1000/avgTime << " "; + outfile << endl; + #endif + char tmpCh[256]; + memset(tmpCh, 0, sizeof(tmpCh)); + snprintf(tmpCh, sizeof(tmpCh), "NN inference cost average time: %4.3f ms %4.3f fps/s\n", avgTime, (1.0 * 1000/avgTime)); + outfile << tmpCh; + outfile.close(); + +} + + +aclError GetModelInputOutputInfo(Config& cfg) +{ + aclError ret; + + std::ofstream outFile("modelInputOutputInfo", std::ios::trunc); + char tmpChr[256] = {0}; + //Get model input info + size_t inputNum = aclmdlGetNumInputs(cfg.modelDesc); + LOG("model input num %zd\n", inputNum); + snprintf(tmpChr, sizeof(tmpChr), "model input num %zd\n", inputNum); + outFile << tmpChr; + + cfg.inputNum = inputNum; + for (size_t i = 0; i < inputNum && i < MODEL_INPUT_OUTPUT_NUM_MAX; i++) + { + size_t size = aclmdlGetInputSizeByIndex(cfg.modelDesc, i); + cfg.inputInfo[i].size = size; + LOG("model input[%zd] size %zd\n", i, cfg.inputInfo[i].size); + snprintf(tmpChr, sizeof(tmpChr), "model input[%zd] size %zd\n", i, cfg.inputInfo[i].size); + outFile << tmpChr; + + aclmdlIODims dims; + ret = aclmdlGetInputDims(cfg.modelDesc, i, &dims); + if (ACL_ERROR_NONE != ret) + { + LOG("aclmdlGetInputDims fail ret %d\n", ret); + return 1; + } + + cfg.inputInfo[i].dimCount = dims.dimCount; + ret = aclrtMemcpy(cfg.inputInfo[i].dims , cfg.inputInfo[i].dimCount * sizeof(int64_t), dims.dims, cfg.inputInfo[i].dimCount * sizeof(int64_t), ACL_MEMCPY_HOST_TO_HOST); + if (ACL_ERROR_NONE != ret) + { + LOG("aclrtMemcpy fail ret %d line %d\n", ret, __LINE__); + return 1; + } + + LOG("model input[%zd] dimCount %zd\n", i, cfg.inputInfo[i].dimCount); + snprintf(tmpChr, sizeof(tmpChr), "model input[%zd] dimCount %zd\n", i, cfg.inputInfo[i].dimCount); + outFile << tmpChr; + for (size_t dimIdx = 0; dimIdx < cfg.inputInfo[i].dimCount; dimIdx++) + { + LOG("model input[%zd] dim[%zd] info %ld\n", i, dimIdx, cfg.inputInfo[i].dims[dimIdx]); + snprintf(tmpChr, sizeof(tmpChr), "model input[%zd] dim[%zd] info %ld\n", i, dimIdx, cfg.inputInfo[i].dims[dimIdx]); + outFile << tmpChr; + } + + cfg.inputInfo[i].Format = aclmdlGetInputFormat(cfg.modelDesc, i); + + cfg.inputInfo[i].Type = aclmdlGetInputDataType(cfg.modelDesc, i); + + LOG("model input[%zd] format %d inputType %d\n", i, cfg.inputInfo[i].Format, cfg.inputInfo[i].Type); + snprintf(tmpChr, sizeof(tmpChr), "model input[%zd] format %d inputType %d\n", i, cfg.inputInfo[i].Format, cfg.inputInfo[i].Type); + outFile << tmpChr; + + + //const char tmp[ACL_MAX_TENSOR_NAME_LEN] = aclmdlGetInputNameByIndex(cfg.modelDesc, i); + cfg.inputInfo[i].Name = aclmdlGetInputNameByIndex(cfg.modelDesc, i); + LOG("model input[%zd] name %s\n", i, cfg.inputInfo[i].Name); + snprintf(tmpChr, sizeof(tmpChr), "model input[%zd] name %s\n", i, cfg.inputInfo[i].Name); + outFile << tmpChr; + + size_t index; + ret = aclmdlGetInputIndexByName(cfg.modelDesc, cfg.inputInfo[i].Name, &index); + if (ACL_ERROR_NONE != ret) + { + LOG("aclmdlGetInputIndexByName fail ret %d line %d\n", ret, __LINE__); + return 1; + } + + if (i != index) + { + LOG("aclmdlGetInputNameByIndex not equal aclmdlGetInputIndexByName\n"); + return 1; + } + else + { + LOG("model input name %s is belone to input %zd\n", cfg.inputInfo[i].Name, index); + } + + } + + //Get model output info + size_t outputNum = aclmdlGetNumOutputs(cfg.modelDesc); + LOG("model output num %zd\n", outputNum); + snprintf(tmpChr, sizeof(tmpChr), "model output num %zd\n", outputNum); + outFile << tmpChr; + + cfg.outputNum = outputNum; + for (size_t i = 0; i < outputNum && i < MODEL_INPUT_OUTPUT_NUM_MAX; i++) + { + size_t size = aclmdlGetOutputSizeByIndex(cfg.modelDesc, i); + cfg.outputInfo[i].size = size; + LOG("model output[%zd] size %zd\n", i, cfg.outputInfo[i].size); + snprintf(tmpChr, sizeof(tmpChr), "model output[%zd] size %zd\n", i, cfg.outputInfo[i].size); + outFile << tmpChr; + + aclmdlIODims dims; + ret = aclmdlGetOutputDims(cfg.modelDesc, i, &dims); + if (ACL_ERROR_NONE != ret) + { + LOG("aclmdlGetOutputDims fail ret %d\n", ret); + return 1; + } + + cfg.outputInfo[i].dimCount = dims.dimCount; + ret = aclrtMemcpy(cfg.outputInfo[i].dims, cfg.outputInfo[i].dimCount * sizeof(int64_t), dims.dims, cfg.outputInfo[i].dimCount * sizeof(int64_t), ACL_MEMCPY_HOST_TO_HOST); + if (ACL_ERROR_NONE != ret) + { + LOG("aclrtMemcpy fail ret %d line %d\n", ret, __LINE__); + return 1; + } + + LOG("model output[%zd] dimCount %zd\n", i, cfg.outputInfo[i].dimCount); + snprintf(tmpChr, sizeof(tmpChr), "model output[%zd] dimCount %zd\n", i, cfg.outputInfo[i].dimCount); + outFile << tmpChr; + + for (size_t dimIdx = 0; dimIdx < cfg.outputInfo[i].dimCount; dimIdx++) + { + LOG("model output[%zd] dim[%zd] info %ld\n", i, dimIdx, cfg.outputInfo[i].dims[dimIdx]); + snprintf(tmpChr, sizeof(tmpChr), "model output[%zd] dim[%zd] info %ld\n", i, dimIdx, cfg.outputInfo[i].dims[dimIdx]); + outFile << tmpChr; + } + + cfg.outputInfo[i].Format = aclmdlGetOutputFormat(cfg.modelDesc, i); + cfg.outputInfo[i].Type = aclmdlGetOutputDataType(cfg.modelDesc, i); + LOG("model output[%zd] format %d outputType %d\n", i, cfg.outputInfo[i].Format, cfg.outputInfo[i].Type); + snprintf(tmpChr, sizeof(tmpChr), "model output[%zd] format %d outputType %d\n", i, cfg.outputInfo[i].Format, cfg.outputInfo[i].Type); + outFile << tmpChr; + + cfg.outputInfo[i].Name = aclmdlGetOutputNameByIndex(cfg.modelDesc, i); + LOG("model output[%zd] name %s\n", i, cfg.outputInfo[i].Name); + snprintf(tmpChr, sizeof(tmpChr), "model output[%zd] name %s\n", i, cfg.outputInfo[i].Name); + outFile << tmpChr; + + size_t index; + ret = aclmdlGetOutputIndexByName(cfg.modelDesc, cfg.outputInfo[i].Name, &index); + if (ACL_ERROR_NONE != ret) + { + LOG("aclmdlGetOutputIndexByName fail ret %d line %d\n", ret, __LINE__); + return 1; + } + + if (i != index) + { + LOG("aclmdlGetOutputNameByIndex not equal aclmdlGetOutputIndexByName\n"); + return 1; + } + else + { + LOG("model output name %s is belone to output %d\n", cfg.outputInfo[i].Name, index); + } + + } + + outFile.close(); + + return ACL_ERROR_NONE; + +} + + +int main(int argc, char** argv) +{ + processedCnt = 0; + inferTime = 0; + + std::string errorMsg; + ret = ParseParams(argc, argv, cfg, errorMsg); + CHECK_ACL_RET(errorMsg, ret); + + ret = InitContext(); + CHECK_RET(ret); + + ret = LoadModel(); + CHECK_RET(ret); + + ret = GetModelInputOutputInfo(cfg); + CHECK_RET(ret); + + ret = Process(); + CHECK_RET(ret); + + ret = UnloadModel(); + CHECK_RET(ret); + + ret = UnInitContext(); + CHECK_RET(ret); + LOG("\n"); + + avgTime = 1.0*inferTime/processedCnt/cfg.batchSize/1000; + avgPreTime = 1.0*dataProcTime/processedCnt/cfg.batchSize/1000; + + if (cfg.useDvpp){ + LOG("\n"); + LOG("DVPP performance details:\n"); + LOG("#############################################\n"); + std::unordered_map::iterator iter; + for (iter = dvppTime.begin(); iter != dvppTime.end(); iter++){ + LOG("%s using avg time %0.2f ms\n",iter->first.c_str(),1.0*iter->second/processedCnt/cfg.batchSize/1000); + } + LOG("\n"); + } + + LOG("performance summary:\n"); + LOG("#############################################\n"); + LOG("total %ld imgs processed and batch size %ld\n", processedCnt*cfg.batchSize, cfg.batchSize); + #if 0 + if(cfg.postprocessType == "resnet"){ + LOG("top1 ratio %0.3f top5 ratio %0.3f\n", 1.0*resnet50Res.top1/resnet50Res.total, 1.0*resnet50Res.top5/resnet50Res.total); + } + #endif + + LOG("avg preprocess time %0.2f ms, %0.2f imgs/s\n", avgPreTime, 1.0*1000/avgPreTime); + LOG("avg inference time %0.2f ms, %0.2f imgs/s\n", avgTime, 1.0*1000/avgTime); + + SaveResult(); + +} diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/post_process.cpp b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/post_process.cpp new file mode 100644 index 000000000..b0914ded3 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/post_process.cpp @@ -0,0 +1,131 @@ +/* * +* Copyright 2020 Huawei Technologies Co., Ltd +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* */ + +#include "post_process.h" +#include "util.h" +#include +#include +#include +#include +#include "stdio.h" +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +extern int processedCnt; + +extern Config cfg; +extern DataFrame outputDataframe; +extern aclError ret; +int topNum = 5; + +extern int processedCnt; + +aclError SaveBinPostprocess() +{ + aclError retVal; + + LOG("save batch %d start\n", processedCnt); + DataFrame dataframe = outputDataframe; + std::vector& inferFile_vec = outputDataframe.fileNames; + aclmdlDataset* output = dataframe.dataset; + + std::string resultFolder = cfg.outDir + "/" + cfg.modelType; + DIR* op = opendir(resultFolder.c_str()); + if (NULL == op){ + mkdir(resultFolder.c_str(), 00775); + }else{ + closedir(op); + } + + for (size_t i = 0; i < cfg.outputNum; ++i) + { + aclDataBuffer* dataBuffer = aclmdlGetDatasetBuffer(output, i); + void* data = aclGetDataBufferAddr(dataBuffer); + uint32_t len; + len = cfg.outputInfo[i].size; + + //LOG("output[%d] real data len %d\n", i, len); + void* outHostData = NULL; + ret = aclrtMallocHost(&outHostData, len); + if (ret != ACL_ERROR_NONE) { + LOG("Malloc host failed.\n"); + return 1; + } + + ret = aclrtMemcpy(outHostData, len, data, len, ACL_MEMCPY_DEVICE_TO_HOST); + if (ret != ACL_ERROR_NONE) { + LOG("Copy device to host failed.\n"); + aclrtFreeHost(outHostData); + return 1; + } + + uint32_t eachSize = len / cfg.batchSize; + //LOG("inferenceIndex=%d, out_index=%d, len=%d, eachSize=%d\n", inferenceIndex, i, len,eachSize); + for (size_t j = 0; j < inferFile_vec.size(); j++) + { + FILE* outputFile; + std::string framename = inferFile_vec[j]; + std::size_t dex = (framename).find_first_of("."); + std::string inputFileName = (framename).erase(dex); + + if (cfg.modelType.compare(0, 6, "resnet") == 0){ + outputFile = fopen((resultFolder + "/" + "davinci_" + inputFileName + "_" + "output" + ".bin").c_str(), "wb"); + }else{ + outputFile = fopen((resultFolder + "/" + "davinci_" + inputFileName + "_" + "output" + std::to_string(i) + ".bin").c_str(), "wb"); + } + + if (NULL == outputFile){ + aclrtFreeHost(outHostData); + return 1; + } + + fwrite((uint8_t *)outHostData + (j * eachSize), eachSize, sizeof(char), outputFile); + fclose(outputFile); + } + + ret = aclrtFreeHost(outHostData); + if (ret != ACL_ERROR_NONE) { + LOG("Free output host failed.\n"); + } + } + + (void)DestroyDatasetResurce(outputDataframe.dataset, 0); + + LOG("save batch %d done\n", processedCnt); + return ACL_ERROR_NONE; +} diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/util.cpp b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/util.cpp new file mode 100644 index 000000000..74eea1b5c --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/util.cpp @@ -0,0 +1,214 @@ +/* * +* Copyright 2020 Huawei Technologies Co., Ltd +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* */ + +#include "util.h" +#include +#include +#include +#if 0 +static std::unordered_map errorMap = { + {ACL_ERROR_NONE, "success"}, + {ACL_ERROR_INVALID_PARAM, "params may not valid"}, + {ACL_ERROR_BAD_ALLOC, "alloc memory failed"}, + {ACL_ERROR_RT_FAILURE, "runtime failure"}, + {ACL_ERROR_GE_FAILURE, "GE failure"}, + {ACL_ERROR_OP_NOT_FOUND, "OP not find"}, + {ACL_ERROR_OP_LOAD_FAILED, "OP loads failed"}, + {ACL_ERROR_READ_MODEL_FAILURE, "load model failed"}, + {ACL_ERROR_PARSE_MODEL, "parse model failed"}, + {ACL_ERROR_MODEL_MISSING_ATTR, "model misssing attr"}, + {ACL_ERROR_DESERIALIZE_MODEL, "deserilize model failed"}, + // {ACL_ERROR_MULTIPLE_MODEL_MATCHED, "multiple model matched"}, + //{ACL_ERROR_EVENT_NOT_READY, "event not ready"}, + //{ACL_ERROR_EVENT_COMPLETE, "event not complete"}, + {ACL_ERROR_UNSUPPORTED_DATA_TYPE, "unsupport datatype"}, + {ACL_ERROR_REPEAT_INITIALIZE, "initial repeated"}, + //{ACL_ERROR_COMPILER_NOT_REGISTERED, "compilter not registered"}, + {ACL_ERROR_PATH_INVALID, "path invalid"}, + {ACL_ERROR_PARSE_PARAM_FAILED, "parse params failed"}, + {ACL_ERROR_DVPP_ERROR, "dvpp errors"} +}; + + +std::string CausedBy(aclError error) +{ + return errorMap[error]; +} +#endif + +bool FolderExists(std::string foldname) +{ + DIR* dir; + + if ((dir = opendir(foldname.c_str())) == NULL) { + return false; + } + + closedir(dir); + + return true; +} + + +bool FileExists(std::string filename) +{ + std::fstream file; + file.open(filename, std::ios::in); + + if (!file) { + return false; + } + + file.close(); + return true; +} + + + + +char* ReadBinFile(std::string fileName, uint32_t& fileSize) +{ + std::ifstream binFile(fileName, std::ifstream::binary); + + if (binFile.is_open() == false) { + LOG("open file[%s] failed\n", fileName.c_str()); + return nullptr; + } + + binFile.seekg(0, binFile.end); + uint32_t binFileBufferLen = binFile.tellg(); + + if (binFileBufferLen == 0) { + LOG("binfile is empty, filename: %s", fileName.c_str()); + binFile.close(); + return nullptr; + } + + binFile.seekg(0, binFile.beg); + char* binFileBufferData = new(std::nothrow) char[binFileBufferLen]; + LOG("binFileBufferData:%p\n", binFileBufferData); + + if (binFileBufferData == nullptr) { + LOG("malloc binFileBufferData failed\n"); + binFile.close(); + return nullptr; + } + + binFile.read(binFileBufferData, binFileBufferLen); + binFile.close(); + fileSize = binFileBufferLen; + return binFileBufferData; +} + +aclError GetFiles(std::string path, std::vector& files) +{ + DIR* dir; + struct dirent* ptr; + char base[1000]; + + if ((dir = opendir(path.c_str())) == NULL) { + LOG("Open dir %s error.\n", path.c_str()); + return ACL_ERROR_PATH_INVALID; + } + + while ((ptr = readdir(dir)) != NULL) { + if (strcmp(ptr->d_name, ".") == 0 || strcmp(ptr->d_name, "..") == 0) { + //current dir OR parrent dir + continue; + } else if (ptr->d_type == 8) { + //file + files.push_back(ptr->d_name); + } else if (ptr->d_type == 10) { + //link file + continue; + } else if (ptr->d_type == 4) { + //dir + continue; + } + } + + closedir(dir); + std::sort(files.begin(), files.end()); + return ACL_ERROR_NONE; +} + +aclError FreeDevMemory(aclmdlDataset* dataset) +{ + aclError ret; + + for (size_t i = 0; i < aclmdlGetDatasetNumBuffers(dataset); ++i) { + aclDataBuffer* dataBuffer = aclmdlGetDatasetBuffer(dataset, i); + void* data = aclGetDataBufferAddr(dataBuffer); + aclrtFree(data); + aclDestroyDataBuffer(dataBuffer); + } + + return ACL_ERROR_NONE; +} + +aclError DestroyDatasetResurce(aclmdlDataset* dataset, uint32_t flag) +{ + aclError ret = ACL_ERROR_NONE; + + if (nullptr == dataset) { + LOG("dataset == null\n"); + return 1; + } + + for (size_t i = 0; i < aclmdlGetDatasetNumBuffers(dataset); ++i) { + aclDataBuffer* dataBuffer = aclmdlGetDatasetBuffer(dataset, i); + if (nullptr == dataBuffer) { + LOG("dataBuffer == null\n"); + continue; + } + + void* data = aclGetDataBufferAddr(dataBuffer); + if (nullptr != data) { + if (1 == flag) { + if (i > 0) { + ret = aclrtFree(data); + if (ret != ACL_ERROR_NONE) { + LOG("aclrtFree data failed, ret %d\n", ret); + } + } else { + ret = acldvppFree(data); + if (ret != ACL_ERROR_NONE) { + LOG("acldvppFree data failed, ret %d\n", ret); + } + } + } else { + ret = aclrtFree(data); + if (ret != ACL_ERROR_NONE) { + LOG("aclrtFree data failed, ret %d\n", ret); + } + } + } + + ret = aclDestroyDataBuffer(dataBuffer); + if (ret != ACL_ERROR_NONE) { + LOG("Destroy dataBuffer failed, ret %d\n", ret); + } + } + + ret = aclmdlDestroyDataset(dataset); + if (ret != ACL_ERROR_NONE) { + LOG("aclrtFree dataset failed, ret %d\n", ret); + } + + return ret; +} + + -- Gitee From 992e4f2fa7563ae4392d8114141e5a50c4ba3586 Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 06:56:35 +0000 Subject: [PATCH 05/22] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/.keep diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/.keep b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/.keep new file mode 100644 index 000000000..e69de29bb -- Gitee From ed8536d2dab33aba6e21eb5cc84dc433d77ca816 Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 06:57:14 +0000 Subject: [PATCH 06/22] update. --- .../script/advanced_east.py | 70 ++++++ .../cv/Advanced_East_for_ACL/script/atc.sh | 3 + .../cv/Advanced_East_for_ACL/script/cfg.py | 102 ++++++++ .../Advanced_East_for_ACL/script/cfg_bank.py | 101 ++++++++ .../script/clock_wise.py | 64 +++++ .../Advanced_East_for_ACL/script/h5_to_pb.py | 68 ++++++ .../Advanced_East_for_ACL/script/image2bin.py | 89 +++++++ .../script/image_util.py | 216 +++++++++++++++++ .../cv/Advanced_East_for_ACL/script/label.py | 202 ++++++++++++++++ .../cv/Advanced_East_for_ACL/script/msame.sh | 6 + .../script/network_add_bn.py | 219 ++++++++++++++++++ .../cv/Advanced_East_for_ACL/script/nms.py | 114 +++++++++ .../script/postprocess.py | 178 ++++++++++++++ .../Advanced_East_for_ACL/script/predict.py | 50 ++++ .../script/preprocess.py | 208 +++++++++++++++++ 15 files changed, 1690 insertions(+) create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/advanced_east.py create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/atc.sh create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/cfg.py create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/cfg_bank.py create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/clock_wise.py create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/h5_to_pb.py create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/image2bin.py create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/image_util.py create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/label.py create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/msame.sh create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/network_add_bn.py create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/nms.py create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/postprocess.py create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/predict.py create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/preprocess.py diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/advanced_east.py b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/advanced_east.py new file mode 100644 index 000000000..8abd97584 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/advanced_east.py @@ -0,0 +1,70 @@ +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint +import os + +from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint +from tensorflow.keras.optimizers import Adam + +# from keras.callbacks import EarlyStopping, ModelCheckpoint +# from keras.optimizers import Adam +import cfg +from data_generator import gen +from losses import quad_loss +# from network_tf import East +from network_tensorflow_changeVGG_npu import East + +os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" +os.environ[ + "CUDA_VISIBLE_DEVICES"] = "1" # 这里是gpu的序号,指定使用的gpu对象config = tf.ConfigProto()config.gpu_options.allow_growth = True + +east = East() +east_network = east.east_network() +east_network.summary() +east_network.compile(loss=quad_loss, optimizer=Adam(lr=cfg.lr, + # clipvalue=cfg.clipvalue, + decay=cfg.decay)) +if cfg.load_weights and os.path.exists(cfg.saved_model_weights_file_path): + east_network.load_weights(cfg.saved_model_weights_file_path) +east_network.fit_generator(generator=gen(), + steps_per_epoch=cfg.steps_per_epoch, + epochs=cfg.epoch_num, + validation_data=gen(is_val=True), + validation_steps=cfg.validation_steps, + verbose=1, + initial_epoch=cfg.initial_epoch, + callbacks=[ + EarlyStopping(patience=cfg.patience, verbose=1), + ModelCheckpoint(filepath=cfg.model_weights_path, + save_best_only=True, + save_weights_only=True, + verbose=1)]) +east_network.save(cfg.saved_model_file_path) +east_network.save_weights(cfg.saved_model_weights_file_path) diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/atc.sh b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/atc.sh new file mode 100644 index 000000000..dcb54cffe --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/atc.sh @@ -0,0 +1,3 @@ +#!/bin/bash +atc --model=model.pb --input_shape="input_img:1,736,736,3" --framework=3 --output=./om/modelom --soc_version=Ascend310 --input_format=NHWC \ + diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/cfg.py b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/cfg.py new file mode 100644 index 000000000..4d444a6f9 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/cfg.py @@ -0,0 +1,102 @@ +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +train_task_id = '3T736' +initial_epoch = 0 +epoch_num = 24 +lr = 1e-3 +decay = 5e-4 +# clipvalue = 0.5 # default 0.5, 0 means no clip +patience = 5 +load_weights = False +lambda_inside_score_loss = 4.0 +lambda_side_vertex_code_loss = 1.0 +lambda_side_vertex_coord_loss = 1.0 + +total_img = 10000 +validation_split_ratio = 0.1 +max_train_img_size = int(train_task_id[-3:]) +max_predict_img_size = int(train_task_id[-3:]) # 2400 +assert max_train_img_size in [256, 384, 512, 640, 736], \ + 'max_train_img_size must in [256, 384, 512, 640, 736]' +if max_train_img_size == 256: + batch_size = 8 +elif max_train_img_size == 384: + batch_size = 4 +elif max_train_img_size == 512: + batch_size = 2 +else: + batch_size = 1 +steps_per_epoch = total_img * (1 - validation_split_ratio) // batch_size +validation_steps = total_img * validation_split_ratio // batch_size + +data_dir = 'icpr/' +origin_image_dir_name = 'image_10000/' +origin_txt_dir_name = 'txt_10000/' +train_image_dir_name = 'images_%s/' % train_task_id +train_label_dir_name = 'labels_%s/' % train_task_id +show_gt_image_dir_name = 'show_gt_images_%s/' % train_task_id +show_act_image_dir_name = 'show_act_images_%s/' % train_task_id +gen_origin_img = True +draw_gt_quad = True +draw_act_quad = True +val_fname = 'val_%s.txt' % train_task_id +train_fname = 'train_%s.txt' % train_task_id +# in paper it's 0.3, maybe to large to this problem +shrink_ratio = 0.2 +# pixels between 0.2 and 0.6 are side pixels +shrink_side_ratio = 0.6 +epsilon = 1e-4 + +num_channels = 3 +feature_layers_range = range(5, 1, -1) +# feature_layers_range = range(3, 0, -1) +feature_layers_num = len(feature_layers_range) +# pixel_size = 4 +pixel_size = 2 ** feature_layers_range[-1] +locked_layers = False + +if not os.path.exists('model'): + os.mkdir('model') +if not os.path.exists('saved_model'): + os.mkdir('saved_model') + +model_weights_path = 'model/weights_%s.{epoch:03d}-{val_loss:.3f}.h5' \ + % train_task_id +saved_model_file_path = 'saved_model/east_model_%s.h5' % train_task_id +saved_model_weights_file_path = 'saved_model/east_model_weights_%s.h5' \ + % train_task_id + +pixel_threshold = 0.9 +side_vertex_pixel_threshold = 0.9 +trunc_threshold = 0.1 +predict_cut_text_line = False +predict_write2txt = True +quiet = True diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/cfg_bank.py b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/cfg_bank.py new file mode 100644 index 000000000..c7e6f919d --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/cfg_bank.py @@ -0,0 +1,101 @@ +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +train_task_id = '3T832' +initial_epoch = 0 +epoch_num = 24 +lr = 1e-3 +decay = 5e-4 +# clipvalue = 0.5 # default 0.5, 0 means no clip +patience = 5 +load_weights = False +lambda_inside_score_loss = 4.0 +lambda_side_vertex_code_loss = 1.0 +lambda_side_vertex_coord_loss = 1.0 + +total_img = 10000 +validation_split_ratio = 0.1 +max_train_img_size = int(train_task_id[-3:]) +max_predict_img_size = int(train_task_id[-3:]) # 2400 +assert max_train_img_size in [256, 384, 512, 640, 736, 832], \ + 'max_train_img_size must in [256, 384, 512, 640, 736, 832]' +if max_train_img_size == 256: + batch_size = 8 +elif max_train_img_size == 384: + batch_size = 4 +elif max_train_img_size == 512: + batch_size = 2 +else: + batch_size = 1 +steps_per_epoch = total_img * (1 - validation_split_ratio) // batch_size +validation_steps = total_img * validation_split_ratio // batch_size + +data_dir = 'dataset/train' +origin_image_dir_name = 'pitures/' +origin_txt_dir_name = 'txts/' +train_image_dir_name = 'images_%s/' % train_task_id +train_label_dir_name = 'labels_%s/' % train_task_id +show_gt_image_dir_name = 'show_gt_images_%s/' % train_task_id +show_act_image_dir_name = 'show_act_images_%s/' % train_task_id +gen_origin_img = True +draw_gt_quad = True +draw_act_quad = True +val_fname = 'val_%s.txt' % train_task_id +train_fname = 'train_%s.txt' % train_task_id +# in paper it's 0.3, maybe to large to this problem +shrink_ratio = 0.2 +# pixels between 0.2 and 0.6 are side pixels +shrink_side_ratio = 0.6 +epsilon = 1e-4 + +num_channels = 3 +feature_layers_range = range(5, 1, -1) +# feature_layers_range = range(3, 0, -1) +feature_layers_num = len(feature_layers_range) +# pixel_size = 4 +pixel_size = 2 ** feature_layers_range[-1] +locked_layers = False + +if not os.path.exists('model'): + os.mkdir('model') +if not os.path.exists('saved_model'): + os.mkdir('saved_model') + +model_weights_path = 'model/weights_%s.{epoch:03d}-{val_loss:.3f}.h5' \ + % train_task_id +saved_model_file_path = 'saved_model/east_model_%s.h5' % train_task_id +saved_model_weights_file_path = 'saved_model/east_model_weights_%s.h5' \ + % train_task_id + +pixel_threshold = 0.7 +side_vertex_pixel_threshold = 0.7 +trunc_threshold = 0.1 +predict_cut_text_line = False +predict_write2txt = True diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/clock_wise.py b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/clock_wise.py new file mode 100644 index 000000000..ae3709ee9 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/clock_wise.py @@ -0,0 +1,64 @@ +from scipy.spatial import distance as dist +import numpy as np +import math + +def cos_dist(a, b): + if len(a) != len(b): + return None + part_up = 0.0 + a_sq = 0.0 + b_sq = 0.0 + for a1, b1 in zip(a,b): + part_up += a1*b1 + a_sq += a1**2 + b_sq += b1**2 + part_down = math.sqrt(a_sq*b_sq) + if part_down == 0.0: + return None + else: + return part_up / part_down + +def order_points(pts): + xSorted = pts[np.argsort(pts[:, 0]), :] + leftMost = xSorted[:2, :] + rightMost = xSorted[2:, :] + + leftMost = leftMost[np.argsort(leftMost[:, 1]), :] + (tl, bl) = leftMost + D = dist.cdist(tl[np.newaxis], rightMost, "euclidean")[0] + (br, tr) = rightMost[np.argsort(D)[::-1], :] + return np.array([tl, tr, br, bl], dtype="int32") + +def order_points_quadrangle(pts): + xSorted = pts[np.argsort(pts[:, 0]), :] + leftMost = xSorted[:2, :] + rightMost = xSorted[2:, :] + leftMost = leftMost[np.argsort(leftMost[:, 1]), :] + (tl, bl) = leftMost + + vector_0 = np.array(bl-tl) + vector_1 = np.array(rightMost[0]-tl) + vector_2 = np.array(rightMost[1]-tl) + angle = [np.arccos(cos_dist(vector_0, vector_1)), np.arccos(cos_dist(vector_0, vector_2))] + (br, tr) = rightMost[np.argsort(angle), :] + return np.array([tl, tr, br, bl], dtype="int32") + +from functools import reduce +import operator +import math +def order_points_tuple(pts): + pts = pts.tolist() + coords = [] + for elem in pts: + coords.append(tuple(elem)) + center = tuple(map(operator,truediv, reduce(lambda x, y:map(operator.add, x, y), coords), [len(coords)] * 2)) + output = sorted(coords, key=lambda coords: (-135 - math.degrees(math.atan2(*tuple(map(operator.sub, coords, center))[::-1]))) % 360, reverse=True) + res = [] + for elem in output: + res.append(list(elem)) + return np.array(res, dtype="int32") +points = np.array([[54,20],[39,48],[117,52],[121,21]]) +print(order_points(points)) +pt = np.array([703,211,754,283,756,223,747,212]).reshape(4,2) +print(order_points(pt)) +print(order_points_tuple(pt)) \ No newline at end of file diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/h5_to_pb.py b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/h5_to_pb.py new file mode 100644 index 000000000..fa6c05dad --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/h5_to_pb.py @@ -0,0 +1,68 @@ +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from tensorflow.keras.models import load_model +import tensorflow as tf +import os +import os.path as osp +from tensorflow.keras import backend as K +from network_add_bn import East +from predict import predict_txt +import cfg + +#路径参数 +input_path = './model/' +weight_file = 'east_model_3T832.h5' +weight_file_path = osp.join(input_path,weight_file) +output_graph_name = weight_file[:-3] + '.pb' +#转换函数 +def h5_to_pb(h5_model,output_dir,model_name,out_prefix = "output_",log_tensorboard = True): + if osp.exists(output_dir) == False: + os.mkdir(output_dir) + out_nodes = [] + for i in range(len(h5_model.outputs)): + out_nodes.append(out_prefix + str(i + 1)) + tf.identity(h5_model.output[i],out_prefix + str(i + 1)) + sess = K.get_session() + from tensorflow.python.framework import graph_util,graph_io + init_graph = sess.graph.as_graph_def() + main_graph = graph_util.convert_variables_to_constants(sess,init_graph,out_nodes) + graph_io.write_graph(main_graph,output_dir,name = model_name,as_text = False) + if log_tensorboard: + from tensorflow.python.tools import import_pb_to_tensorboard + import_pb_to_tensorboard.import_to_tensorboard(osp.join(output_dir,model_name),output_dir) +#输出路径 +output_dir = "trans_model" +#加载模型 +east = East() +east_detect = east.east_network() +east_detect.load_weights(cfg.saved_model_weights_file_path) +h5_model =east_detect +h5_to_pb(h5_model,output_dir = output_dir,model_name = output_graph_name) +print('model saved') \ No newline at end of file diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/image2bin.py b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/image2bin.py new file mode 100644 index 000000000..291e0e844 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/image2bin.py @@ -0,0 +1,89 @@ +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import cfg +import argparse +import os +import numpy as np +from PIL import Image, ImageDraw +from tensorflow.keras.applications.vgg16 import preprocess_input +from tensorflow.keras.preprocessing import image + +def resize_image(im, max_img_size=cfg.max_train_img_size): + im_width = np.minimum(im.width, max_img_size) + if im_width == max_img_size < im.width: + im_height = int((im_width / im.width) * im.height) + else: + im_height = im.height + o_height = np.minimum(im_height, max_img_size) + if o_height == max_img_size < im_height: + o_width = int((o_height / im_height) * im_width) + else: + o_width = im_width + d_wight = o_width - (o_width % 32) + d_height = o_height - (o_height % 32) + return d_wight, d_height + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--src_path", default="../image_test1", help="path of original pictures") + parser.add_argument("--dst_path", default="../image_test_bin", help="path of output bin files") + parser.add_argument("--pic_num", default=10000, help="picture number") + args = parser.parse_args() + src_path = args.src_path + dst_path = args.dst_path + pic_num = args.pic_num + files = os.listdir(src_path) + files.sort() + n = 0 + for file in files: + src = src_path + "/" + file + print("start to process %s"%src) + img = image.load_img(src) + d_wight, d_height = resize_image(img, cfg.max_predict_img_size) + img = img.resize((d_wight, d_height), Image.NEAREST).convert('RGB') + img = image.img_to_array(img,dtype=np.float32) + print(img.shape) + print(d_wight, d_height) + if d_height != 736: + zero = np.zeros((736 - d_height, d_wight, 3),dtype=np.float32) + img = np.concatenate((img, zero), axis=0) + print(img.shape) + if d_wight != 736: + zero = np.zeros((736, 736 - d_wight, 3),dtype=np.float32) + img = np.concatenate((img, zero), axis=1) + print('img.shape', img.shape) + img = preprocess_input(img, mode='tf') + x = np.expand_dims(img, axis=0) + print('x.shape', x.shape) + print(x.dtype) + x.tofile(dst_path + "/" + file + ".bin") + n += 1 + if int(pic_num) == n: + break \ No newline at end of file diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/image_util.py b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/image_util.py new file mode 100644 index 000000000..5a2c1f67f --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/image_util.py @@ -0,0 +1,216 @@ +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import warnings +import tensorflow as tf +from tensorflow.python.ops import variables as tf_variables + +def _obtain_input_shape(input_shape, + default_size, + min_size, + data_format, + require_flatten, + weights=None): + """Internal utility to compute/validate a model's input shape. + + # Arguments + input_shape: Either None (will return the default network input shape), + or a user-provided shape to be validated. + default_size: Default input width/height for the model. + min_size: Minimum input width/height accepted by the model. + data_format: Image data format to use. + require_flatten: Whether the model is expected to + be linked to a classifier via a Flatten layer. + weights: One of `None` (random initialization) + or 'imagenet' (pre-training on ImageNet). + If weights='imagenet' input channels must be equal to 3. + + # Returns + An integer shape tuple (may include None entries). + + # Raises + ValueError: In case of invalid argument values. + """ + if weights != 'imagenet' and input_shape and len(input_shape) == 3: + if data_format == 'channels_first': + if input_shape[0] not in {1, 3}: + warnings.warn( + 'This model usually expects 1 or 3 input channels. ' + 'However, it was passed an input_shape with ' + + str(input_shape[0]) + ' input channels.') + default_shape = (input_shape[0], default_size, default_size) + else: + if input_shape[-1] not in {1, 3}: + warnings.warn( + 'This model usually expects 1 or 3 input channels. ' + 'However, it was passed an input_shape with ' + + str(input_shape[-1]) + ' input channels.') + default_shape = (default_size, default_size, input_shape[-1]) + else: + if data_format == 'channels_first': + default_shape = (3, default_size, default_size) + else: + default_shape = (default_size, default_size, 3) + if weights == 'imagenet' and require_flatten: + if input_shape is not None: + if input_shape != default_shape: + raise ValueError('When setting`include_top=True` ' + 'and loading `imagenet` weights, ' + '`input_shape` should be ' + + str(default_shape) + '.') + return default_shape + if input_shape: + if data_format == 'channels_first': + if input_shape is not None: + if len(input_shape) != 3: + raise ValueError( + '`input_shape` must be a tuple of three integers.') + if input_shape[0] != 3 and weights == 'imagenet': + raise ValueError('The input must have 3 channels; got ' + '`input_shape=' + str(input_shape) + '`') + if ((input_shape[1] is not None and input_shape[1] < min_size) or + (input_shape[2] is not None and input_shape[2] < min_size)): + raise ValueError('Input size must be at least ' + + str(min_size) + 'x' + str(min_size) + '; got ' + '`input_shape=' + str(input_shape) + '`') + else: + if input_shape is not None: + if len(input_shape) != 3: + raise ValueError( + '`input_shape` must be a tuple of three integers.') + if input_shape[-1] != 3 and weights == 'imagenet': + raise ValueError('The input must have 3 channels; got ' + '`input_shape=' + str(input_shape) + '`') + if ((input_shape[0] is not None and input_shape[0] < min_size) or + (input_shape[1] is not None and input_shape[1] < min_size)): + raise ValueError('Input size must be at least ' + + str(min_size) + 'x' + str(min_size) + '; got ' + '`input_shape=' + str(input_shape) + '`') + else: + if require_flatten: + input_shape = default_shape + else: + if data_format == 'channels_first': + input_shape = (3, None, None) + else: + input_shape = (None, None, 3) + if require_flatten: + if None in input_shape: + raise ValueError('If `include_top` is True, ' + 'you should specify a static `input_shape`. ' + 'Got `input_shape=' + str(input_shape) + '`') + return input_shape + + + +def get_source_inputs(tensor, layer=None, node_index=None): + """Returns the list of input tensors necessary to compute `tensor`. + + Output will always be a list of tensors + (potentially with 1 element). + + # Arguments + tensor: The tensor to start from. + layer: Origin layer of the tensor. Will be + determined via tensor._keras_history if not provided. + node_index: Origin node index of the tensor. + + # Returns + List of input tensors. + """ + if not hasattr(tensor, '_keras_history'): + return tensor + + if layer is None or node_index: + layer, node_index, _ = tensor._keras_history + if not layer._inbound_nodes: + return [tensor] + else: + node = layer._inbound_nodes[node_index] + if not node.inbound_layers: + # Reached an Input layer, stop recursion. + return node.input_tensors + else: + source_tensors = [] + for i in range(len(node.inbound_layers)): + x = node.input_tensors[i] + layer = node.inbound_layers[i] + node_index = node.node_indices[i] + previous_sources = get_source_inputs(x, + layer, + node_index) + # Avoid input redundancy. + for x in previous_sources: + if x not in source_tensors: + source_tensors.append(x) + return source_tensors + +def is_keras_tensor(x): + """Returns whether `x` is a Keras tensor. + + A "Keras tensor" is a tensor that was returned by a Keras layer, + (`Layer` class) or by `Input`. + + # Arguments + x: A candidate tensor. + + # Returns + A boolean: Whether the argument is a Keras tensor. + + # Raises + ValueError: In case `x` is not a symbolic tensor. + + # Examples + ```python + >>> from keras import backend as K + >>> from keras.layers import Input, Dense + >>> np_var = numpy.array([1, 2]) + >>> K.is_keras_tensor(np_var) # A numpy array is not a symbolic tensor. + ValueError + >>> k_var = tf.placeholder('float32', shape=(1,1)) + >>> K.is_keras_tensor(k_var) # A variable indirectly created outside of keras is not a Keras tensor. + False + >>> keras_var = K.variable(np_var) + >>> K.is_keras_tensor(keras_var) # A variable created with the keras backend is not a Keras tensor. + False + >>> keras_placeholder = K.placeholder(shape=(2, 4, 5)) + >>> K.is_keras_tensor(keras_placeholder) # A placeholder is not a Keras tensor. + False + >>> keras_input = Input([10]) + >>> K.is_keras_tensor(keras_input) # An Input is a Keras tensor. + True + >>> keras_layer_output = Dense(10)(keras_input) + >>> K.is_keras_tensor(keras_layer_output) # Any Keras layer output is a Keras tensor. + True + ``` + """ + if not isinstance(x, (tf.Tensor, + tf_variables.Variable, + tf.SparseTensor)): + raise ValueError('Unexpectedly found an instance of type `' + str(type(x)) + '`. ' + 'Expected a symbolic tensor instance.') + return hasattr(x, '_keras_history') \ No newline at end of file diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/label.py b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/label.py new file mode 100644 index 000000000..1092f0989 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/label.py @@ -0,0 +1,202 @@ +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np +import os +from PIL import Image, ImageDraw +from tqdm import tqdm +import cfg + + +def point_inside_of_quad(px, py, quad_xy_list, p_min, p_max): + if (p_min[0] <= px <= p_max[0]) and (p_min[1] <= py <= p_max[1]): + xy_list = np.zeros((4, 2)) + xy_list[:3, :] = quad_xy_list[1:4, :] - quad_xy_list[:3, :] + xy_list[3] = quad_xy_list[0, :] - quad_xy_list[3, :] + yx_list = np.zeros((4, 2)) + yx_list[:, :] = quad_xy_list[:, -1:-3:-1] + a = xy_list * ([py, px] - yx_list) + b = a[:, 0] - a[:, 1] + if np.amin(b) >= 0 or np.amax(b) <= 0: + return True + else: + return False + else: + return False + + +def point_inside_of_nth_quad(px, py, xy_list, shrink_1, long_edge): + nth = -1 + vs = [[[0, 0, 3, 3, 0], [1, 1, 2, 2, 1]], + [[0, 0, 1, 1, 0], [2, 2, 3, 3, 2]]] + for ith in range(2): + quad_xy_list = np.concatenate(( + np.reshape(xy_list[vs[long_edge][ith][0]], (1, 2)), + np.reshape(shrink_1[vs[long_edge][ith][1]], (1, 2)), + np.reshape(shrink_1[vs[long_edge][ith][2]], (1, 2)), + np.reshape(xy_list[vs[long_edge][ith][3]], (1, 2))), axis=0) + p_min = np.amin(quad_xy_list, axis=0) + p_max = np.amax(quad_xy_list, axis=0) + if point_inside_of_quad(px, py, quad_xy_list, p_min, p_max): + if nth == -1: + nth = ith + else: + nth = -1 + break + return nth + + +def shrink(xy_list, ratio=cfg.shrink_ratio): + if ratio == 0.0: + return xy_list, xy_list + diff_1to3 = xy_list[:3, :] - xy_list[1:4, :] + diff_4 = xy_list[3:4, :] - xy_list[0:1, :] + diff = np.concatenate((diff_1to3, diff_4), axis=0) + dis = np.sqrt(np.sum(np.square(diff), axis=-1)) + # determine which are long or short edges + long_edge = int(np.argmax(np.sum(np.reshape(dis, (2, 2)), axis=0))) + short_edge = 1 - long_edge + # cal r length array + r = [np.minimum(dis[i], dis[(i + 1) % 4]) for i in range(4)] + # cal theta array + diff_abs = np.abs(diff) + diff_abs[:, 0] += cfg.epsilon + theta = np.arctan(diff_abs[:, 1] / diff_abs[:, 0]) + # shrink two long edges + temp_new_xy_list = np.copy(xy_list) + shrink_edge(xy_list, temp_new_xy_list, long_edge, r, theta, ratio) + shrink_edge(xy_list, temp_new_xy_list, long_edge + 2, r, theta, ratio) + # shrink two short edges + new_xy_list = np.copy(temp_new_xy_list) + shrink_edge(temp_new_xy_list, new_xy_list, short_edge, r, theta, ratio) + shrink_edge(temp_new_xy_list, new_xy_list, short_edge + 2, r, theta, ratio) + return temp_new_xy_list, new_xy_list, long_edge + + +def shrink_edge(xy_list, new_xy_list, edge, r, theta, ratio=cfg.shrink_ratio): + if ratio == 0.0: + return + start_point = edge + end_point = (edge + 1) % 4 + long_start_sign_x = np.sign( + xy_list[end_point, 0] - xy_list[start_point, 0]) + new_xy_list[start_point, 0] = \ + xy_list[start_point, 0] + \ + long_start_sign_x * ratio * r[start_point] * np.cos(theta[start_point]) + long_start_sign_y = np.sign( + xy_list[end_point, 1] - xy_list[start_point, 1]) + new_xy_list[start_point, 1] = \ + xy_list[start_point, 1] + \ + long_start_sign_y * ratio * r[start_point] * np.sin(theta[start_point]) + # long edge one, end point + long_end_sign_x = -1 * long_start_sign_x + new_xy_list[end_point, 0] = \ + xy_list[end_point, 0] + \ + long_end_sign_x * ratio * r[end_point] * np.cos(theta[start_point]) + long_end_sign_y = -1 * long_start_sign_y + new_xy_list[end_point, 1] = \ + xy_list[end_point, 1] + \ + long_end_sign_y * ratio * r[end_point] * np.sin(theta[start_point]) + + +def process_label(data_dir=cfg.data_dir): + with open(os.path.join(data_dir, cfg.val_fname), 'r') as f_val: + f_list = f_val.readlines() + with open(os.path.join(data_dir, cfg.train_fname), 'r') as f_train: + f_list.extend(f_train.readlines()) + for line, _ in zip(f_list, tqdm(range(len(f_list)))): + line_cols = str(line).strip().split(',') + img_name, width, height = \ + line_cols[0].strip(), int(line_cols[1].strip()), \ + int(line_cols[2].strip()) + gt = np.zeros((height // cfg.pixel_size, width // cfg.pixel_size, 7)) + train_label_dir = os.path.join(data_dir, cfg.train_label_dir_name) + xy_list_array = np.load(os.path.join(train_label_dir, + img_name[:-4] + '.npy')) + train_image_dir = os.path.join(data_dir, cfg.train_image_dir_name) + with Image.open(os.path.join(train_image_dir, img_name)) as im: + draw = ImageDraw.Draw(im) + for xy_list in xy_list_array: + _, shrink_xy_list, _ = shrink(xy_list, cfg.shrink_ratio) + shrink_1, _, long_edge = shrink(xy_list, cfg.shrink_side_ratio) + p_min = np.amin(shrink_xy_list, axis=0) + p_max = np.amax(shrink_xy_list, axis=0) + # floor of the float + ji_min = (p_min / cfg.pixel_size - 0.5).astype(int) - 1 + # +1 for ceil of the float and +1 for include the end + ji_max = (p_max / cfg.pixel_size - 0.5).astype(int) + 3 + imin = np.maximum(0, ji_min[1]) + imax = np.minimum(height // cfg.pixel_size, ji_max[1]) + jmin = np.maximum(0, ji_min[0]) + jmax = np.minimum(width // cfg.pixel_size, ji_max[0]) + for i in range(imin, imax): + for j in range(jmin, jmax): + px = (j + 0.5) * cfg.pixel_size + py = (i + 0.5) * cfg.pixel_size + if point_inside_of_quad(px, py, + shrink_xy_list, p_min, p_max): + gt[i, j, 0] = 1 + line_width, line_color = 1, 'red' + ith = point_inside_of_nth_quad(px, py, + xy_list, + shrink_1, + long_edge) + vs = [[[3, 0], [1, 2]], [[0, 1], [2, 3]]] + if ith in range(2): + gt[i, j, 1] = 1 + if ith == 0: + line_width, line_color = 2, 'yellow' + else: + line_width, line_color = 2, 'green' + gt[i, j, 2:3] = ith + gt[i, j, 3:5] = \ + xy_list[vs[long_edge][ith][0]] - [px, py] + gt[i, j, 5:] = \ + xy_list[vs[long_edge][ith][1]] - [px, py] + draw.line([(px - 0.5 * cfg.pixel_size, + py - 0.5 * cfg.pixel_size), + (px + 0.5 * cfg.pixel_size, + py - 0.5 * cfg.pixel_size), + (px + 0.5 * cfg.pixel_size, + py + 0.5 * cfg.pixel_size), + (px - 0.5 * cfg.pixel_size, + py + 0.5 * cfg.pixel_size), + (px - 0.5 * cfg.pixel_size, + py - 0.5 * cfg.pixel_size)], + width=line_width, fill=line_color) + act_image_dir = os.path.join(cfg.data_dir, + cfg.show_act_image_dir_name) + if cfg.draw_act_quad: + im.save(os.path.join(act_image_dir, img_name)) + train_label_dir = os.path.join(data_dir, cfg.train_label_dir_name) + np.save(os.path.join(train_label_dir, + img_name[:-4] + '_gt.npy'), gt) + + +if __name__ == '__main__': + process_label() diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/msame.sh b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/msame.sh new file mode 100644 index 000000000..fd27404fb --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/msame.sh @@ -0,0 +1,6 @@ +MODEL="/home/HwHiAiUser/11my310/ACL/modelom.om" +INPUT="/home/HwHiAiUser/11my310/image_test_bin/" +OUTPUT="/home/HwHiAiUser/11my310/image_test_output" +./msame --model $MODEL --input $INPUT --output $OUTPUT --outfmt BIN + + diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/network_add_bn.py b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/network_add_bn.py new file mode 100644 index 000000000..545c2d93c --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/network_add_bn.py @@ -0,0 +1,219 @@ +# coding=utf-8 +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import tensorflow as tf +from tensorflow.keras import backend as K +from tensorflow.keras.layers import BatchNormalization +# from tensorflow.keras.applications.vgg16 import VGG16 +from tensorflow.keras.layers import Concatenate, UpSampling2D +from tensorflow.keras.layers import Conv2D +from tensorflow.keras.layers import Dense +from tensorflow.keras.layers import Flatten +from tensorflow.keras.layers import GlobalAveragePooling2D +from tensorflow.keras.layers import GlobalMaxPooling2D +from tensorflow.keras.layers import Input +from tensorflow.keras.layers import MaxPooling2D +from tensorflow.keras.models import Model + +import cfg +from image_util import _obtain_input_shape, is_keras_tensor +from image_util import get_source_inputs + +""" +input_shape=(img.height, img.width, 3), height and width must scaled by 32. +So images's height and width need to be pre-processed to the nearest num that +scaled by 32.And the annotations xy need to be scaled by the same ratio +as height and width respectively. +""" + + +def VGG16(include_top=True, weights='imagenet', + input_tensor=None, input_shape=None, + pooling=None, + classes=1000): + # 确定正确的输入形状 + input_shape = _obtain_input_shape(input_shape, + default_size=224, + min_size=48, + data_format=K.image_data_format(), + require_flatten=include_top) + + if input_tensor is None: + img_input = Input(shape=input_shape) + else: + if not is_keras_tensor(input_tensor): + img_input = Input(tensor=input_tensor, shape=input_shape) + else: + img_input = input_tensor + # Block 1 + x = Conv2D(64, (3, 3), activation='relu', padding='same', name='block1_conv1')(img_input) + x = BatchNormalization(name='block1_batchnorm1')(x) + x = tf.nn.relu(x) + x = Conv2D(64, (3, 3), activation='relu', padding='same', name='block1_conv2')(x) + x = BatchNormalization(name='block1_batchnorm2')(x) + x = tf.nn.relu(x) + x = MaxPooling2D((2, 2), strides=(2, 2), name='block1_pool')(x) + + # Block 2 + x = Conv2D(128, (3, 3), activation='relu', padding='same', name='block2_conv1')(x) + x = BatchNormalization(name='block2_batchnorm1')(x) + x = tf.nn.relu(x) + x = Conv2D(128, (3, 3), activation='relu', padding='same', name='block2_conv2')(x) + x = BatchNormalization(name='block2_batchnorm2')(x) + x = tf.nn.relu(x) + x = MaxPooling2D((2, 2), strides=(2, 2), name='block2_pool')(x) + + # Block 3 + x = Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv1')(x) + x = BatchNormalization(name='block3_batchnorm1')(x) + x = tf.nn.relu(x) + x = Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv2')(x) + x = BatchNormalization(name='block3_batchnorm2')(x) + x = tf.nn.relu(x) + x = Conv2D(256, (3, 3), activation='relu', padding='same', name='block3_conv3')(x) + x = BatchNormalization(name='block3_batchnorm3')(x) + x = tf.nn.relu(x) + x = MaxPooling2D((2, 2), strides=(2, 2), name='block3_pool')(x) + + # Block 4 + x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv1')(x) + x = BatchNormalization(name='block4_batchnorm1')(x) + x = tf.nn.relu(x) + x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv2')(x) + x = BatchNormalization(name='block4_batchnorm2')(x) + x = tf.nn.relu(x) + x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block4_conv3')(x) + x = BatchNormalization(name='block4_batchnorm3')(x) + x = tf.nn.relu(x) + x = MaxPooling2D((2, 2), strides=(2, 2), name='block4_pool')(x) + + # Block 5 + x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv1')(x) + x = BatchNormalization(name='block5_batchnorm1')(x) + x = tf.nn.relu(x) + x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv2')(x) + x = BatchNormalization(name='block5_batchnorm2')(x) + x = tf.nn.relu(x) + x = Conv2D(512, (3, 3), activation='relu', padding='same', name='block5_conv3')(x) + x = BatchNormalization(name='block5_batchnorm3')(x) + x = tf.nn.relu(x) + x = MaxPooling2D((2, 2), strides=(2, 2), name='block5_pool')(x) + + # + if include_top: + # 分类 block + x = Flatten(name='flatten')(x) + x = Dense(4096, activation='relu', name='fc1')(x) + x = Dense(4096, activation='relu', name='fc2')(x) + x = Dense(classes, activation='softmax', name='predictions')(x) + else: + # 当 include_top为False时,设置pooling + if pooling == 'avg': + x = GlobalAveragePooling2D()(x) + elif pooling == 'max': + x = GlobalMaxPooling2D()(x) + + # 确保模型考虑了所有的input_tensor + if input_tensor is not None: + inputs = get_source_inputs(input_tensor) + else: + inputs = img_input + # 创建模型. + model = Model(inputs, x, name='vgg16') + + return model + + +class East: + + def __init__(self): + self.input_img = Input(name='input_img', + shape=(None, None, cfg.num_channels), + dtype='float32') + vgg16 = VGG16(input_tensor=self.input_img, + include_top=False) + if cfg.locked_layers: + # locked first two conv layers + locked_layers = [vgg16.get_layer('block1_conv1'), + vgg16.get_layer('block1_conv2')] + for layer in locked_layers: + layer.trainable = False + self.f = [vgg16.get_layer('block%d_pool' % i).output + for i in cfg.feature_layers_range] + self.f.insert(0, None) + self.diff = cfg.feature_layers_range[0] - cfg.feature_layers_num + + def g(self, i): + # i+diff in cfg.feature_layers_range + assert i + self.diff in cfg.feature_layers_range, \ + ('i=%d+diff=%d not in ' % (i, self.diff)) + \ + str(cfg.feature_layers_range) + if i == cfg.feature_layers_num: + bn = BatchNormalization()(self.h(i)) + return Conv2D(32, 3, activation='relu', padding='same')(bn) + else: + return UpSampling2D((2, 2))(self.h(i)) + + def h(self, i): + # i+diff in cfg.feature_layers_range + assert i + self.diff in cfg.feature_layers_range, \ + ('i=%d+diff=%d not in ' % (i, self.diff)) + \ + str(cfg.feature_layers_range) + if i == 1: + return self.f[i] + else: + concat = Concatenate(axis=-1)([self.g(i - 1), self.f[i]]) + bn1 = BatchNormalization()(concat) + conv_1 = Conv2D(128 // 2 ** (i - 2), 1, + activation='relu', padding='same', )(bn1) + bn2 = BatchNormalization()(conv_1) + conv_3 = Conv2D(128 // 2 ** (i - 2), 3, + activation='relu', padding='same', )(bn2) + return conv_3 + + def east_network(self): + before_output = self.g(cfg.feature_layers_num) + inside_score = Conv2D(1, 1, padding='same', name='inside_score' + )(before_output) + side_v_code = Conv2D(2, 1, padding='same', name='side_vertex_code' + )(before_output) + side_v_coord = Conv2D(4, 1, padding='same', name='side_vertex_coord' + )(before_output) + east_detect = Concatenate(axis=-1, + name='east_detect')([inside_score, + side_v_code, + side_v_coord]) + print('east_detect.shape:', east_detect.shape) + return Model(inputs=self.input_img, outputs=east_detect) + + +if __name__ == '__main__': + east = East() + east_network = east.east_network() + east_network.summary() diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/nms.py b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/nms.py new file mode 100644 index 000000000..1b7cbf9c7 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/nms.py @@ -0,0 +1,114 @@ +# coding=utf-8 +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np + +import cfg + + +def should_merge(region, i, j): + neighbor = {(i, j - 1)} + return not region.isdisjoint(neighbor) + + +def region_neighbor(region_set): + region_pixels = np.array(list(region_set)) + j_min = np.amin(region_pixels, axis=0)[1] - 1 + j_max = np.amax(region_pixels, axis=0)[1] + 1 + i_m = np.amin(region_pixels, axis=0)[0] + 1 + region_pixels[:, 0] += 1 + neighbor = {(region_pixels[n, 0], region_pixels[n, 1]) for n in + range(len(region_pixels))} + neighbor.add((i_m, j_min)) + neighbor.add((i_m, j_max)) + return neighbor + + +def region_group(region_list): + S = [i for i in range(len(region_list))] + D = [] + while len(S) > 0: + m = S.pop(0) + if len(S) == 0: + # S has only one element, put it to D + D.append([m]) + else: + D.append(rec_region_merge(region_list, m, S)) + return D + + +def rec_region_merge(region_list, m, S): + rows = [m] + tmp = [] + for n in S: + if not region_neighbor(region_list[m]).isdisjoint(region_list[n]) or \ + not region_neighbor(region_list[n]).isdisjoint(region_list[m]): + # 第m与n相交 + tmp.append(n) + for d in tmp: + S.remove(d) + for e in tmp: + rows.extend(rec_region_merge(region_list, e, S)) + return rows + + +def nms(predict, activation_pixels, threshold=cfg.side_vertex_pixel_threshold): + region_list = [] + for i, j in zip(activation_pixels[0], activation_pixels[1]): + merge = False + for k in range(len(region_list)): + if should_merge(region_list[k], i, j): + region_list[k].add((i, j)) + merge = True + # Fixme 重叠文本区域处理,存在和多个区域邻接的pixels,先都merge试试 + # break + if not merge: + region_list.append({(i, j)}) + D = region_group(region_list) + quad_list = np.zeros((len(D), 4, 2)) + score_list = np.zeros((len(D), 4)) + for group, g_th in zip(D, range(len(D))): + total_score = np.zeros((4, 2)) + for row in group: + for ij in region_list[row]: + score = predict[ij[0], ij[1], 1] + if score >= threshold: + ith_score = predict[ij[0], ij[1], 2:3] + if not (cfg.trunc_threshold <= ith_score < 1 - + cfg.trunc_threshold): + ith = int(np.around(ith_score)) + total_score[ith * 2:(ith + 1) * 2] += score + px = (ij[1] + 0.5) * cfg.pixel_size + py = (ij[0] + 0.5) * cfg.pixel_size + p_v = [px, py] + np.reshape(predict[ij[0], ij[1], 3:7], + (2, 2)) + quad_list[g_th, ith * 2:(ith + 1) * 2] += score * p_v + score_list[g_th] = total_score[:, 0] + quad_list[g_th] /= (total_score + cfg.epsilon) + return score_list, quad_list diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/postprocess.py b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/postprocess.py new file mode 100644 index 000000000..5281ef160 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/postprocess.py @@ -0,0 +1,178 @@ +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import os +import numpy as np +from PIL import Image, ImageDraw +from keras.preprocessing import image +from keras.applications.vgg16 import preprocess_input + +import cfg_bank as cfg +from label import point_inside_of_quad +from network_add_bn import East +from preprocess import resize_image +from nms import nms +from clock_wise import* + + +def sigmoid(x): + """`y = 1 / (1 + exp(-x))`""" + return 1 / (1 + np.exp(-x)) + +def cut_text_line(geo,scale_ratio_w, scale_ratio_h, imarry, img_path, s): + geo /= [scale_ratio_w, scale_ratio_h] + p_min = np.amin(geo, axis=0) + p_max = np.amax(geo, axis=0) + min_xy = p_min.astype(int) + max_xy = p_max.astype(int) + 2 + sub_im_arr = im_array[min_xy[1]:max_xy[1], min_xy[0]:max_xy[0], :].copy() + for m in range(min_xy[1], max_xy[1]): + for n in range(min_xy[1], max_xy[1]): + if not point_inside_of_quad(n, m, geo, p_min, p_max): + sub_im_arr[m - min_xy[1], n - min_xy[0], :] = 255 + sub_im = image.array_to_img(sub_im_arr, scale=False) + sub_im.save(img_path + '_subim%d.jpg' % s) + +def predict(east_detect, img_path, pixel_threshold, quiet=False): + img = image.load_img(img_path) + d_weight, d_height = resize_image(img, cfg.max_predict_img_size) + img = img.resize((d_weight, d_height), Image.NEAREST).convert('RGB') + img = image.img_to_array(img) + #img = img/255 + img = preprocess_input(img, mode='tf') + x = np.expand_dims(img, axis=0) + y =east_detect.predict(x) + + y = np.squeeze(y, axis=0) + y[:, :, :3] = sigmoid(y[:, :, :3]) + cond = np.greater_equal(y[:, :, 0], pixel_threshold) + activation_pixels = np.where(cond) + quad_scores, quad_after_nms = nms(y, activation_pixels) + with Image.open(img_path) as im: + im_array = image.img_to_array(im.convert('RGB')) + d_wight, d_height = resize_image(im, cfg.max_predict_img_size) + scale_ratio_w = d_wight / im.width + scale_ratio_h = d_height / im.height + im = im.resize((d_wight, d_height), Image.NEAREST).convert('RGB') + quad_im = im.copy() + draw = ImageDraw.Draw(im) + for i, j in zip(activation_pixels[0], activation_pixels[1]): + px = (j + 0.5) * cfg.pixel_size + py = (i + 0.5) * cfg.pixel_size + line_width, line_color = 1, 'red' + if y[i, j, 1] >= cfg.side_vertex_pixel_threshold: + if y[i, j, 2] < cfg.trunc_threshold: + line_width, line_color = 2, 'yellow' + elif y[i, j, 2] >= 1 - cfg.trunc_threshold: + line_width, line_color = 2, 'green' + draw.line([(px - 0.5 * cfg.pixel_size, py - 0.5 * cfg.pixel_size), + (px + 0.5 * cfg.pixel_size, py - 0.5 * cfg.pixel_size), + (px + 0.5 * cfg.pixel_size, py + 0.5 * cfg.pixel_size), + (px - 0.5 * cfg.pixel_size, py + 0.5 * cfg.pixel_size), + (px - 0.5 * cfg.pixel_size, py - 0.5 * cfg.pixel_size)], + width=line_width, fill=line_color) + im.save(img_path + '_act.jpg') + quad_draw = ImageDraw.Draw(quad_im) + txt_items = [] + for score, geo, s in zip(quad_scores, quad_after_nms, + range(len(quad_scores))): + if np.amin(score) > 0: + quad_draw.line([tuple(geo[0]), + tuple(geo[1]), + tuple(geo[2]), + tuple(geo[3]), + tuple(geo[0])], width=2, fill='red') + if cfg.predict_cut_text_line: + cut_text_line(geo, scale_ratio_w, scale_ratio_h, im_array, + img_path, s) + rescaled_geo = geo / [scale_ratio_w, scale_ratio_h] + rescaled_geo_list = np.reshape(rescaled_geo, (8,)).tolist() + txt_item = ','.join(map(str, rescaled_geo_list)) + txt_items.append(txt_item + '\n') + elif not quiet: + print('quad invalid with vertex num less then 4.') + quad_im.save(img_path + '_predict.jpg') + if cfg.predict_write2txt and len(txt_items) > 0: + with open(img_path[:-4] + '.txt', 'w') as f_txt: + f_txt.writelines(txt_items) + +def predict_txt(east_detect, img_path, txt_path, pixel_threshold, quiet=False): + img = image.load_img(img_path) + d_weight, d_height = cfg.max_predict_img_size, cfg.max_predict_img_size + scale_ratio_w = d_weight / img.width + scale_ratio_h = d_height / img.height + img = img.resize((d_weight, d_height), Image.NEAREST).convert('RGB') + img = image.img_to_array(img) + img = preprocess_input(img, mode='tf') + x = np.expand_dims(img, axis=0) + y =east_detect.predict(x) + y = np.squeeze(y, axis=0) + y[:, :, :3] = sigmoid(y[:, :, :3]) + cond = np.greater_equal(y[:, :, 0], pixel_threshold) + activation_pixels = np.where(cond) + quad_scores, quad_after_nms = nms(y, activation_pixels) + + txt_items = [] + for score, geo in zip(quad_scores, quad_after_nms): + if np.amin(score) > 0: + rescaled_geo = geo / [scale_ratio_w, scale_ratio_h] + rescaled_geo = np.round(rescaled_geo,decimals=0).astype(np.int32) + rescaled_geo = order_points_tuple(rescaled_geo) + rescaled_geo_list = np.reshape(rescaled_geo, (8,)).tolist() + txt_item = ','.join(map(str, rescaled_geo_list)) + txt_items.append(txt_item + '\n') + elif not quiet: + print('quad invalid with vertex num less than 4.') + if cfg.predict_write2txt and len(txt_items) > 0: + with open(txt_path, 'w') as f_txt: + f_txt.writelines(txt_items) + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument('--path', '-p', + default='demo/012.png', + help='image path') + parser.add_argument('--threshold', '-t', + default=cfg.pixel_threshold, + help='pixel activation threshold') + return parser.parse_args() + + +if __name__=='__main__': + args = parse_args() + img_path = args.path + threshold = float(args.threshold) + print(img_path, threshold) + + east = East() + east_detect = east.east_network() + east_detect.load_weights(cfg.saved_model_weights_file_path) + predict(east_detect, img_path, threshold) + east_detect.save("saved_model/AdvancedEast_model.h5") + \ No newline at end of file diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/predict.py b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/predict.py new file mode 100644 index 000000000..4fcc92e45 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/predict.py @@ -0,0 +1,50 @@ +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import os +from tqdm import tqdm +from network_add_bn import East +from postprocess import predict_txt +import cfg + +if __name__=='__main__': + east = East() + east_detect = east.east_network() + east_detect.load_weights("./model.h5") + image_test_dir = os.path.join(cfg.data_dir, 'rename_images/') + txt_test_dir = os.path.join(cfg.data_dir, 'txt_test') + test_imgname_list = os.listdir(image_test_dir) + test_imgname_list = sorted(test_imgname_list) + print('found %d test images.' % len(test_imgname_list)) + for test_img_name, _ in zip(test_imgname_list, + tqdm(range(len(test_imgname_list)))): + img_path = os.path.join(image_test_dir, test_img_name) + txt_path = os.path.join(txt_test_dir, 'res_'+test_img_name[:-4] + '.txt') + predict_txt(east_detect, img_path, txt_path, cfg.pixel_threshold, True) + diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/preprocess.py b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/preprocess.py new file mode 100644 index 000000000..b83c589da --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/preprocess.py @@ -0,0 +1,208 @@ +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import numpy as np +from PIL import Image, ImageDraw +import os +import random +from tqdm import tqdm + +import cfg +from label import shrink + + +def batch_reorder_vertexes(xy_list_array): + reorder_xy_list_array = np.zeros_like(xy_list_array) + for xy_list, i in zip(xy_list_array, range(len(xy_list_array))): + reorder_xy_list_array[i] = reorder_vertexes(xy_list) + return reorder_xy_list_array + + +def reorder_vertexes(xy_list): + reorder_xy_list = np.zeros_like(xy_list) + # determine the first point with the smallest x, + # if two has same x, choose that with smallest y, + ordered = np.argsort(xy_list, axis=0) + xmin1_index = ordered[0, 0] + xmin2_index = ordered[1, 0] + if xy_list[xmin1_index, 0] == xy_list[xmin2_index, 0]: + if xy_list[xmin1_index, 1] <= xy_list[xmin2_index, 1]: + reorder_xy_list[0] = xy_list[xmin1_index] + first_v = xmin1_index + else: + reorder_xy_list[0] = xy_list[xmin2_index] + first_v = xmin2_index + else: + reorder_xy_list[0] = xy_list[xmin1_index] + first_v = xmin1_index + # connect the first point to others, the third point on the other side of + # the line with the middle slope + others = list(range(4)) + others.remove(first_v) + k = np.zeros((len(others),)) + for index, i in zip(others, range(len(others))): + k[i] = (xy_list[index, 1] - xy_list[first_v, 1]) \ + / (xy_list[index, 0] - xy_list[first_v, 0] + cfg.epsilon) + k_mid = np.argsort(k)[1] + third_v = others[k_mid] + reorder_xy_list[2] = xy_list[third_v] + # determine the second point which on the bigger side of the middle line + others.remove(third_v) + b_mid = xy_list[first_v, 1] - k[k_mid] * xy_list[first_v, 0] + second_v, fourth_v = 0, 0 + for index, i in zip(others, range(len(others))): + # delta = y - (k * x + b) + delta_y = xy_list[index, 1] - (k[k_mid] * xy_list[index, 0] + b_mid) + if delta_y > 0: + second_v = index + else: + fourth_v = index + reorder_xy_list[1] = xy_list[second_v] + reorder_xy_list[3] = xy_list[fourth_v] + # compare slope of 13 and 24, determine the final order + k13 = k[k_mid] + k24 = (xy_list[second_v, 1] - xy_list[fourth_v, 1]) / ( + xy_list[second_v, 0] - xy_list[fourth_v, 0] + cfg.epsilon) + if k13 < k24: + tmp_x, tmp_y = reorder_xy_list[3, 0], reorder_xy_list[3, 1] + for i in range(2, -1, -1): + reorder_xy_list[i + 1] = reorder_xy_list[i] + reorder_xy_list[0, 0], reorder_xy_list[0, 1] = tmp_x, tmp_y + return reorder_xy_list + + +def resize_image(im, max_img_size=cfg.max_train_img_size): + im_width = np.minimum(im.width, max_img_size) + if im_width == max_img_size < im.width: + im_height = int((im_width / im.width) * im.height) + else: + im_height = im.height + o_height = np.minimum(im_height, max_img_size) + if o_height == max_img_size < im_height: + o_width = int((o_height / im_height) * im_width) + else: + o_width = im_width + d_wight = o_width - (o_width % 32) + d_height = o_height - (o_height % 32) + return d_wight, d_height + + +def preprocess(): + data_dir = cfg.data_dir + origin_image_dir = os.path.join(data_dir, cfg.origin_image_dir_name) + origin_txt_dir = os.path.join(data_dir, cfg.origin_txt_dir_name) + train_image_dir = os.path.join(data_dir, cfg.train_image_dir_name) + train_label_dir = os.path.join(data_dir, cfg.train_label_dir_name) + if not os.path.exists(train_image_dir): + os.mkdir(train_image_dir) + if not os.path.exists(train_label_dir): + os.mkdir(train_label_dir) + draw_gt_quad = cfg.draw_gt_quad + show_gt_image_dir = os.path.join(data_dir, cfg.show_gt_image_dir_name) + if not os.path.exists(show_gt_image_dir): + os.mkdir(show_gt_image_dir) + show_act_image_dir = os.path.join(cfg.data_dir, cfg.show_act_image_dir_name) + if not os.path.exists(show_act_image_dir): + os.mkdir(show_act_image_dir) + + o_img_list = os.listdir(origin_image_dir) + print('found %d origin images.' % len(o_img_list)) + train_val_set = [] + for o_img_fname, _ in zip(o_img_list, tqdm(range(len(o_img_list)))): + with Image.open(os.path.join(origin_image_dir, o_img_fname)) as im: + # d_wight, d_height = resize_image(im) + d_wight, d_height = cfg.max_train_img_size, cfg.max_train_img_size + scale_ratio_w = d_wight / im.width + scale_ratio_h = d_height / im.height + im = im.resize((d_wight, d_height), Image.NEAREST).convert('RGB') + show_gt_im = im.copy() + # draw on the img + draw = ImageDraw.Draw(show_gt_im) + with open(os.path.join(origin_txt_dir, + o_img_fname[:-4] + '.txt'), 'r', encoding='UTF-8') as f: + anno_list = f.readlines() + xy_list_array = np.zeros((len(anno_list), 4, 2)) + for anno, i in zip(anno_list, range(len(anno_list))): + anno_colums = anno.strip().split(',') + anno_array = np.array(anno_colums) + xy_list = np.reshape(anno_array[:8].astype(float), (4, 2)) + xy_list[:, 0] = xy_list[:, 0] * scale_ratio_w + xy_list[:, 1] = xy_list[:, 1] * scale_ratio_h + xy_list = reorder_vertexes(xy_list) + xy_list_array[i] = xy_list + _, shrink_xy_list, _ = shrink(xy_list, cfg.shrink_ratio) + shrink_1, _, long_edge = shrink(xy_list, cfg.shrink_side_ratio) + if draw_gt_quad: + draw.line([tuple(xy_list[0]), tuple(xy_list[1]), + tuple(xy_list[2]), tuple(xy_list[3]), + tuple(xy_list[0]) + ], + width=2, fill='green') + draw.line([tuple(shrink_xy_list[0]), + tuple(shrink_xy_list[1]), + tuple(shrink_xy_list[2]), + tuple(shrink_xy_list[3]), + tuple(shrink_xy_list[0]) + ], + width=2, fill='blue') + vs = [[[0, 0, 3, 3, 0], [1, 1, 2, 2, 1]], + [[0, 0, 1, 1, 0], [2, 2, 3, 3, 2]]] + for q_th in range(2): + draw.line([tuple(xy_list[vs[long_edge][q_th][0]]), + tuple(shrink_1[vs[long_edge][q_th][1]]), + tuple(shrink_1[vs[long_edge][q_th][2]]), + tuple(xy_list[vs[long_edge][q_th][3]]), + tuple(xy_list[vs[long_edge][q_th][4]])], + width=3, fill='yellow') + if cfg.gen_origin_img: + im.save(os.path.join(train_image_dir, o_img_fname)) + np.save(os.path.join( + train_label_dir, + o_img_fname[:-4] + '.npy'), + xy_list_array) + if draw_gt_quad: + show_gt_im.save(os.path.join(show_gt_image_dir, o_img_fname)) + train_val_set.append('{},{},{}\n'.format(o_img_fname, + d_wight, + d_height)) + + train_img_list = os.listdir(train_image_dir) + print('found %d train images.' % len(train_img_list)) + train_label_list = os.listdir(train_label_dir) + print('found %d train labels.' % len(train_label_list)) + + random.shuffle(train_val_set) + val_count = int(cfg.validation_split_ratio * len(train_val_set)) + with open(os.path.join(data_dir, cfg.val_fname), 'w') as f_val: + f_val.writelines(train_val_set[:val_count]) + with open(os.path.join(data_dir, cfg.train_fname), 'w') as f_train: + f_train.writelines(train_val_set[val_count:]) + + +if __name__ == '__main__': + preprocess() -- Gitee From 363978e0bf4c5009b48a15b1249020ef804b3442 Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 06:57:30 +0000 Subject: [PATCH 07/22] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20AC?= =?UTF-8?q?L=5FTensorFlow/built-in/cv/Advanced=5FEast=5Ffor=5FACL/script/.?= =?UTF-8?q?keep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/.keep diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/.keep b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/script/.keep deleted file mode 100644 index e69de29bb..000000000 -- Gitee From f1b6a512064331a6cc86b34c80d938bbbd6ebf9b Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 06:57:50 +0000 Subject: [PATCH 08/22] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20AC?= =?UTF-8?q?L=5FTensorFlow/built-in/cv/Advanced=5FEast=5Ffor=5FACL/Benchmar?= =?UTF-8?q?k/.keep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/.keep diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/.keep b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/.keep deleted file mode 100644 index e69de29bb..000000000 -- Gitee From fb8530e27b28dbdf25bebc785ecda17359857fc6 Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 06:58:35 +0000 Subject: [PATCH 09/22] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20inc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../built-in/cv/Advanced_East_for_ACL/Benchmark/inc/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/.keep diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/.keep b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/.keep new file mode 100644 index 000000000..e69de29bb -- Gitee From 6e413a5e170f7a282ce605b7ecb3fcd2eb7743e6 Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 06:58:59 +0000 Subject: [PATCH 10/22] update. --- .../Benchmark/inc/infer_engine.h | 29 +++ .../Benchmark/inc/post_process.h | 6 + .../Benchmark/inc/util.h | 168 ++++++++++++++++++ 3 files changed, 203 insertions(+) create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/infer_engine.h create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/post_process.h create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/util.h diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/infer_engine.h b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/infer_engine.h new file mode 100644 index 000000000..18894ccfa --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/infer_engine.h @@ -0,0 +1,29 @@ +#ifndef BENCHMARK_INFER_ENGINE_H +#define BENCHMARK_INFER_ENGINE_H +#include "util.h" +#include "acl/acl_base.h" +#include "post_process.h" +#include +#include +#include +#include +#include +#include "acl/acl_mdl.h" +#include +#include + +aclError InitContext(const char* configPath = ""); +aclError UnInitContext(); +aclError LoadModel(); +aclError InitInput(std::vector files); +aclError Inference(); +aclError PostProcess(); +aclError DvppSetup(); +aclError DvppInitInput(std::vector files); +aclError UnloadModel(); +void getImgResizeShape(); +aclError GetImageSize(std::string file); + + + +#endif diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/post_process.h b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/post_process.h new file mode 100644 index 000000000..137831288 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/post_process.h @@ -0,0 +1,6 @@ +#ifndef BENCHMARK_POST_PROCESS_H +#define BENCHMARK_POST_PROCESS_H +#include "util.h" +aclError SaveBinPostprocess(); + +#endif diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/util.h b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/util.h new file mode 100644 index 000000000..54c470b74 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/util.h @@ -0,0 +1,168 @@ +#ifndef BENCHMARK_UTIL_H +#define BENCHMARK_UTIL_H +#include +#include +#include +#include "acl/acl_base.h" +#include "acl/acl_mdl.h" +#include "acl/acl_rt.h" +#include "acl/acl_rt.h" +#include "acl/ops/acl_dvpp.h" +#include +#include +#include +#include +#include +#include + +// self defined problem code. +const int ACL_ERROR_PATH_INVALID = 101; +const int ACL_ERROR_CREATE_DATASET_FAILED = 102; +const int ACL_ERROR_PARSE_PARAM_FAILED = 103; +const int ACL_ERROR_DVPP_ERROR = 104; +const int ACL_ERROR_OTHERS = 255; +#define MODEL_INPUT_NUM_MAX (4) +#define MODEL_INPUT_OUTPUT_NUM_MAX (16) + +#define LOG(fmt, args...) \ + do { \ + printf(fmt, ##args); \ + } while(0) + + +#define START_PROC \ + struct timeval start, end; \ + long long time_use; \ + do { \ + gettimeofday(&start, NULL); \ + } while (0); + + +#define END_PROC \ + do { \ + gettimeofday(&end, NULL); \ + time_use = (end.tv_sec-start.tv_sec)*1000000+(end.tv_usec-start.tv_usec); \ + LOG("time use: %lld us\n", time_use); \ + } while (0); + + +#define CHECK_ACL_RET(msg, ret) \ + if (ret != ACL_ERROR_NONE) { \ + std::cout << msg << ", ret "<< ret << std::endl; \ + return ret; \ + } + + +#define CHECK_WITH_RET(condition, ret, msg) \ + if(!(condition)) { \ + std::cout << msg << ", ret "<< ret << std::endl; \ + return ret; \ + } + + +#define CHECK_RET(ret) \ + if(ret != ACL_ERROR_NONE) { \ + return ret; \ + } + + + + + + + +bool FolderExists(std::string foldname); + +bool FileExists(std::string filename); + +char* ReadBinFile(std::string fileName, uint32_t& fileSize); + +aclError GetFiles(std::string path, std::vector& files); + +aclError FreeDevMemory(aclmdlDataset* dataset); + +aclError DestroyDatasetResurce(aclmdlDataset* dataset, uint32_t flag); + + +struct DvppConfig { + uint32_t resizedWidth; + uint32_t resizedHeight; + std::unordered_map> imgSizes; +}; + + + +struct ModelInfo +{ + aclFormat Format; + const char* Name; + size_t size; + size_t dimCount; + int64_t dims[ACL_MAX_DIM_CNT]; + aclDataType Type; +}; + +struct Config { + std::string om; + std::string dataDir; + std::string outDir; + DvppConfig dvppConfig; + bool useDvpp; + size_t batchSize; + ModelInfo inputInfo[MODEL_INPUT_OUTPUT_NUM_MAX]; + ModelInfo outputInfo[MODEL_INPUT_OUTPUT_NUM_MAX]; + size_t inputNum; + size_t outputNum; + aclmdlDesc* modelDesc; + uint32_t modelId; + aclrtContext context; + char* modelData_ptr; + void* devMem_ptr; + void* weightMem_ptr; + std::string imgType; + std::string modelType; + uint32_t deviceId; + uint32_t loopNum; + std::string framework; + int64_t curOutputSize[MODEL_INPUT_OUTPUT_NUM_MAX]; + Config() + { + om = ""; + dataDir = ""; + batchSize = 0; + useDvpp = 0; + inputNum = 0; + outputNum = 0; + modelDesc = nullptr; + modelId = 0; + context = nullptr; + imgType = ""; + modelType = ""; + deviceId = 0; + loopNum = 1; + framework = "caffe"; + outDir = "../../results"; + modelData_ptr = nullptr; + devMem_ptr = nullptr; + weightMem_ptr = nullptr; + } +}; + + + +struct Resnet50Result { + int top1; + int top5; + int total; + std::unordered_map cmp; + Resnet50Result(): top1(0), top5(0), total(0) {}; +}; + +struct DataFrame { + std::vector fileNames; + aclmdlDataset* dataset; +}; + + + +#endif -- Gitee From 94ef0113143aa32ffa10de0e09a0ddd96296be8e Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 06:59:11 +0000 Subject: [PATCH 11/22] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20AC?= =?UTF-8?q?L=5FTensorFlow/built-in/cv/Advanced=5FEast=5Ffor=5FACL/Benchmar?= =?UTF-8?q?k/inc/.keep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../built-in/cv/Advanced_East_for_ACL/Benchmark/inc/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/.keep diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/.keep b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/.keep deleted file mode 100644 index e69de29bb..000000000 -- Gitee From c69da878909845979dac1958e12cc01c31cbac2f Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 06:59:33 +0000 Subject: [PATCH 12/22] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20gflags?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/.keep diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/.keep b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/.keep new file mode 100644 index 000000000..e69de29bb -- Gitee From abafa4327fa24dac3d24a3dad3af651422f85452 Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 06:59:51 +0000 Subject: [PATCH 13/22] update. --- .../Benchmark/inc/gflags/defines.h | 48 ++ .../Benchmark/inc/gflags/gflags.h | 627 ++++++++++++++++++ .../Benchmark/inc/gflags/gflags_completions.h | 121 ++++ .../Benchmark/inc/gflags/gflags_declare.h | 156 +++++ .../Benchmark/inc/gflags/gflags_gflags.h | 102 +++ 5 files changed, 1054 insertions(+) create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/defines.h create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/gflags.h create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/gflags_completions.h create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/gflags_declare.h create mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/gflags_gflags.h diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/defines.h b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/defines.h new file mode 100644 index 000000000..f0be3dcb4 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/defines.h @@ -0,0 +1,48 @@ +/* Generated from defines.h.in during build configuration using CMake. */ + +// Note: This header file is only used internally. It is not part of public interface! +// Any cmakedefine is defined using the -D flag instead when Bazel is used. +// For Bazel, this file is thus not used to avoid a private file in $(GENDIR). + +#ifndef GFLAGS_DEFINES_H_ +#define GFLAGS_DEFINES_H_ + + +// Define if you build this library for a MS Windows OS. +/* #undef OS_WINDOWS */ + +// Define if you have the header file. +#define HAVE_STDINT_H + +// Define if you have the header file. +#define HAVE_SYS_TYPES_H + +// Define if you have the header file. +#define HAVE_INTTYPES_H + +// Define if you have the header file. +#define HAVE_SYS_STAT_H + +// Define if you have the header file. +#define HAVE_UNISTD_H + +// Define if you have the header file. +#define HAVE_FNMATCH_H + +// Define if you have the header file (Windows 2000/XP). +/* #undef HAVE_SHLWAPI_H */ + +// Define if you have the strtoll function. +#define HAVE_STRTOLL + +// Define if you have the strtoq function. +/* #undef HAVE_STRTOQ */ + +// Define if you have the header file. +#define HAVE_PTHREAD + +// Define if your pthread library defines the type pthread_rwlock_t +#define HAVE_RWLOCK + + +#endif // GFLAGS_DEFINES_H_ diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/gflags.h b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/gflags.h new file mode 100644 index 000000000..66bbf1338 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/gflags.h @@ -0,0 +1,627 @@ +// Copyright (c) 2006, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// --- +// Revamped and reorganized by Craig Silverstein +// +// This is the file that should be included by any file which declares +// or defines a command line flag or wants to parse command line flags +// or print a program usage message (which will include information about +// flags). Executive summary, in the form of an example foo.cc file: +// +// #include "foo.h" // foo.h has a line "DECLARE_int32(start);" +// #include "validators.h" // hypothetical file defining ValidateIsFile() +// +// DEFINE_int32(end, 1000, "The last record to read"); +// +// DEFINE_string(filename, "my_file.txt", "The file to read"); +// // Crash if the specified file does not exist. +// static bool dummy = RegisterFlagValidator(&FLAGS_filename, +// &ValidateIsFile); +// +// DECLARE_bool(verbose); // some other file has a DEFINE_bool(verbose, ...) +// +// void MyFunc() { +// if (FLAGS_verbose) printf("Records %d-%d\n", FLAGS_start, FLAGS_end); +// } +// +// Then, at the command-line: +// ./foo --noverbose --start=5 --end=100 +// +// For more details, see +// doc/gflags.html +// +// --- A note about thread-safety: +// +// We describe many functions in this routine as being thread-hostile, +// thread-compatible, or thread-safe. Here are the meanings we use: +// +// thread-safe: it is safe for multiple threads to call this routine +// (or, when referring to a class, methods of this class) +// concurrently. +// thread-hostile: it is not safe for multiple threads to call this +// routine (or methods of this class) concurrently. In gflags, +// most thread-hostile routines are intended to be called early in, +// or even before, main() -- that is, before threads are spawned. +// thread-compatible: it is safe for multiple threads to read from +// this variable (when applied to variables), or to call const +// methods of this class (when applied to classes), as long as no +// other thread is writing to the variable or calling non-const +// methods of this class. + +#ifndef GFLAGS_GFLAGS_H_ +#define GFLAGS_GFLAGS_H_ + +#include +#include + +#include "gflags/gflags_declare.h" // IWYU pragma: export + + +// We always want to export variables defined in user code +#ifndef GFLAGS_DLL_DEFINE_FLAG +# if GFLAGS_IS_A_DLL && defined(_MSC_VER) +# define GFLAGS_DLL_DEFINE_FLAG __declspec(dllexport) +# else +# define GFLAGS_DLL_DEFINE_FLAG +# endif +#endif + + +namespace GFLAGS_NAMESPACE { + + +// -------------------------------------------------------------------- +// To actually define a flag in a file, use DEFINE_bool, +// DEFINE_string, etc. at the bottom of this file. You may also find +// it useful to register a validator with the flag. This ensures that +// when the flag is parsed from the commandline, or is later set via +// SetCommandLineOption, we call the validation function. It is _not_ +// called when you assign the value to the flag directly using the = operator. +// +// The validation function should return true if the flag value is valid, and +// false otherwise. If the function returns false for the new setting of the +// flag, the flag will retain its current value. If it returns false for the +// default value, ParseCommandLineFlags() will die. +// +// This function is safe to call at global construct time (as in the +// example below). +// +// Example use: +// static bool ValidatePort(const char* flagname, int32 value) { +// if (value > 0 && value < 32768) // value is ok +// return true; +// printf("Invalid value for --%s: %d\n", flagname, (int)value); +// return false; +// } +// DEFINE_int32(port, 0, "What port to listen on"); +// static bool dummy = RegisterFlagValidator(&FLAGS_port, &ValidatePort); + +// Returns true if successfully registered, false if not (because the +// first argument doesn't point to a command-line flag, or because a +// validator is already registered for this flag). +extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const bool* flag, bool (*validate_fn)(const char*, bool)); +extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const int32* flag, bool (*validate_fn)(const char*, int32)); +extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const uint32* flag, bool (*validate_fn)(const char*, uint32)); +extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const int64* flag, bool (*validate_fn)(const char*, int64)); +extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const uint64* flag, bool (*validate_fn)(const char*, uint64)); +extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const double* flag, bool (*validate_fn)(const char*, double)); +extern GFLAGS_DLL_DECL bool RegisterFlagValidator(const std::string* flag, bool (*validate_fn)(const char*, const std::string&)); + +// Convenience macro for the registration of a flag validator +#define DEFINE_validator(name, validator) \ + static const bool name##_validator_registered = \ + GFLAGS_NAMESPACE::RegisterFlagValidator(&FLAGS_##name, validator) + + +// -------------------------------------------------------------------- +// These methods are the best way to get access to info about the +// list of commandline flags. Note that these routines are pretty slow. +// GetAllFlags: mostly-complete info about the list, sorted by file. +// ShowUsageWithFlags: pretty-prints the list to stdout (what --help does) +// ShowUsageWithFlagsRestrict: limit to filenames with restrict as a substr +// +// In addition to accessing flags, you can also access argv[0] (the program +// name) and argv (the entire commandline), which we sock away a copy of. +// These variables are static, so you should only set them once. +// +// No need to export this data only structure from DLL, avoiding VS warning 4251. +struct CommandLineFlagInfo { + std::string name; // the name of the flag + std::string type; // the type of the flag: int32, etc + std::string description; // the "help text" associated with the flag + std::string current_value; // the current value, as a string + std::string default_value; // the default value, as a string + std::string filename; // 'cleaned' version of filename holding the flag + bool has_validator_fn; // true if RegisterFlagValidator called on this flag + bool is_default; // true if the flag has the default value and + // has not been set explicitly from the cmdline + // or via SetCommandLineOption + const void* flag_ptr; // pointer to the flag's current value (i.e. FLAGS_foo) +}; + +// Using this inside of a validator is a recipe for a deadlock. +// TODO(user) Fix locking when validators are running, to make it safe to +// call validators during ParseAllFlags. +// Also make sure then to uncomment the corresponding unit test in +// gflags_unittest.sh +extern GFLAGS_DLL_DECL void GetAllFlags(std::vector* OUTPUT); +// These two are actually defined in gflags_reporting.cc. +extern GFLAGS_DLL_DECL void ShowUsageWithFlags(const char *argv0); // what --help does +extern GFLAGS_DLL_DECL void ShowUsageWithFlagsRestrict(const char *argv0, const char *restrict); + +// Create a descriptive string for a flag. +// Goes to some trouble to make pretty line breaks. +extern GFLAGS_DLL_DECL std::string DescribeOneFlag(const CommandLineFlagInfo& flag); + +// Thread-hostile; meant to be called before any threads are spawned. +extern GFLAGS_DLL_DECL void SetArgv(int argc, const char** argv); + +// The following functions are thread-safe as long as SetArgv() is +// only called before any threads start. +extern GFLAGS_DLL_DECL const std::vector& GetArgvs(); +extern GFLAGS_DLL_DECL const char* GetArgv(); // all of argv as a string +extern GFLAGS_DLL_DECL const char* GetArgv0(); // only argv0 +extern GFLAGS_DLL_DECL uint32 GetArgvSum(); // simple checksum of argv +extern GFLAGS_DLL_DECL const char* ProgramInvocationName(); // argv0, or "UNKNOWN" if not set +extern GFLAGS_DLL_DECL const char* ProgramInvocationShortName(); // basename(argv0) + +// ProgramUsage() is thread-safe as long as SetUsageMessage() is only +// called before any threads start. +extern GFLAGS_DLL_DECL const char* ProgramUsage(); // string set by SetUsageMessage() + +// VersionString() is thread-safe as long as SetVersionString() is only +// called before any threads start. +extern GFLAGS_DLL_DECL const char* VersionString(); // string set by SetVersionString() + + + +// -------------------------------------------------------------------- +// Normally you access commandline flags by just saying "if (FLAGS_foo)" +// or whatever, and set them by calling "FLAGS_foo = bar" (or, more +// commonly, via the DEFINE_foo macro). But if you need a bit more +// control, we have programmatic ways to get/set the flags as well. +// These programmatic ways to access flags are thread-safe, but direct +// access is only thread-compatible. + +// Return true iff the flagname was found. +// OUTPUT is set to the flag's value, or unchanged if we return false. +extern GFLAGS_DLL_DECL bool GetCommandLineOption(const char* name, std::string* OUTPUT); + +// Return true iff the flagname was found. OUTPUT is set to the flag's +// CommandLineFlagInfo or unchanged if we return false. +extern GFLAGS_DLL_DECL bool GetCommandLineFlagInfo(const char* name, CommandLineFlagInfo* OUTPUT); + +// Return the CommandLineFlagInfo of the flagname. exit() if name not found. +// Example usage, to check if a flag's value is currently the default value: +// if (GetCommandLineFlagInfoOrDie("foo").is_default) ... +extern GFLAGS_DLL_DECL CommandLineFlagInfo GetCommandLineFlagInfoOrDie(const char* name); + +enum GFLAGS_DLL_DECL FlagSettingMode { + // update the flag's value (can call this multiple times). + SET_FLAGS_VALUE, + // update the flag's value, but *only if* it has not yet been updated + // with SET_FLAGS_VALUE, SET_FLAG_IF_DEFAULT, or "FLAGS_xxx = nondef". + SET_FLAG_IF_DEFAULT, + // set the flag's default value to this. If the flag has not yet updated + // yet (via SET_FLAGS_VALUE, SET_FLAG_IF_DEFAULT, or "FLAGS_xxx = nondef") + // change the flag's current value to the new default value as well. + SET_FLAGS_DEFAULT +}; + +// Set a particular flag ("command line option"). Returns a string +// describing the new value that the option has been set to. The +// return value API is not well-specified, so basically just depend on +// it to be empty if the setting failed for some reason -- the name is +// not a valid flag name, or the value is not a valid value -- and +// non-empty else. + +// SetCommandLineOption uses set_mode == SET_FLAGS_VALUE (the common case) +extern GFLAGS_DLL_DECL std::string SetCommandLineOption (const char* name, const char* value); +extern GFLAGS_DLL_DECL std::string SetCommandLineOptionWithMode(const char* name, const char* value, FlagSettingMode set_mode); + + +// -------------------------------------------------------------------- +// Saves the states (value, default value, whether the user has set +// the flag, registered validators, etc) of all flags, and restores +// them when the FlagSaver is destroyed. This is very useful in +// tests, say, when you want to let your tests change the flags, but +// make sure that they get reverted to the original states when your +// test is complete. +// +// Example usage: +// void TestFoo() { +// FlagSaver s1; +// FLAG_foo = false; +// FLAG_bar = "some value"; +// +// // test happens here. You can return at any time +// // without worrying about restoring the FLAG values. +// } +// +// Note: This class is marked with GFLAGS_ATTRIBUTE_UNUSED because all +// the work is done in the constructor and destructor, so in the standard +// usage example above, the compiler would complain that it's an +// unused variable. +// +// This class is thread-safe. However, its destructor writes to +// exactly the set of flags that have changed value during its +// lifetime, so concurrent _direct_ access to those flags +// (i.e. FLAGS_foo instead of {Get,Set}CommandLineOption()) is unsafe. + +class GFLAGS_DLL_DECL FlagSaver { + public: + FlagSaver(); + ~FlagSaver(); + + private: + class FlagSaverImpl* impl_; // we use pimpl here to keep API steady + + FlagSaver(const FlagSaver&); // no copying! + void operator=(const FlagSaver&); +}__attribute((unused)); + +// -------------------------------------------------------------------- +// Some deprecated or hopefully-soon-to-be-deprecated functions. + +// This is often used for logging. TODO(csilvers): figure out a better way +extern GFLAGS_DLL_DECL std::string CommandlineFlagsIntoString(); +// Usually where this is used, a FlagSaver should be used instead. +extern GFLAGS_DLL_DECL +bool ReadFlagsFromString(const std::string& flagfilecontents, + const char* prog_name, + bool errors_are_fatal); // uses SET_FLAGS_VALUE + +// These let you manually implement --flagfile functionality. +// DEPRECATED. +extern GFLAGS_DLL_DECL bool AppendFlagsIntoFile(const std::string& filename, const char* prog_name); +extern GFLAGS_DLL_DECL bool ReadFromFlagsFile(const std::string& filename, const char* prog_name, bool errors_are_fatal); // uses SET_FLAGS_VALUE + + +// -------------------------------------------------------------------- +// Useful routines for initializing flags from the environment. +// In each case, if 'varname' does not exist in the environment +// return defval. If 'varname' does exist but is not valid +// (e.g., not a number for an int32 flag), abort with an error. +// Otherwise, return the value. NOTE: for booleans, for true use +// 't' or 'T' or 'true' or '1', for false 'f' or 'F' or 'false' or '0'. + +extern GFLAGS_DLL_DECL bool BoolFromEnv(const char *varname, bool defval); +extern GFLAGS_DLL_DECL int32 Int32FromEnv(const char *varname, int32 defval); +extern GFLAGS_DLL_DECL uint32 Uint32FromEnv(const char *varname, uint32 defval); +extern GFLAGS_DLL_DECL int64 Int64FromEnv(const char *varname, int64 defval); +extern GFLAGS_DLL_DECL uint64 Uint64FromEnv(const char *varname, uint64 defval); +extern GFLAGS_DLL_DECL double DoubleFromEnv(const char *varname, double defval); +extern GFLAGS_DLL_DECL const char *StringFromEnv(const char *varname, const char *defval); + + +// -------------------------------------------------------------------- +// The next two functions parse gflags from main(): + +// Set the "usage" message for this program. For example: +// string usage("This program does nothing. Sample usage:\n"); +// usage += argv[0] + " "; +// SetUsageMessage(usage); +// Do not include commandline flags in the usage: we do that for you! +// Thread-hostile; meant to be called before any threads are spawned. +extern GFLAGS_DLL_DECL void SetUsageMessage(const std::string& usage); + +// Sets the version string, which is emitted with --version. +// For instance: SetVersionString("1.3"); +// Thread-hostile; meant to be called before any threads are spawned. +extern GFLAGS_DLL_DECL void SetVersionString(const std::string& version); + + +// Looks for flags in argv and parses them. Rearranges argv to put +// flags first, or removes them entirely if remove_flags is true. +// If a flag is defined more than once in the command line or flag +// file, the last definition is used. Returns the index (into argv) +// of the first non-flag argument. +// See top-of-file for more details on this function. +#ifndef SWIG // In swig, use ParseCommandLineFlagsScript() instead. +extern GFLAGS_DLL_DECL uint32 ParseCommandLineFlags(int *argc, char*** argv, bool remove_flags); +#endif + + +// Calls to ParseCommandLineNonHelpFlags and then to +// HandleCommandLineHelpFlags can be used instead of a call to +// ParseCommandLineFlags during initialization, in order to allow for +// changing default values for some FLAGS (via +// e.g. SetCommandLineOptionWithMode calls) between the time of +// command line parsing and the time of dumping help information for +// the flags as a result of command line parsing. If a flag is +// defined more than once in the command line or flag file, the last +// definition is used. Returns the index (into argv) of the first +// non-flag argument. (If remove_flags is true, will always return 1.) +extern GFLAGS_DLL_DECL uint32 ParseCommandLineNonHelpFlags(int *argc, char*** argv, bool remove_flags); + +// This is actually defined in gflags_reporting.cc. +// This function is misnamed (it also handles --version, etc.), but +// it's too late to change that now. :-( +extern GFLAGS_DLL_DECL void HandleCommandLineHelpFlags(); // in gflags_reporting.cc + +// Allow command line reparsing. Disables the error normally +// generated when an unknown flag is found, since it may be found in a +// later parse. Thread-hostile; meant to be called before any threads +// are spawned. +extern GFLAGS_DLL_DECL void AllowCommandLineReparsing(); + +// Reparse the flags that have not yet been recognized. Only flags +// registered since the last parse will be recognized. Any flag value +// must be provided as part of the argument using "=", not as a +// separate command line argument that follows the flag argument. +// Intended for handling flags from dynamically loaded libraries, +// since their flags are not registered until they are loaded. +extern GFLAGS_DLL_DECL void ReparseCommandLineNonHelpFlags(); + +// Clean up memory allocated by flags. This is only needed to reduce +// the quantity of "potentially leaked" reports emitted by memory +// debugging tools such as valgrind. It is not required for normal +// operation, or for the google perftools heap-checker. It must only +// be called when the process is about to exit, and all threads that +// might access flags are quiescent. Referencing flags after this is +// called will have unexpected consequences. This is not safe to run +// when multiple threads might be running: the function is +// thread-hostile. +extern GFLAGS_DLL_DECL void ShutDownCommandLineFlags(); + + +// -------------------------------------------------------------------- +// Now come the command line flag declaration/definition macros that +// will actually be used. They're kind of hairy. A major reason +// for this is initialization: we want people to be able to access +// variables in global constructors and have that not crash, even if +// their global constructor runs before the global constructor here. +// (Obviously, we can't guarantee the flags will have the correct +// default value in that case, but at least accessing them is safe.) +// The only way to do that is have flags point to a static buffer. +// So we make one, using a union to ensure proper alignment, and +// then use placement-new to actually set up the flag with the +// correct default value. In the same vein, we have to worry about +// flag access in global destructors, so FlagRegisterer has to be +// careful never to destroy the flag-values it constructs. +// +// Note that when we define a flag variable FLAGS_, we also +// preemptively define a junk variable, FLAGS_no. This is to +// cause a link-time error if someone tries to define 2 flags with +// names like "logging" and "nologging". We do this because a bool +// flag FLAG can be set from the command line to true with a "-FLAG" +// argument, and to false with a "-noFLAG" argument, and so this can +// potentially avert confusion. +// +// We also put flags into their own namespace. It is purposefully +// named in an opaque way that people should have trouble typing +// directly. The idea is that DEFINE puts the flag in the weird +// namespace, and DECLARE imports the flag from there into the current +// namespace. The net result is to force people to use DECLARE to get +// access to a flag, rather than saying "extern GFLAGS_DLL_DECL bool FLAGS_whatever;" +// or some such instead. We want this so we can put extra +// functionality (like sanity-checking) in DECLARE if we want, and +// make sure it is picked up everywhere. +// +// We also put the type of the variable in the namespace, so that +// people can't DECLARE_int32 something that they DEFINE_bool'd +// elsewhere. + +class GFLAGS_DLL_DECL FlagRegisterer { + public: + // We instantiate this template ctor for all supported types, + // so it is possible to place implementation of the FlagRegisterer ctor in + // .cc file. + // Calling this constructor with unsupported type will produce linker error. + template + FlagRegisterer(const char* name, + const char* help, const char* filename, + FlagType* current_storage, FlagType* defvalue_storage); +}; + +// Force compiler to not generate code for the given template specialization. +#if defined(_MSC_VER) && _MSC_VER < 1800 // Visual Studio 2013 version 12.0 + #define GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(type) +#else + #define GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(type) \ + extern template GFLAGS_DLL_DECL FlagRegisterer::FlagRegisterer( \ + const char* name, const char* help, const char* filename, \ + type* current_storage, type* defvalue_storage) +#endif + +// Do this for all supported flag types. +GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(bool); +GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(int32); +GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(uint32); +GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(int64); +GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(uint64); +GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(double); +GFLAGS_DECLARE_FLAG_REGISTERER_CTOR(std::string); + +#undef GFLAGS_DECLARE_FLAG_REGISTERER_CTOR + +// If your application #defines STRIP_FLAG_HELP to a non-zero value +// before #including this file, we remove the help message from the +// binary file. This can reduce the size of the resulting binary +// somewhat, and may also be useful for security reasons. + +extern GFLAGS_DLL_DECL const char kStrippedFlagHelp[]; + + +} // namespace GFLAGS_NAMESPACE + + +#ifndef SWIG // In swig, ignore the main flag declarations + +#if defined(STRIP_FLAG_HELP) && STRIP_FLAG_HELP > 0 +// Need this construct to avoid the 'defined but not used' warning. +#define MAYBE_STRIPPED_HELP(txt) \ + (false ? (txt) : GFLAGS_NAMESPACE::kStrippedFlagHelp) +#else +#define MAYBE_STRIPPED_HELP(txt) txt +#endif + +// Each command-line flag has two variables associated with it: one +// with the current value, and one with the default value. However, +// we have a third variable, which is where value is assigned; it's a +// constant. This guarantees that FLAG_##value is initialized at +// static initialization time (e.g. before program-start) rather than +// than global construction time (which is after program-start but +// before main), at least when 'value' is a compile-time constant. We +// use a small trick for the "default value" variable, and call it +// FLAGS_no. This serves the second purpose of assuring a +// compile error if someone tries to define a flag named no +// which is illegal (--foo and --nofoo both affect the "foo" flag). +#define DEFINE_VARIABLE(type, shorttype, name, value, help) \ + namespace fL##shorttype { \ + static const type FLAGS_nono##name = value; \ + /* We always want to export defined variables, dll or no */ \ + GFLAGS_DLL_DEFINE_FLAG type FLAGS_##name = FLAGS_nono##name; \ + static type FLAGS_no##name = FLAGS_nono##name; \ + static GFLAGS_NAMESPACE::FlagRegisterer o_##name( \ + #name, MAYBE_STRIPPED_HELP(help), __FILE__, \ + &FLAGS_##name, &FLAGS_no##name); \ + } \ + using fL##shorttype::FLAGS_##name + +// For DEFINE_bool, we want to do the extra check that the passed-in +// value is actually a bool, and not a string or something that can be +// coerced to a bool. These declarations (no definition needed!) will +// help us do that, and never evaluate From, which is important. +// We'll use 'sizeof(IsBool(val))' to distinguish. This code requires +// that the compiler have different sizes for bool & double. Since +// this is not guaranteed by the standard, we check it with a +// COMPILE_ASSERT. +namespace fLB { +struct CompileAssert {}; +typedef CompileAssert expected_sizeof_double_neq_sizeof_bool[ + (sizeof(double) != sizeof(bool)) ? 1 : -1]; +template double GFLAGS_DLL_DECL IsBoolFlag(const From& from); +GFLAGS_DLL_DECL bool IsBoolFlag(bool from); +} // namespace fLB + +// Here are the actual DEFINE_*-macros. The respective DECLARE_*-macros +// are in a separate include, gflags_declare.h, for reducing +// the physical transitive size for DECLARE use. +#define DEFINE_bool(name, val, txt) \ + namespace fLB { \ + typedef ::fLB::CompileAssert FLAG_##name##_value_is_not_a_bool[ \ + (sizeof(::fLB::IsBoolFlag(val)) != sizeof(double))? 1: -1]; \ + } \ + DEFINE_VARIABLE(bool, B, name, val, txt) + +#define DEFINE_int32(name, val, txt) \ + DEFINE_VARIABLE(GFLAGS_NAMESPACE::int32, I, \ + name, val, txt) + +#define DEFINE_uint32(name,val, txt) \ + DEFINE_VARIABLE(GFLAGS_NAMESPACE::uint32, U, \ + name, val, txt) + +#define DEFINE_int64(name, val, txt) \ + DEFINE_VARIABLE(GFLAGS_NAMESPACE::int64, I64, \ + name, val, txt) + +#define DEFINE_uint64(name,val, txt) \ + DEFINE_VARIABLE(GFLAGS_NAMESPACE::uint64, U64, \ + name, val, txt) + +#define DEFINE_double(name, val, txt) \ + DEFINE_VARIABLE(double, D, name, val, txt) + +// Strings are trickier, because they're not a POD, so we can't +// construct them at static-initialization time (instead they get +// constructed at global-constructor time, which is much later). To +// try to avoid crashes in that case, we use a char buffer to store +// the string, which we can static-initialize, and then placement-new +// into it later. It's not perfect, but the best we can do. + +namespace fLS { + +inline clstring* dont_pass0toDEFINE_string(char *stringspot, + const char *value) { + return new(stringspot) clstring(value); +} +inline clstring* dont_pass0toDEFINE_string(char *stringspot, + const clstring &value) { + return new(stringspot) clstring(value); +} +inline clstring* dont_pass0toDEFINE_string(char *stringspot, + int value); + +// Auxiliary class used to explicitly call destructor of string objects +// allocated using placement new during static program deinitialization. +// The destructor MUST be an inline function such that the explicit +// destruction occurs in the same compilation unit as the placement new. +class StringFlagDestructor { + void *current_storage_; + void *defvalue_storage_; + +public: + + StringFlagDestructor(void *current, void *defvalue) + : current_storage_(current), defvalue_storage_(defvalue) {} + + ~StringFlagDestructor() { + reinterpret_cast(current_storage_ )->~clstring(); + reinterpret_cast(defvalue_storage_)->~clstring(); + } +}; + +} // namespace fLS + +// We need to define a var named FLAGS_no##name so people don't define +// --string and --nostring. And we need a temporary place to put val +// so we don't have to evaluate it twice. Two great needs that go +// great together! +// The weird 'using' + 'extern' inside the fLS namespace is to work around +// an unknown compiler bug/issue with the gcc 4.2.1 on SUSE 10. See +// http://code.google.com/p/google-gflags/issues/detail?id=20 +#define DEFINE_string(name, val, txt) \ + namespace fLS { \ + using ::fLS::clstring; \ + using ::fLS::StringFlagDestructor; \ + static union { void* align; char s[sizeof(clstring)]; } s_##name[2]; \ + clstring* const FLAGS_no##name = ::fLS:: \ + dont_pass0toDEFINE_string(s_##name[0].s, \ + val); \ + static GFLAGS_NAMESPACE::FlagRegisterer o_##name( \ + #name, MAYBE_STRIPPED_HELP(txt), __FILE__, \ + FLAGS_no##name, new (s_##name[1].s) clstring(*FLAGS_no##name)); \ + static StringFlagDestructor d_##name(s_##name[0].s, s_##name[1].s); \ + extern GFLAGS_DLL_DEFINE_FLAG clstring& FLAGS_##name; \ + using fLS::FLAGS_##name; \ + clstring& FLAGS_##name = *FLAGS_no##name; \ + } \ + using fLS::FLAGS_##name + +#endif // SWIG + + +// Import gflags library symbols into alternative/deprecated namespace(s) +#include "gflags_gflags.h" + + +#endif // GFLAGS_GFLAGS_H_ diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/gflags_completions.h b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/gflags_completions.h new file mode 100644 index 000000000..f951c1e02 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/gflags_completions.h @@ -0,0 +1,121 @@ +// Copyright (c) 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --- + +// +// Implement helpful bash-style command line flag completions +// +// ** Functional API: +// HandleCommandLineCompletions() should be called early during +// program startup, but after command line flag code has been +// initialized, such as the beginning of HandleCommandLineHelpFlags(). +// It checks the value of the flag --tab_completion_word. If this +// flag is empty, nothing happens here. If it contains a string, +// however, then HandleCommandLineCompletions() will hijack the +// process, attempting to identify the intention behind this +// completion. Regardless of the outcome of this deduction, the +// process will be terminated, similar to --helpshort flag +// handling. +// +// ** Overview of Bash completions: +// Bash can be told to programatically determine completions for the +// current 'cursor word'. It does this by (in this case) invoking a +// command with some additional arguments identifying the command +// being executed, the word being completed, and the previous word +// (if any). Bash then expects a sequence of output lines to be +// printed to stdout. If these lines all contain a common prefix +// longer than the cursor word, bash will replace the cursor word +// with that common prefix, and display nothing. If there isn't such +// a common prefix, bash will display the lines in pages using 'more'. +// +// ** Strategy taken for command line completions: +// If we can deduce either the exact flag intended, or a common flag +// prefix, we'll output exactly that. Otherwise, if information +// must be displayed to the user, we'll take the opportunity to add +// some helpful information beyond just the flag name (specifically, +// we'll include the default flag value and as much of the flag's +// description as can fit on a single terminal line width, as specified +// by the flag --tab_completion_columns). Furthermore, we'll try to +// make bash order the output such that the most useful or relevent +// flags are the most likely to be shown at the top. +// +// ** Additional features: +// To assist in finding that one really useful flag, substring matching +// was implemented. Before pressing a to get completion for the +// current word, you can append one or more '?' to the flag to do +// substring matching. Here's the semantics: +// --foo Show me all flags with names prefixed by 'foo' +// --foo? Show me all flags with 'foo' somewhere in the name +// --foo?? Same as prior case, but also search in module +// definition path for 'foo' +// --foo??? Same as prior case, but also search in flag +// descriptions for 'foo' +// Finally, we'll trim the output to a relatively small number of +// flags to keep bash quiet about the verbosity of output. If one +// really wanted to see all possible matches, appending a '+' to the +// search word will force the exhaustive list of matches to be printed. +// +// ** How to have bash accept completions from a binary: +// Bash requires that it be informed about each command that programmatic +// completion should be enabled for. Example addition to a .bashrc +// file would be (your path to gflags_completions.sh file may differ): + +/* +$ complete -o bashdefault -o default -o nospace -C \ + '/home/build/eng/bash/bash_completions.sh --tab_completion_columns $COLUMNS' \ + time env binary_name another_binary [...] +*/ + +// This would allow the following to work: +// $ /path/to/binary_name --vmodule +// Or: +// $ ./bin/path/another_binary --gfs_u +// (etc) +// +// Sadly, it appears that bash gives no easy way to force this behavior for +// all commands. That's where the "time" in the above example comes in. +// If you haven't specifically added a command to the list of completion +// supported commands, you can still get completions by prefixing the +// entire command with "env". +// $ env /some/brand/new/binary --vmod +// Assuming that "binary" is a newly compiled binary, this should still +// produce the expected completion output. + + +#ifndef GFLAGS_COMPLETIONS_H_ +#define GFLAGS_COMPLETIONS_H_ + +namespace google { + +extern void HandleCommandLineCompletions(void); + +} + +#endif // GFLAGS_COMPLETIONS_H_ diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/gflags_declare.h b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/gflags_declare.h new file mode 100644 index 000000000..b5308462c --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/gflags_declare.h @@ -0,0 +1,156 @@ +// Copyright (c) 1999, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// --- +// +// Revamped and reorganized by Craig Silverstein +// +// This is the file that should be included by any file which declares +// command line flag. + +#ifndef GFLAGS_DECLARE_H_ +#define GFLAGS_DECLARE_H_ + + +// --------------------------------------------------------------------------- +// Namespace of gflags library symbols. +#define GFLAGS_NAMESPACE google + +// --------------------------------------------------------------------------- +// Windows DLL import/export. + +// Whether gflags library is a DLL. +// +// Set to 1 by default when the shared gflags library was built on Windows. +// Must be overwritten when this header file is used with the optionally also +// built static library instead; set by CMake's INTERFACE_COMPILE_DEFINITIONS. +#ifndef GFLAGS_IS_A_DLL +# define GFLAGS_IS_A_DLL 1 +#endif + +// We always want to import the symbols of the gflags library. +#ifndef GFLAGS_DLL_DECL +# if GFLAGS_IS_A_DLL && defined(_MSC_VER) +# define GFLAGS_DLL_DECL __declspec(dllimport) +# elif defined(__GNUC__) && __GNUC__ >= 4 +# define GFLAGS_DLL_DECL __attribute__((visibility("default"))) +# else +# define GFLAGS_DLL_DECL +# endif +#endif + +// We always want to import variables declared in user code. +#ifndef GFLAGS_DLL_DECLARE_FLAG +# if GFLAGS_IS_A_DLL && defined(_MSC_VER) +# define GFLAGS_DLL_DECLARE_FLAG __declspec(dllimport) +# elif defined(__GNUC__) && __GNUC__ >= 4 +# define GFLAGS_DLL_DECLARE_FLAG __attribute__((visibility("default"))) +# else +# define GFLAGS_DLL_DECLARE_FLAG +# endif +#endif + +// --------------------------------------------------------------------------- +// Flag types +#include +#if 1 +# include // the normal place uint32_t is defined +#elif 1 +# include // the normal place u_int32_t is defined +#elif 1 +# include // a third place for uint32_t or u_int32_t +#endif + +namespace GFLAGS_NAMESPACE { + +#if 1 // C99 +typedef int32_t int32; +typedef uint32_t uint32; +typedef int64_t int64; +typedef uint64_t uint64; +#elif 0 // BSD +typedef int32_t int32; +typedef u_int32_t uint32; +typedef int64_t int64; +typedef u_int64_t uint64; +#elif 0 // Windows +typedef __int32 int32; +typedef unsigned __int32 uint32; +typedef __int64 int64; +typedef unsigned __int64 uint64; +#else +# error Do not know how to define a 32-bit integer quantity on your system +#endif + +} // namespace GFLAGS_NAMESPACE + + +namespace fLS { + +// The meaning of "string" might be different between now and when the +// macros below get invoked (e.g., if someone is experimenting with +// other string implementations that get defined after this file is +// included). Save the current meaning now and use it in the macros. +typedef std::string clstring; + +} // namespace fLS + + +#define DECLARE_VARIABLE(type, shorttype, name) \ + /* We always want to import declared variables, dll or no */ \ + namespace fL##shorttype { extern GFLAGS_DLL_DECLARE_FLAG type FLAGS_##name; } \ + using fL##shorttype::FLAGS_##name + +#define DECLARE_bool(name) \ + DECLARE_VARIABLE(bool, B, name) + +#define DECLARE_int32(name) \ + DECLARE_VARIABLE(::GFLAGS_NAMESPACE::int32, I, name) + +#define DECLARE_uint32(name) \ + DECLARE_VARIABLE(::GFLAGS_NAMESPACE::uint32, U, name) + +#define DECLARE_int64(name) \ + DECLARE_VARIABLE(::GFLAGS_NAMESPACE::int64, I64, name) + +#define DECLARE_uint64(name) \ + DECLARE_VARIABLE(::GFLAGS_NAMESPACE::uint64, U64, name) + +#define DECLARE_double(name) \ + DECLARE_VARIABLE(double, D, name) + +#define DECLARE_string(name) \ + /* We always want to import declared variables, dll or no */ \ + namespace fLS { \ + extern GFLAGS_DLL_DECLARE_FLAG ::fLS::clstring& FLAGS_##name; \ + } \ + using fLS::FLAGS_##name + + +#endif // GFLAGS_DECLARE_H_ diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/gflags_gflags.h b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/gflags_gflags.h new file mode 100644 index 000000000..36d0ba1d5 --- /dev/null +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/gflags_gflags.h @@ -0,0 +1,102 @@ +// Copyright (c) 2014, Andreas Schuh +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// ----------------------------------------------------------------------------- +// Imports the gflags library symbols into an alternative/deprecated namespace. + +#ifndef GFLAGS_GFLAGS_H_ +# error The internal header gflags_gflags.h may only be included by gflags.h +#endif + +#ifndef GFLAGS_NS_GFLAGS_H_ +#define GFLAGS_NS_GFLAGS_H_ + + +namespace gflags { + + +using GFLAGS_NAMESPACE::int32; +using GFLAGS_NAMESPACE::uint32; +using GFLAGS_NAMESPACE::int64; +using GFLAGS_NAMESPACE::uint64; + +using GFLAGS_NAMESPACE::RegisterFlagValidator; +using GFLAGS_NAMESPACE::CommandLineFlagInfo; +using GFLAGS_NAMESPACE::GetAllFlags; +using GFLAGS_NAMESPACE::ShowUsageWithFlags; +using GFLAGS_NAMESPACE::ShowUsageWithFlagsRestrict; +using GFLAGS_NAMESPACE::DescribeOneFlag; +using GFLAGS_NAMESPACE::SetArgv; +using GFLAGS_NAMESPACE::GetArgvs; +using GFLAGS_NAMESPACE::GetArgv; +using GFLAGS_NAMESPACE::GetArgv0; +using GFLAGS_NAMESPACE::GetArgvSum; +using GFLAGS_NAMESPACE::ProgramInvocationName; +using GFLAGS_NAMESPACE::ProgramInvocationShortName; +using GFLAGS_NAMESPACE::ProgramUsage; +using GFLAGS_NAMESPACE::VersionString; +using GFLAGS_NAMESPACE::GetCommandLineOption; +using GFLAGS_NAMESPACE::GetCommandLineFlagInfo; +using GFLAGS_NAMESPACE::GetCommandLineFlagInfoOrDie; +using GFLAGS_NAMESPACE::FlagSettingMode; +using GFLAGS_NAMESPACE::SET_FLAGS_VALUE; +using GFLAGS_NAMESPACE::SET_FLAG_IF_DEFAULT; +using GFLAGS_NAMESPACE::SET_FLAGS_DEFAULT; +using GFLAGS_NAMESPACE::SetCommandLineOption; +using GFLAGS_NAMESPACE::SetCommandLineOptionWithMode; +using GFLAGS_NAMESPACE::FlagSaver; +using GFLAGS_NAMESPACE::CommandlineFlagsIntoString; +using GFLAGS_NAMESPACE::ReadFlagsFromString; +using GFLAGS_NAMESPACE::AppendFlagsIntoFile; +using GFLAGS_NAMESPACE::ReadFromFlagsFile; +using GFLAGS_NAMESPACE::BoolFromEnv; +using GFLAGS_NAMESPACE::Int32FromEnv; +using GFLAGS_NAMESPACE::Uint32FromEnv; +using GFLAGS_NAMESPACE::Int64FromEnv; +using GFLAGS_NAMESPACE::Uint64FromEnv; +using GFLAGS_NAMESPACE::DoubleFromEnv; +using GFLAGS_NAMESPACE::StringFromEnv; +using GFLAGS_NAMESPACE::SetUsageMessage; +using GFLAGS_NAMESPACE::SetVersionString; +using GFLAGS_NAMESPACE::ParseCommandLineNonHelpFlags; +using GFLAGS_NAMESPACE::HandleCommandLineHelpFlags; +using GFLAGS_NAMESPACE::AllowCommandLineReparsing; +using GFLAGS_NAMESPACE::ReparseCommandLineNonHelpFlags; +using GFLAGS_NAMESPACE::ShutDownCommandLineFlags; +using GFLAGS_NAMESPACE::FlagRegisterer; + +#ifndef SWIG +using GFLAGS_NAMESPACE::ParseCommandLineFlags; +#endif + + +} // namespace gflags + + +#endif // GFLAGS_NS_GFLAGS_H_ -- Gitee From 94142fc067a1f7844e53cfbede0666e5c7289b28 Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 07:00:22 +0000 Subject: [PATCH 14/22] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20AC?= =?UTF-8?q?L=5FTensorFlow/built-in/cv/Advanced=5FEast=5Ffor=5FACL/Benchmar?= =?UTF-8?q?k/inc/gflags/.keep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/.keep diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/.keep b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/Benchmark/inc/gflags/.keep deleted file mode 100644 index e69de29bb..000000000 -- Gitee From aa01600ecade46a7a63eb82e367016dcc1088701 Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 07:01:01 +0000 Subject: [PATCH 15/22] update ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md. --- ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md index 4aece44c7..effde107a 100644 --- a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md @@ -1,4 +1,4 @@ -# ID0130_AdvancedEAST +# Advanced_Ease_for_ACL AdvancedEAST 是一种用于场景图像文本检测的算法,主要基于 EAST:An Efficient and Accurate Scene Text Detector,并进行了重大改进,使长文本预测更加准确。 ## 训练环境 -- Gitee From 80be6efe73e61c8b6209891cb2f3def1cc3f3c1d Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 07:01:26 +0000 Subject: [PATCH 16/22] update ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md. --- ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md index effde107a..d4fbbaca0 100644 --- a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md @@ -1,4 +1,4 @@ -# Advanced_Ease_for_ACL +# Advanced_East_for_ACL AdvancedEAST 是一种用于场景图像文本检测的算法,主要基于 EAST:An Efficient and Accurate Scene Text Detector,并进行了重大改进,使长文本预测更加准确。 ## 训练环境 @@ -8,7 +8,7 @@ AdvancedEAST 是一种用于场景图像文本检测的算法,主要基于 EAS ## 代码及路径解释 ``` -AdvancedEAST_ID0130_for_ACL +Advanced_EAST_for_ACL ├── nms.py 预测用到的一个函数 ├── cfg.py 参数配置 ├── cfg_bank.py 参数配置 -- Gitee From 98eca5761e5d682e6b3f031d79a31144e3428261 Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 07:25:29 +0000 Subject: [PATCH 17/22] update ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md. --- .../cv/Advanced_East_for_ACL/README.md | 149 +++++++++--------- 1 file changed, 72 insertions(+), 77 deletions(-) diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md index d4fbbaca0..f0c7532ca 100644 --- a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md @@ -1,104 +1,99 @@ # Advanced_East_for_ACL -AdvancedEAST 是一种用于场景图像文本检测的算法,主要基于 EAST:An Efficient and Accurate Scene Text Detector,并进行了重大改进,使长文本预测更加准确。 -## 训练环境 +This repository provides a script and recipe to Inference the Advanced_East model. -* TensorFlow 1.15.0+ -* Python 3.7.0+ +## Notice +**This sample only provides reference for you to learn the Ascend software stack and is not for commercial purposes.** -## 代码及路径解释 +Before starting, please pay attention to the following adaptation conditions. If they do not match, may leading in failure. -``` -Advanced_EAST_for_ACL -├── nms.py 预测用到的一个函数 -├── cfg.py 参数配置 -├── cfg_bank.py 参数配置 -├── advanced_east.py 参数配置 -├── image_util.py 参数配置 -├── label.py 参数配置 -├── network_add_bn.py 参数配置 -├── icpr 数据集位置 -│ └── image_10000 图像文件 -│ └── txt_10000 标签文件 -├── demo 样例图片 -│ └── 001.png -├── image_test_bin 图片转为bin存放位置 -├── image_test_output msame推理结果bin文件存放位置 -├── preprocess.py 图片预处理 -├── image2bin.py 推理数据预处理:将image_test中的image文件转换为bin并进行其他图片预处理 -├── h5_to_pb.py h5模型固化为pb -├── atc.sh act工具 pb==》om 转换命令 -├── msame.sh msame工具:om离线推理命令 -├── postprocess.py 后处理 -├── predict.py 精度预测 +| Conditions | Need | +| --- | --- | +| CANN Version | >=5.0.3 | +| Chip Platform| Ascend310/Ascend310P3 | +| 3rd Party Requirements| Please follow the 'requirements.txt' | + +## Quick Start Guide + +### 1. Clone the respository + +```shell +git clone https://gitee.com/ascend/ModelZoo-TensorFlow.git +cd Modelzoo-TensorFlow/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL ``` +### 2. Download and preprocess the dataset tianchi ICPR MTWI 2018 -## 数据集 tianchi ICPR MTWI 2018 +1. Download the dataset by yourself + ``` + tianchi ICPR MTWI 2018 + + ``` -测试集下载地址:链接: 提取码:1234 +2. Executing the Preprocessing Script + + ``` + python3. preprocess.py -精度验证链接: https://tianchi.aliyun.com/competition/entrance/231685/rankingList + ``` + ``` + python3.7.5 image2bin.py -## 图片预处理 -```shell -python3.7.5 preprocess.py -``` + ``` -## 将测试集图片转为bin文件 -```shell -python3.7.5 image2bin.py -``` +### 3. Offline Inference +**Convert h5 to pb.** + ``` + python3.7.5 h5_to_pb.py -## 模型文件 -包括初始h5文件,固化pb文件,以及推理om文件 -h5模型下载地址:链接: 提取码: -pb模型下载地址:链接: 提取码: + ``` +**Convert pb to om.** -## pb模型 + [pb download link]() -模型固化 -```shell -python3.7.5 h5_to_pb.py -``` -## 生成om模型 -使用ATC模型转换工具进行模型转换时可参考如下指令 atc.sh: -```shell -atc --model=model.pb --input_shape="input_img:1,736,736,3" --framework=3 --output=model --soc_version=Ascend310 --input_format=NHWC -``` -具体参数使用方法请查看官方文档。 +- configure the env -## 使用msame工具推理 + ``` + export install_path=/usr/local/Ascend + export PATH=/usr/local/python3.7.5/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH + export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/atc/python/site-packages/auto_tune.egg/auto_tune:${install_path}/atc/python/site-packages/schedule_search.egg:$PYTHONPATH + export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH + export ASCEND_OPP_PATH=${install_path}/opp + ``` -使用msame工具进行推理时可参考如下指令 msame.sh -```shell -./msame --model $MODEL --input $INPUT --output $OUTPUT --outfmt BIN -``` -参考 https://gitee.com/ascend/tools/tree/master/msame, 获取msame推理工具及使用方法。 +- convert pb to om -## 执行predict -```shell -python3.7.5 predict.py -``` + ``` + atc --model=model.pb --input_shape="input_img:1,736,736,3" --framework=3 --output=Advanced_East --soc_version=Ascend310 --input_format=NHWC + + ``` + +- Build the program -## 精度 -* 论文精度: + ``` + bash build.sh + ``` -| Score | Precision | Recall | -| :--------: | ---------- | ------ | -| 0.611 | 0.809 | 0.492 | +- Run the program: -* GPU目标精度: +``` +bash benchmark_tf.sh --batchSize=1 --modelPath=../../model/Advanced_East.om --dataPath=../../datasets/ --modelType=Advanced_East --imgType=rgb + +``` +## Performance -| Score | Precision | Recall | -| :--------: | ---------- | ------ | -| 0.554 | 0.760 | 0.436 | +### Result -* Ascend推理精度: +Our result were obtained by running the applicable inference script. To achieve the same results, follow the steps in the Quick Start Guide. + ``` + python3.7.5 predict.py -| Score | Precision | Recall | -| :--------: | ---------- | ------ | -| 0.632 | 0.849 | 0.513 | + ``` +#### Inference accuracy results +| model | **data** | precision | recall | heamn | +| :---------------: | :-------: | :-------------: | :-------------: | :-------------: | +| offline Inference | 233 images | 74.73% | 70.26% | 72.43% | +## -- Gitee From dd4728f04e82934f1b5cd6d5475d33358a7a29ff Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 07:26:32 +0000 Subject: [PATCH 18/22] update ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md. --- .../built-in/cv/Advanced_East_for_ACL/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md index f0c7532ca..90b7dc1b7 100644 --- a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md @@ -43,10 +43,10 @@ cd Modelzoo-TensorFlow/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL ### 3. Offline Inference **Convert h5 to pb.** - ``` - python3.7.5 h5_to_pb.py + ``` + python3.7.5 h5_to_pb.py - ``` + ``` **Convert pb to om.** [pb download link]() @@ -77,10 +77,10 @@ cd Modelzoo-TensorFlow/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL - Run the program: -``` -bash benchmark_tf.sh --batchSize=1 --modelPath=../../model/Advanced_East.om --dataPath=../../datasets/ --modelType=Advanced_East --imgType=rgb + ``` + bash benchmark_tf.sh --batchSize=1 --modelPath=../../model/Advanced_East.om --dataPath=../../datasets/ --modelType=Advanced_East --imgType=rgb -``` + ``` ## Performance ### Result -- Gitee From 2205c8b4ebea5c3dc49a9f1f41a90bfff0213afc Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 07:29:24 +0000 Subject: [PATCH 19/22] update ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md. --- .../cv/Advanced_East_for_ACL/README.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md index 90b7dc1b7..7e7326210 100644 --- a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md @@ -42,15 +42,6 @@ cd Modelzoo-TensorFlow/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL ### 3. Offline Inference -**Convert h5 to pb.** - ``` - python3.7.5 h5_to_pb.py - - ``` -**Convert pb to om.** - - [pb download link]() - - configure the env @@ -61,14 +52,22 @@ cd Modelzoo-TensorFlow/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL export LD_LIBRARY_PATH=${install_path}/atc/lib64:${install_path}/acllib/lib64:$LD_LIBRARY_PATH export ASCEND_OPP_PATH=${install_path}/opp ``` +- Convert h5 to pb -- convert pb to om + ``` + python3.7.5 h5_to_pb.py + + ``` +2. Convert pb to om + + [pb download link]() ``` atc --model=model.pb --input_shape="input_img:1,736,736,3" --framework=3 --output=Advanced_East --soc_version=Ascend310 --input_format=NHWC ``` + - Build the program ``` -- Gitee From 9eeedb32f2b8328a403554e98f18b3abdb2fdea4 Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 07:30:10 +0000 Subject: [PATCH 20/22] update ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md. --- .../built-in/cv/Advanced_East_for_ACL/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md index 7e7326210..207a52799 100644 --- a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md @@ -32,11 +32,11 @@ cd Modelzoo-TensorFlow/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL 2. Executing the Preprocessing Script ``` - python3. preprocess.py + python3 script/preprocess.py ``` ``` - python3.7.5 image2bin.py + python3 script/image2bin.py ``` @@ -55,7 +55,7 @@ cd Modelzoo-TensorFlow/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL - Convert h5 to pb ``` - python3.7.5 h5_to_pb.py + python3 h5_to_pb.py ``` 2. Convert pb to om @@ -86,7 +86,7 @@ cd Modelzoo-TensorFlow/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL Our result were obtained by running the applicable inference script. To achieve the same results, follow the steps in the Quick Start Guide. ``` - python3.7.5 predict.py + python3 predict.py ``` -- Gitee From dd0faaa35eb0c6902c9db22db3fccdb700ada038 Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 07:30:45 +0000 Subject: [PATCH 21/22] update ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md. --- .../built-in/cv/Advanced_East_for_ACL/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md index 207a52799..2937354f2 100644 --- a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md @@ -60,12 +60,12 @@ cd Modelzoo-TensorFlow/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL ``` 2. Convert pb to om - [pb download link]() + [pb download link]() - ``` - atc --model=model.pb --input_shape="input_img:1,736,736,3" --framework=3 --output=Advanced_East --soc_version=Ascend310 --input_format=NHWC + ``` + atc --model=model.pb --input_shape="input_img:1,736,736,3" --framework=3 --output=Advanced_East --soc_version=Ascend310 --input_format=NHWC - ``` + ``` - Build the program -- Gitee From 53861883695eceda468b1a328fe7f45cd1a0a782 Mon Sep 17 00:00:00 2001 From: WinnieMa Date: Mon, 25 Jul 2022 08:39:08 +0000 Subject: [PATCH 22/22] update ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md. --- ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md index 2937354f2..48e6bbbd4 100644 --- a/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md +++ b/ACL_TensorFlow/built-in/cv/Advanced_East_for_ACL/README.md @@ -94,5 +94,5 @@ Our result were obtained by running the applicable inference script. To achieve | model | **data** | precision | recall | heamn | | :---------------: | :-------: | :-------------: | :-------------: | :-------------: | -| offline Inference | 233 images | 74.73% | 70.26% | 72.43% | +| offline Inference | 1000 images | 84.91% | 55.54% | 63.57% | ## -- Gitee