├── .gitignore ├── LICENSE ├── README.md ├── TensorBuilder ├── .gitignore ├── CodeEditDialog.qml ├── Connection.qml ├── ConsoleDialog.qml ├── GraphDisplay.qml ├── GraphNode.qml ├── HelpDialog.qml ├── LoadingDialog.qml ├── ModelBrowser.qml ├── MyButton.qml ├── MyDialog.qml ├── MyLabel.qml ├── NewNodeDialog.qml ├── Page1.qml ├── Page1Form.ui.qml ├── SelectionPanel.qml ├── TensorBuilder.pro ├── main.cpp ├── main.qml ├── native.cpp ├── native.h ├── qml.qrc └── qtquickcontrols2.conf └── pics ├── 1.png ├── 2.png ├── 3.png └── 4.png /.gitignore: -------------------------------------------------------------------------------- 1 | # C++ objects and libs 2 | 3 | *.slo 4 | *.lo 5 | *.o 6 | *.a 7 | *.la 8 | *.lai 9 | *.so 10 | *.dll 11 | *.dylib 12 | 13 | # Qt-es 14 | 15 | /.qmake.cache 16 | /.qmake.stash 17 | *.pro.user 18 | *.pro.user.* 19 | *.qbs.user 20 | *.qbs.user.* 21 | *.moc 22 | moc_*.cpp 23 | moc_*.h 24 | qrc_*.cpp 25 | ui_*.h 26 | Makefile* 27 | *build-* 28 | 29 | # QtCreator 30 | 31 | *.autosave 32 | 33 | # QtCtreator Qml 34 | *.qmlproject.user 35 | *.qmlproject.user.* 36 | 37 | # QtCtreator CMake 38 | CMakeLists.txt.user* 39 | 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | (This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.) 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | {description} 474 | Copyright (C) {year} {fullname} 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | {signature of Ty Coon}, 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TensorBuilder 2 | 3 | A drag and drop GUI tool written in Qt to rapidly prototype TensorFlow computational graphs, and instantly share your models to the community. 4 | 5 | ## Goals 6 | 7 | - To make machine learning more accessible to everyone regardless of programming backgrounds 8 | - To allow professionals to quickly test and experiment with different models 9 | - To simplify sharing and forking of experimental models for accelerated research 10 | 11 | ## Features 12 | 13 | - GUI flow chart for rapid prototyping of TensorFlow computational graphs 14 | - One-click compile and run python TensorFlow for quick feedback 15 | - Instant sharing to community server and browse & fork models uploaded by others 16 | 17 | ![Graph editor](pics/3.png) 18 | 19 | ## Inspiration 20 | Over the past few years, AI and machine learning has become one of the biggest topics around the world. With numerous open-source libraries quickly gaining popularity, it has become more and more accessible to those who are willing to learn it. However, these tools are still suited only towards those who know a decent bit of programming, and that was a big injustice in our perspective to those who want to start learning. 21 | 22 | In order to achieve our vision, we set out to design something that would not only visualize how machine learning works, but would also provide a basic structure for building simple AIs. As such, we have developed a desktop application that allows users to create and connect nodes to form basic machines that process data. Different types of nodes are represented by different colors, as well as intuitive designs to make the learning curve smooth while offering a variety of features. The user can choose any node to run, in which the program will turn the graph into a python script built on top of Tensorflow. 23 | 24 | However, we didn't feel that this was enough to ease someone into the field of AI. Although we had built an app that was simple to use, we still haven't found a way to teach the necessary fundamentals. It was this thought that led us to build an online community system, wherein anyone could put their own graph of nodes online for anyone else across the world to try out for themselves. Not only are we able to now provide simple graphs to showcase the basics, but people can share their own creations for others to analyze and understand as well. 25 | 26 | ![The new node panel](pics/1.png) 27 | 28 | ## TensorBuilder 29 | We built most of our application front end with Qt / QML, and our back end uses a combination of Firebase and AWS. The scripts outputted by the program is generated with C++ within the application itself. We support a lot of the core features from Tensorflow, allowing us to compile all of our scripts into python. 30 | 31 | ![Running Python in the application](pics/4.png) 32 | 33 | ## Challenges 34 | This whole weekend was just challenge upon challenge for us, especially since we are only a 2 man team. Some of the biggest struggles we faced included compiling from the graph to python, saving the data correctly from the client to the server, and simply coding with unfamiliar libraries and platforms. There were countless more hardships along the way, but we're both very proud of what we were able to create. 35 | 36 | ## The Future 37 | Obviously, we wish we had more time to put in the project, but it is a hackathon after all. In this weekend, we were able to achieve a minimal prototype that aligns with our vision at the start. In the future, we want to implement more of the Tensorflow library to allow for even more creativity amongst our users, and possible an authentication system for people to save or share models that they like. In the end, we are hoping that our open-source application provides competition to proprietary software, with hopes to bring more people into the world of AI and machine learning. 38 | 39 | ![Graph editor](pics/2.png) 40 | -------------------------------------------------------------------------------- /TensorBuilder/.gitignore: -------------------------------------------------------------------------------- 1 | # This file is used to ignore files which are generated 2 | # ---------------------------------------------------------------------------- 3 | 4 | *~ 5 | *.autosave 6 | *.a 7 | *.core 8 | *.moc 9 | *.o 10 | *.obj 11 | *.orig 12 | *.rej 13 | *.so 14 | *.so.* 15 | *_pch.h.cpp 16 | *_resource.rc 17 | *.qm 18 | .#* 19 | *.*# 20 | core 21 | !core/ 22 | tags 23 | .DS_Store 24 | .directory 25 | *.debug 26 | Makefile* 27 | *.prl 28 | *.app 29 | moc_*.cpp 30 | ui_*.h 31 | qrc_*.cpp 32 | Thumbs.db 33 | *.res 34 | *.rc 35 | /.qmake.cache 36 | /.qmake.stash 37 | 38 | # qtcreator generated files 39 | *.pro.user* 40 | 41 | # xemacs temporary files 42 | *.flc 43 | 44 | # Vim temporary files 45 | .*.swp 46 | 47 | # Visual Studio generated files 48 | *.ib_pdb_index 49 | *.idb 50 | *.ilk 51 | *.pdb 52 | *.sln 53 | *.suo 54 | *.vcproj 55 | *vcproj.*.*.user 56 | *.ncb 57 | *.sdf 58 | *.opensdf 59 | *.vcxproj 60 | *vcxproj.* 61 | 62 | # MinGW generated files 63 | *.Debug 64 | *.Release 65 | 66 | # Python byte code 67 | *.pyc 68 | 69 | # Binaries 70 | # -------- 71 | *.dll 72 | *.exe 73 | 74 | -------------------------------------------------------------------------------- /TensorBuilder/CodeEditDialog.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | import QtQuick.Controls 2.2 3 | 4 | MyDialog { 5 | id: code_edit_dialog 6 | modal: true 7 | 8 | title: qsTr("Edit Value") 9 | standardButtons: Dialog.Ok | Dialog.Cancel 10 | 11 | onAccepted: { 12 | node.input_values[index] = text_area.text 13 | } 14 | 15 | onNodeChanged: { 16 | if (node.input_values[index]) { 17 | text_area.text = (node.input_values[index]).toString() 18 | } 19 | else { 20 | text_area.text = '' 21 | } 22 | } 23 | 24 | width: 500 25 | height: parent.height * 0.75 26 | 27 | property var node 28 | property int index 29 | 30 | Rectangle { 31 | anchors.fill: parent 32 | color: '#dddddd' 33 | 34 | ScrollView { 35 | anchors.fill: parent 36 | anchors.margins: 10 37 | clip: true 38 | 39 | TextArea { 40 | id: text_area 41 | text: "" 42 | selectByKeyboard: true 43 | selectByMouse: true 44 | } 45 | } 46 | } 47 | 48 | Rectangle { 49 | anchors.fill: parent 50 | color: 'transparent' 51 | border.width: 2 52 | border.color: '#a0a0a0' 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /TensorBuilder/Connection.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | import QtQuick.Controls 2.2 3 | 4 | Item { 5 | id:container 6 | width: 320 7 | height: 480 8 | 9 | anchors.fill: parent 10 | anchors.topMargin: 12 11 | 12 | property var from_node: null 13 | property int from_index: 0 14 | 15 | property var to_node: null 16 | property int to_index: 0 17 | 18 | property var canvas_rect: { 19 | return get_canvas_rect(from_node.get_output_point(from_index), to_node.get_input_point(to_index)) 20 | } 21 | 22 | function get_canvas_rect(from_point, to_point) { 23 | var rect_x = Math.min(from_point.x, to_point.x) 24 | var rect_y = Math.min(from_point.y, to_point.y) 25 | var rect_width = Math.max(from_point.x, to_point.x) - rect_x 26 | var rect_height = Math.max(from_point.y, to_point.y) - rect_y 27 | rect_width = Math.max(10, rect_width) 28 | rect_height = Math.max(10, rect_height) 29 | 30 | return { 31 | 'x': rect_x, 32 | 'y': rect_y, 33 | 'width': rect_width, 34 | 'height': rect_height, 35 | 'start_x': (from_point.x - rect_x) / rect_width, 36 | 'start_y': (from_point.y - rect_y) / rect_height, 37 | 'end_x': (to_point.x - rect_x) / rect_width, 38 | 'end_y': (to_point.y - rect_y) / rect_height, 39 | } 40 | } 41 | 42 | Component.onCompleted: { 43 | 44 | } 45 | 46 | Canvas { 47 | id: canvas 48 | width: Math.min(canvas_rect.width / canvas_rect.height * 512, 512) 49 | height: Math.min(canvas_rect.height / canvas_rect.width * 512, 512) 50 | x: canvas_rect.x 51 | y: canvas_rect.y 52 | property color strokeStyle: from_node.definition.color 53 | property real lineWidth: 4.0 / Math.min(scaleX, scaleY) 54 | property bool fill: true 55 | property bool stroke: true 56 | property real scaleX: canvas_rect.width / width 57 | property real scaleY: canvas_rect.height / height 58 | antialiasing: true 59 | 60 | onFillChanged:requestPaint(); 61 | onStrokeChanged:requestPaint(); 62 | onScaleXChanged: requestPaint(); 63 | onScaleYChanged: requestPaint(); 64 | 65 | transform: Scale { 66 | xScale: canvas.scaleX 67 | yScale: canvas.scaleY 68 | } 69 | 70 | function draw_bezier(ctx, start_x, start_y, end_x, end_y) { 71 | start_x *= width 72 | start_y *= height 73 | end_x *= width 74 | end_y *= height 75 | ctx.moveTo(start_x, start_y); 76 | ctx.bezierCurveTo(lerp(start_x, end_x, 0.5), start_y, lerp(start_x, end_x, 0.5), end_y, end_x, end_y); 77 | } 78 | 79 | onPaint: { 80 | var ctx = canvas.getContext('2d'); 81 | ctx.save(); 82 | ctx.clearRect(0, 0, canvas.width, canvas.height); 83 | ctx.strokeStyle = canvas.strokeStyle; 84 | ctx.fillStyle = canvas.fillStyle; 85 | ctx.lineWidth = canvas.lineWidth; 86 | 87 | ctx.beginPath(); 88 | draw_bezier(ctx, canvas_rect.start_x, canvas_rect.start_y, canvas_rect.end_x, canvas_rect.end_y) 89 | if (canvas.stroke) 90 | ctx.stroke(); 91 | ctx.restore(); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /TensorBuilder/ConsoleDialog.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | import QtQuick.Controls 2.2 3 | import QtQuick.Layouts 1.3 4 | 5 | MyDialog { 6 | id: console_dialog 7 | modal: true 8 | 9 | title: { 10 | return is_running ? qsTr("Running") + main.repeat_str('.', (Math.floor(timer.count / 10) % 3 + 1)) : qsTr("Completed") 11 | } 12 | 13 | closePolicy: is_running ? Popup.NoAutoClose : (Popup.CloseOnEscape | Popup.CloseOnPressOutside) 14 | 15 | standardButtons: { 16 | return is_running ? 0 : Dialog.Ok 17 | } 18 | 19 | property bool is_running: false 20 | 21 | onAccepted: { 22 | 23 | } 24 | 25 | onRejected: function (event) { 26 | 27 | } 28 | 29 | width: 600 30 | height: parent.height * 0.75 31 | 32 | property var node 33 | property int index 34 | 35 | Rectangle { 36 | anchors.fill: parent 37 | color: '#dddddd' 38 | 39 | ScrollView { 40 | anchors.fill: parent 41 | anchors.margins: 10 42 | clip: true 43 | 44 | TextArea { 45 | id: text_area 46 | text: "" 47 | selectByKeyboard: true 48 | selectByMouse: true 49 | readOnly: true 50 | 51 | wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere 52 | } 53 | } 54 | } 55 | 56 | function clear() { 57 | is_running = Native.is_python_running() 58 | text_area.clear() 59 | } 60 | 61 | function add_text(text) { 62 | is_running = Native.is_python_running() 63 | text_area.text += text 64 | } 65 | 66 | Timer { 67 | id: timer 68 | property int count: 0 69 | interval: 100 70 | running: true 71 | repeat: true 72 | onTriggered: { 73 | count++ 74 | is_running = Native.is_python_running() 75 | var stream = Native.get_python_stream() 76 | if (stream.length > 0) { 77 | text_area.text += stream 78 | } 79 | } 80 | } 81 | 82 | Rectangle { 83 | anchors.fill: parent 84 | color: 'transparent' 85 | border.width: 2 86 | border.color: '#a0a0a0' 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /TensorBuilder/GraphDisplay.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | import QtQuick.Controls 2.2 3 | 4 | Rectangle { 5 | id: graphDisplay 6 | color: '#eeeeee' 7 | 8 | property real offset_x: view.x 9 | property real offset_y: view.y 10 | property real view_scale: 1 11 | property real view_scale_rate: 0.25 12 | property real view_scale_min: 0.25 13 | property real view_scale_max: 4 14 | 15 | property bool target_set: false 16 | property var from_node: null 17 | property int from_index: 0 18 | 19 | property real last_right_click_x: 0 20 | property real last_right_click_y: 0 21 | 22 | property var nodes: [] 23 | 24 | Component { 25 | id: graph_node_component 26 | 27 | GraphNode { 28 | 29 | } 30 | } 31 | 32 | Component { 33 | id: connection_component 34 | 35 | Connection { 36 | 37 | } 38 | } 39 | 40 | function add_graph_node(definition) { 41 | var node = graph_node_component.createObject( 42 | view, 43 | { 44 | 'definition': definition, 45 | } 46 | ) 47 | 48 | nodes.push(node) 49 | 50 | return node 51 | } 52 | 53 | function show_code_editor(node, index) { 54 | code_edit_dialog.index = index 55 | code_edit_dialog.node = node 56 | code_edit_dialog.open() 57 | } 58 | 59 | function show_help() { 60 | help_dialog.open() 61 | } 62 | 63 | function show_loading(show) { 64 | if (show) { 65 | loading_dialog.open() 66 | } 67 | else { 68 | loading_dialog.close() 69 | } 70 | } 71 | 72 | function run_node(node) { 73 | var script 74 | script = 'import math, os\n'+ 75 | 'from tensorflow.examples.tutorials.mnist import input_data\n'+ 76 | 'import tensorflow as tf\n'+ 77 | '\n'+ 78 | 'mnist = input_data.read_data_sets("MNIST_data/", one_hot = True)\n'+ 79 | '\n'+ 80 | '# print(tf.Session().run(tf.constant(\'Hello, World!\')))\n'+ 81 | '\n'+ 82 | 'input_dim_raw = 28\n'+ 83 | 'input_dim = 28 * 28\n'+ 84 | 'output_dim = 10\n'+ 85 | 'init_min = 0\n'+ 86 | 'init_max = 0.1\n'+ 87 | 'iterations = 1000\n'+ 88 | 'batch_size = 100\n'+ 89 | '\n'+ 90 | 'iteration_log_frequency = 100\n'+ 91 | '\n'+ 92 | 'num_data = None\n'+ 93 | '\n'+ 94 | 'inputs = tf.placeholder(tf.float32, [num_data, input_dim])\n'+ 95 | '\n'+ 96 | 'weights = tf.Variable(tf.random_uniform([input_dim, output_dim], init_min, init_max))\n'+ 97 | 'biasses = tf.Variable(tf.random_uniform([output_dim], init_min, init_max))\n'+ 98 | ' \n'+ 99 | 'outputs = tf.nn.softmax(tf.add(tf.matmul(inputs, weights), biasses))\n'+ 100 | 'labels = tf.placeholder(tf.float32, [num_data, 10])\n'+ 101 | '\n'+ 102 | 'cost = tf.reduce_mean(-tf.reduce_sum(tf.multiply(labels, tf.log(outputs)), axis = 1))\n'+ 103 | '\n'+ 104 | 'init = tf.global_variables_initializer()\n'+ 105 | 'train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cost)\n'+ 106 | '\n'+ 107 | 'session = tf.InteractiveSession()\n'+ 108 | '\n'+ 109 | 'print(\'initializing.\')\n'+ 110 | 'session.run(init)\n'+ 111 | '\n'+ 112 | 'for i in range(iterations):\n'+ 113 | ' if i % iteration_log_frequency == 0:\n'+ 114 | ' print(\'iteration {0}...\'.format(i))\n'+ 115 | ' \n'+ 116 | ' batch_input, batch_label = mnist.train.next_batch(batch_size)\n'+ 117 | ' # note the use of vectorization and putting 2 matrices to multiple together\n'+ 118 | ' session.run(train_step, {inputs: batch_input, labels: batch_label})\n'+ 119 | '\n'+ 120 | 'print(\'training complete.\')\n'+ 121 | '\n'+ 122 | 'predictions = tf.argmax(outputs, 1)\n'+ 123 | 'accuracies = tf.reduce_mean(tf.cast(tf.equal(predictions, tf.argmax(labels, 1)), tf.float32))\n'+ 124 | '\n'+ 125 | 'print(\'accuracy: {0}\'.format(\n'+ 126 | ' session.run(\n'+ 127 | ' accuracies,\n'+ 128 | ' {inputs: mnist.test.images, labels: mnist.test.labels}\n'+ 129 | ' )\n'+ 130 | '))\n'+ 131 | '\n'+ 132 | 'def predict(input):\n'+ 133 | ' result = session.run(outputs, {inputs: [input]})[0].tolist()\n'+ 134 | ' winner = 0\n'+ 135 | ' curmax = 0\n'+ 136 | ' for i in range(1, len(result)):\n'+ 137 | ' if result[i] > curmax:\n'+ 138 | ' winner = i\n'+ 139 | ' curmax = result[i]\n'+ 140 | ' \n'+ 141 | ' return result, winner\n'+ 142 | '\n'+ 143 | 'def flatten(array):\n'+ 144 | ' result = []\n'+ 145 | ' for row in array:\n'+ 146 | ' result += row\n'+ 147 | ' \n'+ 148 | ' return result\n'+ 149 | '\n'+ 150 | 'def print_with_index(array):\n'+ 151 | ' for i in range(len(array)):\n'+ 152 | ' print(\'{0}:\t{1} {2}\'.format(i, visualize_float(array[i]), array[i]))\n'+ 153 | ' \n'+ 154 | ' \n'+ 155 | '\n'+ 156 | 'def visualize_float(x, length = 16):\n'+ 157 | ' steps = round(x * length)\n'+ 158 | ' return \'-\' * steps + \' \' * (length - steps)\n'+ 159 | '\n'+ 160 | 'x = [[0 for j in range(input_dim_raw)] for i in range(input_dim_raw)]\n'+ 161 | '_ = 0\n'+ 162 | 'x = [\n'+ 163 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_],\n'+ 164 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_],\n'+ 165 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_],\n'+ 166 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_],\n'+ 167 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_],\n'+ 168 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_],\n'+ 169 | ' [_,_,_,_,_,_,_,_,_,_,1,1,1,1,1,1,1,1,1,1,_,_,_,_,_,_,_,_],\n'+ 170 | ' [_,_,_,_,_,_,_,_,_,_,1,1,_,_,_,_,_,1,1,_,_,_,_,_,_,_,_,_],\n'+ 171 | ' [_,_,_,_,_,_,_,_,_,_,1,1,_,_,_,_,_,1,1,_,_,_,_,_,_,_,_,_],\n'+ 172 | ' [_,_,_,_,_,_,_,_,_,_,1,1,_,_,_,_,_,1,1,_,_,_,_,_,_,_,_,_],\n'+ 173 | ' [_,_,_,_,_,_,_,_,_,_,1,1,_,_,_,_,_,1,1,_,_,_,_,_,_,_,_,_],\n'+ 174 | ' [_,_,_,_,_,_,_,_,_,_,1,1,_,_,_,_,_,1,1,_,_,_,_,_,_,_,_,_],\n'+ 175 | ' [_,_,_,_,_,_,_,_,_,_,1,1,_,_,_,_,_,1,1,_,_,_,_,_,_,_,_,_],\n'+ 176 | ' [_,_,_,_,_,_,_,_,_,_,1,1,1,1,1,1,1,1,1,_,_,_,_,_,_,_,_,_],\n'+ 177 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,1,1,_,_,_,_,_,_,_,_,_],\n'+ 178 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,1,1,_,_,_,_,_,_,_,_,_],\n'+ 179 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,1,1,_,_,_,_,_,_,_,_,_],\n'+ 180 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,1,1,_,_,_,_,_,_,_,_,_],\n'+ 181 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,1,1,_,_,_,_,_,_,_,_,_],\n'+ 182 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,1,1,_,_,_,_,_,_,_,_,_],\n'+ 183 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,1,1,_,_,_,_,_,_,_,_,_],\n'+ 184 | ' [_,_,_,_,_,_,_,_,_,_,1,1,1,1,1,1,1,1,1,_,_,_,_,_,_,_,_,_],\n'+ 185 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_],\n'+ 186 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_],\n'+ 187 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_],\n'+ 188 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_],\n'+ 189 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_],\n'+ 190 | ' [_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_]\n'+ 191 | ']\n'+ 192 | '\n'+ 193 | 'result, winner = predict(flatten(x))\n'+ 194 | 'print_with_index(result)\n'+ 195 | 'print(\'prediction: {0}\'.format(winner))\n'+ '' 196 | 197 | cache_node_temps() 198 | 199 | var lines = [ 200 | 'import math, os', 201 | 'import tensorflow as tf', 202 | 'feed_dict = {}', 203 | 'session = tf.InteractiveSession()', 204 | ] 205 | 206 | extend_array(lines, node.get_execution()) 207 | 208 | script = lines.join('\n') 209 | 210 | if (!Native.is_python_running()) { 211 | console_dialog.clear() 212 | // console_dialog.add_text(script) 213 | console_dialog.add_text('...\n') 214 | Native.run_python(script) 215 | } 216 | 217 | console_dialog.open() 218 | } 219 | 220 | function cache_node_temps() { 221 | var count = 0 222 | for (var i in nodes) { 223 | var node = nodes[i] 224 | node.temp_names = [] 225 | for (var j in node.definition.outputs) { 226 | node.temp_names.push('node_' + count + '_' + j) 227 | } 228 | node.temp_declared = false 229 | count++ 230 | } 231 | for (var i in nodes) { 232 | var node = nodes[i] 233 | node.temp_params = {} 234 | for (var j in node.input_values) { 235 | var param = {} 236 | var input_definition = node.definition.inputs[j] 237 | var input_value = node.input_values[j] 238 | var connection = node.connections[j] 239 | 240 | if (input_definition.type === 'code' || input_definition.type === 'number' || input_definition.type === 'type') { 241 | param['code_str'] = input_value 242 | param['value'] = input_value 243 | } 244 | else if (input_definition.type === 'string') { 245 | if (input_definition.code === 'name' && input_value.length === 0) { 246 | input_value = 'node' 247 | } 248 | param['code_str'] = '\'' + input_value + '\'' 249 | param['value'] = input_value 250 | } 251 | else if (input_definition.type === 'reference') { 252 | if (connection === null) { 253 | param['code_str'] = 'None' 254 | } 255 | else { 256 | param['code_str'] = connection.from_node.temp_names[connection.from_index] 257 | } 258 | param['value'] = connection 259 | } 260 | 261 | node.temp_params[input_definition.code] = param 262 | } 263 | } 264 | } 265 | 266 | function remove_graph_node(node) { 267 | for (var i in node.connections) { 268 | node.remove_connection(i) 269 | } 270 | var index 271 | for (var i in nodes) { 272 | var _node = nodes[i] 273 | if (_node === node) { 274 | index = i 275 | continue 276 | } 277 | for (var j in _node.connections) { 278 | if (_node.connections[j] !== null && _node.connections[j].from_node === node) { 279 | _node.remove_connection(j) 280 | } 281 | } 282 | } 283 | 284 | nodes.splice(index, 1) 285 | 286 | node.destroy() 287 | } 288 | 289 | function remove_all_nodes() { 290 | while (nodes.length > 0) { 291 | remove_graph_node(nodes[0]) 292 | } 293 | } 294 | 295 | function start_dragging_connection(from_node, from_index) { 296 | dragging_connection.from_node = from_node 297 | graphDisplay.from_node = from_node 298 | graphDisplay.from_index = from_index 299 | dragging_mouse_area.from_point = from_node.get_output_point(from_index) 300 | dragging_mouse_area.dragging = true 301 | } 302 | 303 | function end_dragging_connection(to_node, to_index) { 304 | to_node.set_connection(from_node, from_index, to_index) 305 | } 306 | 307 | function add_connection_visual(from_node, from_index, to_node, to_index) { 308 | return connection_component.createObject( 309 | view, 310 | { 311 | 'from_node': from_node, 312 | 'from_index': from_index, 313 | 'to_node': to_node, 314 | 'to_index': to_index, 315 | } 316 | ) 317 | } 318 | 319 | Component.onCompleted: { 320 | 321 | } 322 | 323 | MouseArea { 324 | anchors.fill: parent 325 | drag.target: view 326 | 327 | acceptedButtons: Qt.LeftButton | Qt.RightButton 328 | 329 | onWheel: function (event) { 330 | var old_scale = view_scale 331 | view_scale = clamp(view_scale + event.angleDelta.y / 360.0 * view_scale_rate, view_scale_min, view_scale_max) 332 | view.x = lerp(event.x, view.x, view_scale / old_scale) 333 | view.y = lerp(event.y, view.y, view_scale / old_scale) 334 | } 335 | 336 | onClicked: function (event) { 337 | if (event.button === Qt.RightButton) { 338 | right_click_menu.open() 339 | right_click_menu.x = event.x - 10 340 | right_click_menu.y = event.y - 10 341 | 342 | last_right_click_x = (event.x - offset_x) / view_scale; 343 | last_right_click_y = (event.y - offset_y) / view_scale; 344 | return 345 | } 346 | } 347 | } 348 | 349 | Item { 350 | id: view 351 | width: 100 352 | height: 100 353 | 354 | transform: Scale { 355 | xScale: view_scale 356 | yScale: view_scale 357 | } 358 | 359 | Connection { 360 | id: dragging_connection 361 | visible: false 362 | enabled: visible 363 | } 364 | } 365 | 366 | MouseArea { 367 | id: dragging_mouse_area 368 | enabled: true 369 | anchors.fill: parent 370 | propagateComposedEvents: true 371 | hoverEnabled: dragging 372 | property var from_point: null 373 | property bool dragging: false 374 | property real last_click_x: 0 375 | property real last_click_y: 0 376 | 377 | onDraggingChanged: { 378 | if (dragging) { 379 | 380 | dragging_connection.visible = true 381 | dragging_connection.canvas_rect = dragging_connection.get_canvas_rect( 382 | from_point, {x: last_click_x, y: last_click_y}) 383 | entered({accepted: true}) 384 | } 385 | else { 386 | 387 | } 388 | } 389 | 390 | onPressed: function (event) { 391 | last_click_x = (event.x - offset_x) / view_scale; 392 | last_click_y = (event.y - offset_y) / view_scale; 393 | if (!dragging) { 394 | target_set = false 395 | event.accepted = false 396 | } 397 | else { 398 | dragging_connection.visible = dragging = false 399 | target_set = true 400 | event.accepted = false 401 | } 402 | } 403 | 404 | onReleased: { 405 | 406 | } 407 | 408 | onPositionChanged: function (event) { 409 | if (dragging) { 410 | dragging_connection.canvas_rect = dragging_connection.get_canvas_rect( 411 | from_point, { 412 | x: (event.x - offset_x) / view_scale, 413 | y: (event.y - offset_y) / view_scale, 414 | }) 415 | } 416 | event.accepted = false; 417 | } 418 | } 419 | 420 | Menu { 421 | id: right_click_menu 422 | y: 0 423 | 424 | MenuItem { 425 | text: qsTr('New Node...') 426 | 427 | onTriggered: { 428 | new_node_dialog.open() 429 | } 430 | } 431 | } 432 | 433 | NewNodeDialog { 434 | id: new_node_dialog 435 | } 436 | 437 | CodeEditDialog { 438 | id: code_edit_dialog 439 | } 440 | 441 | ConsoleDialog { 442 | id: console_dialog 443 | } 444 | LoadingDialog { 445 | id: loading_dialog 446 | } 447 | HelpDialog { 448 | id: help_dialog 449 | } 450 | } 451 | -------------------------------------------------------------------------------- /TensorBuilder/GraphNode.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | import QtQuick.Layouts 1.3 3 | import QtQuick.Controls 2.2 4 | import QtGraphicalEffects 1.0 5 | 6 | Rectangle { 7 | id: node 8 | color: '#e0e0e0' 9 | 10 | //width: childrenRect.height 11 | width: 300 12 | height: childrenRect.height 13 | 14 | property var definition: null 15 | property var connections: [] 16 | property var connections_visual: [] 17 | property var input_values: [] 18 | property var input_visuals: null 19 | 20 | property var temp_names: [] 21 | property var temp_params: ({}) 22 | property var temp_declared: false 23 | 24 | readonly property real title_height: 40 25 | readonly property real input_height: 60 26 | readonly property real output_height: 30 27 | 28 | onDefinitionChanged: { 29 | if (definition !== null) { 30 | input_list_model.clear() 31 | connections = [] 32 | connections_visual = [] 33 | input_values = [] 34 | for (var i in definition['inputs']) { 35 | var input_definition = definition['inputs'][i] 36 | input_list_model.append({'definition': input_definition, 'index': i}) 37 | connections.push(null) 38 | connections_visual.push(null) 39 | input_values.push(input_definition.default) 40 | } 41 | output_list_model.clear() 42 | for (var i in definition['outputs']) { 43 | output_list_model.append({'definition': definition['outputs'][i], 'index': i}) 44 | } 45 | } 46 | } 47 | 48 | Timer { 49 | interval: 500 50 | repeat: true 51 | running: true 52 | onTriggered: { 53 | set_input_values(input_values) 54 | } 55 | } 56 | 57 | function set_input_values(data) { 58 | for (var i = 0; i < data.length; ++i) { 59 | input_values[i] = data[i] 60 | 61 | if (input_visuals[i] && input_visuals[i].set_value) { 62 | input_visuals[i].set_value(data[i]) 63 | } 64 | } 65 | } 66 | 67 | function get_input_point(index) { 68 | return { 69 | 'x': x + 0, 70 | 'y': y + title_height + index * input_height, 71 | } 72 | } 73 | function get_output_point(index) { 74 | return { 75 | 'x': x + width, 76 | 'y': y + title_height + index * output_height, 77 | } 78 | } 79 | 80 | function set_connection(from_node, from_index, index) { 81 | if (definition.inputs[index].type !== 'reference') return 82 | 83 | if (connections[index] !== null) { 84 | remove_connection(index) 85 | } 86 | 87 | var connection = { 88 | 'from_node': from_node, 89 | 'from_index': from_index, 90 | } 91 | 92 | connections[index] = connection 93 | 94 | connections_visual[index] = graphDisplay.add_connection_visual(from_node, from_index, node, index) 95 | 96 | } 97 | 98 | function remove_connection(index) { 99 | if (connections[index] === null) return 100 | 101 | connections_visual[index].destroy() 102 | connections[index] = null 103 | } 104 | 105 | function get_declaration() { 106 | if (node.temp_declared) return [] 107 | node.temp_declared = true 108 | 109 | var lines = [] 110 | for (var i in connections) { 111 | var connection = connections[i] 112 | if (connection) { 113 | extend_array(lines, connection.from_node.get_declaration()) 114 | } 115 | } 116 | 117 | extend_array(lines, main.declarers[definition.declarer](node)) 118 | return lines 119 | } 120 | 121 | function get_execution() { 122 | var lines = node.get_declaration() 123 | 124 | extend_array(lines, main.executers[definition.executer](node)) 125 | return lines 126 | } 127 | 128 | MouseArea { 129 | anchors.fill: parent 130 | drag.target: parent 131 | acceptedButtons: Qt.LeftButton | Qt.RightButton 132 | 133 | onClicked: function (event) { 134 | if (event.button === Qt.RightButton) { 135 | right_click_menu.open() 136 | right_click_menu.x = event.x - 10 137 | right_click_menu.y = event.y - 10 138 | return 139 | } 140 | } 141 | 142 | Menu { 143 | id: right_click_menu 144 | y: 0 145 | 146 | MenuItem { 147 | text: qsTr('Delete') 148 | 149 | onTriggered: { 150 | graphDisplay.remove_graph_node(node) 151 | } 152 | } 153 | 154 | MenuItem { 155 | text: qsTr('Run') 156 | 157 | onTriggered: { 158 | graphDisplay.run_node(node) 159 | } 160 | } 161 | } 162 | } 163 | 164 | ColumnLayout { 165 | anchors.left: parent.left 166 | anchors.right: parent.right 167 | 168 | spacing: 0 169 | 170 | Rectangle { 171 | color: definition === null ? 'black' : definition.color 172 | border.width: 2 173 | border.color: '#ffffff' 174 | 175 | Layout.fillWidth: true 176 | height: title_height 177 | 178 | MyLabel { 179 | id: title 180 | anchors.left: parent.left 181 | anchors.leftMargin: 10 182 | text: definition === null ? '' : definition['title'] 183 | color: '#ffffff' 184 | } 185 | } 186 | 187 | RowLayout { 188 | Layout.minimumWidth: 10 189 | Layout.maximumWidth: 65536 190 | spacing: 0 191 | ListView { 192 | id: input_list_view 193 | height: input_height * count 194 | width: 300 195 | Layout.alignment: Qt.AlignTop 196 | 197 | interactive: false 198 | 199 | model: ListModel { 200 | id: input_list_model 201 | } 202 | 203 | delegate: Item { 204 | id: input_list_delegate 205 | height: input_height 206 | width: 150 207 | 208 | Component.onCompleted: { 209 | if (!node.input_visuals) { 210 | node.input_visuals = [] 211 | } 212 | while (node.input_visuals.length <= index) { 213 | node.input_visuals.push(null) 214 | } 215 | node.input_visuals[index] = this 216 | } 217 | 218 | function set_value(value) { 219 | var i = 0; 220 | for (i = 0; i < main.types.length; ++i) { 221 | if (main.types[i].code === value) { 222 | combo_box.currentIndex = i 223 | } 224 | } 225 | 226 | if (!value) { 227 | value = '' 228 | } 229 | else { 230 | value = value.toString() 231 | } 232 | 233 | input_literal_field.text = value 234 | } 235 | 236 | Button { 237 | height: parent.height + 10 238 | y: -5 239 | width: 150 240 | flat: true 241 | 242 | onPressed: function (event) { 243 | if (graphDisplay.target_set) { 244 | graphDisplay.end_dragging_connection(node, index) 245 | } 246 | else { 247 | if (node.connections[index]) { 248 | var from_node = node.connections[index].from_node 249 | var from_index = node.connections[index].from_index 250 | 251 | node.remove_connection(index) 252 | 253 | graphDisplay.start_dragging_connection(from_node, from_index) 254 | } 255 | } 256 | } 257 | } 258 | 259 | ColumnLayout { 260 | anchors.fill: parent 261 | anchors.leftMargin: 10 262 | anchors.rightMargin: 10 263 | spacing: 0 264 | 265 | MyLabel { 266 | anchors.top: parent.top 267 | width: 50 268 | height: 30 269 | text: definition.name 270 | } 271 | 272 | ComboBox { 273 | id: combo_box 274 | 275 | Layout.fillHeight: true 276 | Layout.fillWidth: true 277 | Layout.minimumWidth: 10 278 | Layout.maximumWidth: 65536 279 | visible: definition.type === 'type' 280 | model: { 281 | var result = [] 282 | for (var i in main.types) { 283 | result.push(main.types[i]['code']) 284 | } 285 | 286 | return result 287 | } 288 | 289 | onActivated: function (i) { 290 | if (!visible) return 291 | input_values[index] = model[i] 292 | } 293 | } 294 | 295 | 296 | TextField { 297 | id: input_literal_field 298 | 299 | height: 22 300 | Layout.fillWidth: true 301 | Layout.minimumWidth: 10 302 | Layout.maximumWidth: 65536 303 | visible: definition.type === 'string' || definition.type === 'number' 304 | selectByMouse: true 305 | placeholderText: qsTr('(input)') 306 | 307 | onTextChanged: { 308 | if (!visible) return 309 | input_values[index] = text 310 | } 311 | } 312 | 313 | MyButton { 314 | height: 30 315 | Layout.fillWidth: true 316 | Layout.minimumWidth: 10 317 | Layout.maximumWidth: 65536 318 | visible: definition.type === 'code' 319 | text: qsTr('Edit') 320 | 321 | onClicked: { 322 | graphDisplay.show_code_editor(node, index) 323 | } 324 | } 325 | 326 | MyLabel { 327 | height: 30 328 | anchors.verticalCenter: undefined 329 | Layout.fillWidth: true 330 | Layout.fillHeight: true 331 | Layout.minimumWidth: 10 332 | Layout.maximumWidth: 65536 333 | visible: definition.type === 'reference' 334 | text: qsTr('(reference)') 335 | font.pixelSize: 14 336 | color: 'gray' 337 | } 338 | } 339 | 340 | } 341 | } 342 | 343 | ListView { 344 | id: output_list_view 345 | height: output_height * count 346 | width: 300 347 | Layout.alignment: Qt.AlignTop 348 | 349 | interactive: false 350 | 351 | model: ListModel { 352 | id: output_list_model 353 | } 354 | 355 | delegate: Item { 356 | height: output_height 357 | 358 | Button { 359 | height: parent.height + 10 360 | y: -5 361 | width: 150 362 | x: -width 363 | 364 | onPressed: { 365 | graphDisplay.start_dragging_connection(node, index) 366 | } 367 | onReleased: { 368 | 369 | } 370 | } 371 | 372 | MyLabel { 373 | anchors.fill: parent 374 | anchors.rightMargin: 10 375 | text: definition.name 376 | horizontalAlignment: Text.AlignRight 377 | } 378 | } 379 | } 380 | } 381 | } 382 | 383 | Rectangle { 384 | anchors.fill: parent 385 | color: 'transparent' 386 | border.width: 2 387 | border.color: '#a0a0a0' 388 | } 389 | 390 | } 391 | -------------------------------------------------------------------------------- /TensorBuilder/HelpDialog.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | import QtQuick.Controls 2.2 3 | import QtQuick.Layouts 1.3 4 | 5 | MyDialog { 6 | id: help_dialog 7 | modal: true 8 | 9 | title: { 10 | return qsTr('Help') 11 | } 12 | 13 | standardButtons: Dialog.Ok 14 | 15 | property bool is_running: false 16 | 17 | 18 | width: 600 19 | height: parent.height * 0.75 20 | 21 | property var node 22 | property int index 23 | 24 | Rectangle { 25 | anchors.fill: parent 26 | color: '#dddddd' 27 | 28 | ScrollView { 29 | anchors.fill: parent 30 | anchors.margins: 10 31 | clip: true 32 | 33 | TextArea { 34 | id: text_area 35 | text: qsTr("- To start, right click on the canvas and select .\n- Drag to replace the nodes.\n- Click on output ports of nodes to start connecting, then click on destination input port.\n- Right click on a node to delete or execute.\n\n- On the bottom-left, you can name your model and upload to community.\n- Click on uploaded models to start editing.") 36 | selectByKeyboard: true 37 | selectByMouse: true 38 | readOnly: true 39 | 40 | font.pixelSize: 22 41 | 42 | wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere 43 | } 44 | } 45 | } 46 | 47 | Rectangle { 48 | anchors.fill: parent 49 | color: 'transparent' 50 | border.width: 2 51 | border.color: '#a0a0a0' 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /TensorBuilder/LoadingDialog.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | import QtQuick.Controls 2.2 3 | import QtQuick.Layouts 1.3 4 | 5 | MyDialog { 6 | id: loading_dialog 7 | modal: true 8 | 9 | title: '' 10 | closePolicy: Popup.NoAutoClose 11 | 12 | 13 | width: 200 14 | height: 100 15 | 16 | MyLabel { 17 | anchors.centerIn: parent 18 | font.bold: true 19 | font.pixelSize: 28 20 | text: qsTr('Loading...') 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /TensorBuilder/ModelBrowser.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | import QtQuick.Controls 2.2 3 | 4 | Item { 5 | 6 | Rectangle{ 7 | color: "#a0a0a0" 8 | anchors.fill: parent 9 | } 10 | 11 | function loadModels(newname) { 12 | model_list_model.clear() 13 | loading_text.text = "loading..."; 14 | var http = new XMLHttpRequest() 15 | var url = "http://34.234.84.109:3000/models"; 16 | http.open("GET", url, true); 17 | 18 | http.onreadystatechange = function() { // Call a function when the state changes. 19 | var definitions = []; 20 | if (http.readyState == 4) { 21 | if (http.status == 200) { 22 | loading_text.text = ""; 23 | var jsondata = JSON.parse(http.responseText) 24 | for (var i = 0; i < jsondata.length; i++) { 25 | definitions.push({"name":jsondata[i]["name"]}) 26 | } 27 | if (newname) { 28 | // make sure the name isn't already in the list 29 | var found = false 30 | newname = newname.toUpperCase() 31 | for (var i = 0; i < definitions.length; i++){ 32 | if (definitions[i]["name"] === newname){ 33 | found = true 34 | } 35 | } 36 | // if we didn't find the name already, then add it to the list 37 | if (!found) definitions.push({"name":newname}) 38 | } 39 | } else { 40 | console.log("error: " + http.status) 41 | } 42 | } 43 | model_list_view.fillModels(definitions); 44 | } 45 | http.send(); 46 | } 47 | 48 | // returns a JSON representationof the nodes 49 | function loadModel(name){ 50 | name_field.text = name 51 | var http = new XMLHttpRequest() 52 | var url = "http://34.234.84.109:3000/models/" + name; 53 | http.open("GET", url, true); 54 | 55 | main.graphDisplay.show_loading(true) 56 | 57 | http.onreadystatechange = function() { // Call a function when the state changes. 58 | var definitions = []; 59 | if (http.readyState == 4) { 60 | if (http.status == 200) { 61 | var jsondata = JSON.parse(http.responseText) 62 | var nodelist = [] 63 | for (var i = 0; i < jsondata["nodes"].length; i++) { 64 | var nodedata = JSON.parse(jsondata["nodes"][i]) 65 | nodelist.push(nodedata) 66 | } 67 | loadNodes(nodelist) 68 | } else { 69 | console.log("error: " + http.status) 70 | } 71 | } 72 | 73 | main.graphDisplay.show_loading(false) 74 | } 75 | http.send(); 76 | } 77 | 78 | function loadNodes(nodelist) { 79 | // clear all current nodes first 80 | main.graphDisplay.remove_all_nodes() 81 | // loop through the node list to add each node to the graph 82 | for (var i = 0; i < nodelist.length; i++){ 83 | for (var j = 0; j < main.definitions.length; j++){ 84 | if (main.definitions[j]['title'] === nodelist[i]['definition']){ 85 | var node = graphDisplay.add_graph_node(main.definitions[j]) 86 | if (nodelist[i]['input_values']) { 87 | node.set_input_values(nodelist[i]['input_values']) 88 | } 89 | node.x = nodelist[i]['x'] 90 | node.y = nodelist[i]['y'] 91 | } 92 | } 93 | } 94 | // loop through the nodes again but this time to add connections 95 | var nodes = main.graphDisplay.nodes 96 | for (var k = 0; k < nodelist.length; k++){ 97 | var connections = nodelist[k]['connections'] 98 | // loop through and set each connection 99 | for (var l = 0; l < connections.length; l++) { 100 | if (connections[l]){ 101 | var targetIndex = -1 102 | for (var key in connections[l]){ 103 | targetIndex = key 104 | } 105 | nodes[k].set_connection(nodes[targetIndex], connections[l][key], l) 106 | } 107 | } 108 | } 109 | } 110 | 111 | Component.onCompleted: { 112 | loadModels() 113 | } 114 | 115 | Rectangle { 116 | id: exposition_rect 117 | anchors.top: parent.top 118 | height:50; 119 | width: parent.width 120 | color: main.color_blue 121 | 122 | MyLabel { 123 | anchors.verticalCenter: parent.verticalCenter 124 | anchors.right: parent.right 125 | anchors.left: parent.left 126 | anchors.rightMargin: 40 127 | text: "Community Models" 128 | font.pixelSize: 25 129 | color: '#ffffff' 130 | horizontalAlignment: Text.AlignHCenter 131 | } 132 | 133 | RoundButton { 134 | anchors.right: parent.right 135 | anchors.rightMargin: 10 136 | anchors.verticalCenter: parent.verticalCenter 137 | text: '\u21bb' 138 | antialiasing: true 139 | font.pixelSize: 20 140 | font.bold: false 141 | 142 | onClicked: loadModels() 143 | } 144 | } 145 | 146 | Rectangle{ 147 | color: "transparent" 148 | anchors.top: exposition_rect.bottom 149 | width: parent.width 150 | anchors.bottom: lower_rect.top 151 | 152 | Text { 153 | id: loading_text 154 | font.pointSize: 22 155 | color: "white" 156 | 157 | width: parent.width 158 | height: 60 159 | y: 30 160 | horizontalAlignment: Text.AlignHCenter 161 | } 162 | 163 | ListView{ 164 | id: model_list_view 165 | anchors.fill: parent 166 | 167 | interactive: true 168 | clip: true 169 | 170 | function fillModels(definitions) { 171 | for (var i in definitions) { 172 | model_list_model.append({'definition': definitions[i]}) 173 | // console.log(definitions[i]["name"]) 174 | } 175 | } 176 | 177 | model: ListModel{ 178 | id: model_list_model 179 | } 180 | 181 | delegate: Button { 182 | height: 80 183 | width: parent.width 184 | flat: false 185 | 186 | MouseArea { 187 | anchors.fill: parent 188 | onClicked: loadModel(definition["name"]) 189 | } 190 | 191 | text: definition["name"] 192 | font.pixelSize: 25 193 | } 194 | 195 | ScrollBar.vertical: ScrollBar { 196 | active: true 197 | } 198 | } 199 | } 200 | 201 | function uploadModel() { 202 | var graphnodes = main.graphDisplay.nodes 203 | var finalnodes = [] 204 | // fill a JSON structure with node info 205 | for (var i = 0; i < graphnodes.length; i++){ 206 | var node = graphnodes[i] 207 | var nodejson = {} 208 | // let the ID of each node just be their index in the array 209 | nodejson['ID'] = i 210 | nodejson['definition'] = node.definition["title"] 211 | nodejson['x'] = node.x 212 | nodejson['y'] = node.y 213 | var connections = node.connections 214 | var connectionarray = [] 215 | for (var j = 0; j < connections.length; j++){ 216 | if (connections[j]){ 217 | var connectionnode = connections[j]['from_node'] 218 | var connectionelement = {} 219 | for (var k = 0; k < graphnodes.length; k++){ 220 | if (connectionnode === graphnodes[k]){ 221 | connectionelement[k] = connections[j]['from_index'] 222 | } 223 | } 224 | connectionarray.push(connectionelement) 225 | }else{ 226 | connectionarray.push(null) 227 | } 228 | } 229 | nodejson['connections'] = connectionarray 230 | nodejson['input_values'] = node.input_values 231 | finalnodes.push(JSON.stringify(nodejson)) 232 | } 233 | 234 | var http = new XMLHttpRequest() 235 | var url = "http://34.234.84.109:3000/addmodel"; 236 | http.open("POST", url, true); 237 | http.setRequestHeader("Content-type", "application/json"); 238 | 239 | http.onreadystatechange = function() { // Call a function when the state changes. 240 | if (http.readyState == 4) { 241 | if (http.status == 200) { 242 | console.log("success!") 243 | } else { 244 | console.log("error: " + http.status) 245 | } 246 | } 247 | // load the model list again after post has gone through 248 | } 249 | var name = name_field.text !== "" ? name_field.text : "default" 250 | var data = { 251 | "name" : name.toUpperCase(), 252 | "nodes" : finalnodes 253 | } 254 | http.send(JSON.stringify(data)) 255 | loadModels(name) 256 | } 257 | 258 | Rectangle { 259 | id: lower_rect 260 | anchors.bottom: upload_button.top 261 | width: parent.width 262 | height: 60 263 | color: '#666666' 264 | TextField { 265 | id: name_field 266 | placeholderText: "name" 267 | anchors.fill: parent 268 | anchors.verticalCenter: parent.verticalCenter 269 | 270 | font.pointSize: 20 271 | color: '#ffffff' 272 | 273 | horizontalAlignment: Text.AlignHCenter 274 | selectByMouse: true 275 | } 276 | } 277 | 278 | Button { 279 | id: upload_button 280 | anchors.bottom: parent.bottom 281 | height:60; 282 | width: parent.width 283 | 284 | text: qsTr("Save & Upload") 285 | font.pixelSize: 22 286 | 287 | onClicked: uploadModel() 288 | } 289 | 290 | Rectangle { 291 | id: borderRight 292 | width: 2 293 | height: parent.height 294 | anchors.right: parent.right 295 | color: "#878f9b" 296 | } 297 | 298 | } 299 | -------------------------------------------------------------------------------- /TensorBuilder/MyButton.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | import QtQuick.Controls 2.2 3 | 4 | Rectangle { 5 | id: root 6 | 7 | //property bool customColor: false; 8 | 9 | property color buttonColor: "#eeeeee" 10 | 11 | property color idleColor 12 | property color hoverColor 13 | property color pressedColor 14 | 15 | property color currentColor 16 | property color borderColor 17 | property color textColor 18 | 19 | property bool bold: false 20 | /* 21 | property color disabledColor//: "#cccccc" 22 | property color disabledBorderColor//: "#888888" 23 | property color disabledTextColor//: "#888888" 24 | */ 25 | property color disabledColor: Qt.tint(currentColor, disabledTinting); 26 | property color disabledBorderColor: Qt.tint(borderColor, disabledTinting); 27 | property color disabledTextColor: Qt.tint(textColor, disabledTinting); 28 | 29 | property color disabledTinting: "#88888888"; 30 | 31 | property real idleBorderWidth: 1 32 | property real hoverBorderWidth: 2 33 | property real pressedBorderWidth: 1.5 34 | 35 | enabled: visible 36 | 37 | height: 20 38 | 39 | Behavior on color { 40 | id: colorAnimation 41 | ColorAnimation{duration: 60; easing.type: Easing.Linear} 42 | } 43 | 44 | property alias text: txt.text; 45 | property alias label: txt; 46 | 47 | function autoRefreshColor() { 48 | //if (customColor) return; 49 | 50 | var _hsl = main.hsl(buttonColor.r, buttonColor.g, buttonColor.b); 51 | var luma = main.luma(buttonColor.r, buttonColor.g, buttonColor.b); 52 | 53 | textColor = luma > 0.6 ? "#ff000000" : "#ffffffff"; 54 | 55 | var hsl = {h:_hsl.h, s:_hsl.s, l:_hsl.l}; 56 | hsl.l = luma > 0.5 ? hsl.l - 0.2 : hsl.l + 0.3; 57 | hsl.s *= 0.75; 58 | borderColor = Qt.hsla(hsl.h, hsl.s, hsl.l, 1.0); 59 | 60 | idleColor = buttonColor; 61 | 62 | hsl = {h:_hsl.h, s:_hsl.s, l:_hsl.l}; 63 | 64 | hoverColor = idleColor; 65 | //if (hsl.l < 0.25) { 66 | /* 67 | hoverColor.r = 1.0 - (1.0 - idleColor.r) * 0.8; 68 | hoverColor.g = 1.0 - (1.0 - idleColor.g) * 0.8; 69 | hoverColor.b = 1.0 - (1.0 - idleColor.b) * 0.8; 70 | //*/ 71 | //hoverColor = Qt.hsla(hsl.h, hsl.s, 1.0 - (1.0 - hsl.l) * 0.8, 1.0); 72 | //hoverColor = Qt.hsla(hsl.h, hsl.s, hsl.l + 0.2, 1.0); 73 | //} 74 | /* 75 | hoverColor.r *= 1.2; 76 | hoverColor.g *= 1.2; 77 | hoverColor.b *= 1.2; 78 | */ 79 | //else { 80 | /* 81 | hoverColor.r += 0.1; 82 | hoverColor.g += 0.1; 83 | hoverColor.b += 0.1; 84 | //*/ 85 | //} 86 | hoverColor = Qt.hsla(hsl.h, hsl.s, hsl.l + 0.1, 1.0); 87 | 88 | pressedColor = idleColor; 89 | /* 90 | pressedColor.r *= 0.9; 91 | pressedColor.g *= 0.9; 92 | pressedColor.b *= 0.9; 93 | */ 94 | pressedColor = Qt.hsla(hsl.h, hsl.s, hsl.l - 0.05, 1.0); 95 | 96 | if (hsl.l > 0.95) { 97 | var _r = pressedColor.r; 98 | var _g = pressedColor.g; 99 | var _b = pressedColor.b; 100 | pressedColor = hoverColor; 101 | hoverColor.r = _r; 102 | hoverColor.g = _g; 103 | hoverColor.b = _b; 104 | } 105 | 106 | visualEventHandler(); 107 | } 108 | 109 | function visualEventHandler () { 110 | if (mouse.pressed) { 111 | root.currentColor = root.pressedColor 112 | root.border.width = root.pressedBorderWidth 113 | } 114 | else if (mouse.containsMouse){ 115 | root.currentColor = root.hoverColor 116 | root.border.width = root.hoverBorderWidth 117 | } 118 | else { 119 | root.currentColor = root.idleColor 120 | root.border.width = root.idleBorderWidth 121 | } 122 | } 123 | 124 | onButtonColorChanged: function (){ 125 | colorAnimation.enabled = false; 126 | autoRefreshColor(); 127 | colorAnimation.enabled = true; 128 | } 129 | 130 | Component.onCompleted: { 131 | autoRefreshColor(); 132 | } 133 | 134 | color: enabled ? currentColor : disabledColor 135 | border.color: enabled ? borderColor : disabledBorderColor 136 | 137 | signal clicked(var button); 138 | 139 | MouseArea { 140 | id: mouse 141 | anchors.fill: parent 142 | hoverEnabled: true 143 | acceptedButtons: Qt.LeftButton 144 | onClicked: root.clicked(root); 145 | 146 | onContainsMouseChanged: root.visualEventHandler() 147 | onPressedChanged: root.visualEventHandler() 148 | 149 | onPositionChanged: { 150 | 151 | } 152 | } 153 | 154 | Label { 155 | id: txt 156 | text: root.text 157 | color: root.enabled ? textColor : disabledTextColor; 158 | font.bold: bold 159 | anchors.centerIn: parent; 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /TensorBuilder/MyDialog.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | import QtQuick.Controls 2.2 3 | 4 | Dialog { 5 | x: (parent.width - width) / 2 6 | y: (parent.height - height) / 2 7 | } 8 | -------------------------------------------------------------------------------- /TensorBuilder/MyLabel.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | import QtQuick.Controls 2.2 3 | 4 | Label { 5 | text: "" 6 | font.pixelSize: 20 7 | 8 | anchors.verticalCenter: parent.verticalCenter 9 | } 10 | -------------------------------------------------------------------------------- /TensorBuilder/NewNodeDialog.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | import QtQuick.Controls 2.2 3 | 4 | MyDialog { 5 | id: new_node_dialog 6 | modal: true 7 | 8 | title: qsTr("New Node") 9 | // standardButtons: Dialog.Ok | Dialog.Cancel 10 | 11 | // onAccepted: console.log("Ok clicked") 12 | // onRejected: console.log("Cancel clicked") 13 | 14 | width: 450 15 | height: parent.height * 0.8 16 | 17 | Rectangle { 18 | anchors.fill: parent 19 | color: '#dddddd' 20 | 21 | ListView { 22 | id: new_node_list_view 23 | anchors.fill: parent 24 | 25 | interactive: true 26 | clip: true 27 | 28 | Component.onCompleted: { 29 | for (var i in main.definitions) { 30 | new_node_list_model.append({'definition': main.definitions[i]}) 31 | } 32 | } 33 | 34 | model: ListModel { 35 | id: new_node_list_model 36 | } 37 | 38 | delegate: MyButton { 39 | height: 50 40 | width: parent.width 41 | 42 | text: definition.title 43 | buttonColor: definition.color 44 | 45 | bold: true 46 | 47 | onClicked: { 48 | var node = add_graph_node(definition) 49 | node.x = last_right_click_x 50 | node.y = last_right_click_y 51 | new_node_dialog.close() 52 | } 53 | } 54 | 55 | ScrollBar.vertical: ScrollBar { 56 | active: true 57 | } 58 | } 59 | } 60 | 61 | Rectangle { 62 | anchors.fill: parent 63 | color: 'transparent' 64 | border.width: 2 65 | border.color: '#a0a0a0' 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /TensorBuilder/Page1.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.7 2 | 3 | Page1Form { 4 | button1.onClicked: { 5 | console.log("Button Pressed. Entered text: " + textField1.text); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /TensorBuilder/Page1Form.ui.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.7 2 | import QtQuick.Controls 2.0 3 | import QtQuick.Layouts 1.3 4 | 5 | Item { 6 | property alias textField1: textField1 7 | property alias button1: button1 8 | 9 | RowLayout { 10 | anchors.horizontalCenter: parent.horizontalCenter 11 | anchors.topMargin: 20 12 | anchors.top: parent.top 13 | 14 | TextField { 15 | id: textField1 16 | placeholderText: qsTr("Text Field") 17 | } 18 | 19 | Button { 20 | id: button1 21 | text: qsTr("Press Me") 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /TensorBuilder/SelectionPanel.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Item { 4 | Rectangle { 5 | color: '#bbbbbb' 6 | anchors.fill: parent 7 | } 8 | 9 | Rectangle { 10 | color: 'transparent' 11 | anchors.fill: parent 12 | border.width: 2 13 | border.color: '#a0a0a0' 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /TensorBuilder/TensorBuilder.pro: -------------------------------------------------------------------------------- 1 | QT += quick 2 | CONFIG += c++11 3 | 4 | # The following define makes your compiler emit warnings if you use 5 | # any feature of Qt which as been marked deprecated (the exact warnings 6 | # depend on your compiler). Please consult the documentation of the 7 | # deprecated API in order to know how to port your code away from it. 8 | DEFINES += QT_DEPRECATED_WARNINGS 9 | 10 | # You can also make your code fail to compile if you use deprecated APIs. 11 | # In order to do so, uncomment the following line. 12 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 13 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 14 | 15 | SOURCES += main.cpp \ 16 | native.cpp 17 | 18 | RESOURCES += qml.qrc 19 | 20 | # Additional import path used to resolve QML modules in Qt Creator's code model 21 | QML_IMPORT_PATH = 22 | 23 | # Additional import path used to resolve QML modules just for Qt Quick Designer 24 | QML_DESIGNER_IMPORT_PATH = 25 | 26 | # Default rules for deployment. 27 | qnx: target.path = /tmp/$${TARGET}/bin 28 | else: unix:!android: target.path = /opt/$${TARGET}/bin 29 | !isEmpty(target.path): INSTALLS += target 30 | 31 | HEADERS += \ 32 | native.h 33 | -------------------------------------------------------------------------------- /TensorBuilder/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "native.h" 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 9 | QGuiApplication app(argc, argv); 10 | 11 | QQmlApplicationEngine engine; 12 | engine.load(QUrl(QLatin1String("qrc:/main.qml"))); 13 | if (engine.rootObjects().isEmpty()) 14 | return -1; 15 | 16 | Native native; 17 | 18 | native.init(app, engine); 19 | 20 | 21 | return app.exec(); 22 | } 23 | -------------------------------------------------------------------------------- /TensorBuilder/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.7 2 | import QtQuick.Controls 2.0 3 | import QtQuick.Layouts 1.3 4 | import QtGraphicalEffects 1.0 5 | 6 | ApplicationWindow { 7 | id: main 8 | visible: true 9 | width: 1024 10 | height: 768 11 | title: qsTr("TensorBuilder") 12 | property alias graphDisplay: graphDisplay 13 | 14 | property var types: [ 15 | { 16 | 'code': 'tf.float32', 17 | }, 18 | { 19 | 'code': 'tf.float16', 20 | }, 21 | { 22 | 'code': 'tf.float64', 23 | }, 24 | // { 25 | // 'code': 'tf.bfloat16', 26 | // }, 27 | { 28 | 'code': 'tf.complex64', 29 | }, 30 | { 31 | 'code': 'tf.complex128', 32 | }, 33 | { 34 | 'code': 'tf.int8', 35 | }, 36 | { 37 | 'code': 'tf.uint8', 38 | }, 39 | { 40 | 'code': 'tf.uint16', 41 | }, 42 | { 43 | 'code': 'tf.int16', 44 | }, 45 | { 46 | 'code': 'tf.int32', 47 | }, 48 | { 49 | 'code': 'tf.int64', 50 | }, 51 | { 52 | 'code': 'tf.bool', 53 | }, 54 | { 55 | 'code': 'tf.string', 56 | }, 57 | // { 58 | // 'code': 'tf.qint8', 59 | // }, 60 | // { 61 | // 'code': 'tf.quint8', 62 | // }, 63 | // { 64 | // 'code': 'tf.qint16', 65 | // }, 66 | // { 67 | // 'code': 'tf.quint16', 68 | // }, 69 | // { 70 | // 'code': 'tf.qint32', 71 | // }, 72 | // { 73 | // 'code': 'tf.resource', 74 | // }, 75 | ] 76 | 77 | readonly property string color_blue: '#3583d6' 78 | readonly property string color_red: '#fa6a35' 79 | readonly property string color_purple: '#aa6a95' 80 | readonly property string color_green: '#35ba6a' 81 | readonly property string color_grey: '#666666' 82 | 83 | property var declarers: { 84 | 'tf_node': function (node) { 85 | var lines = [] 86 | var line = node.temp_names[0] + ' = ' + node.definition.code + '(' 87 | var first = true 88 | for (var param_code in node.temp_params) { 89 | var param = node.temp_params[param_code] 90 | if (!first) { 91 | line += ', ' 92 | } 93 | else { 94 | first = false 95 | } 96 | line += param_code + '=(' + param.code_str + ')' 97 | } 98 | 99 | line += ')' 100 | lines.push(line) 101 | 102 | return lines 103 | }, 104 | 'mnist': function (node) { 105 | var lines = [ 106 | 'from tensorflow.examples.tutorials.mnist import input_data', 107 | 'mnist = input_data.read_data_sets("MNIST_data/", one_hot = True)', 108 | node.temp_names[0] + ', ' + node.temp_names[1] + ' = mnist.train.next_batch(1000)', 109 | node.temp_names[2] + ' = mnist.test.images', 110 | node.temp_names[3] + ' = mnist.test.labels', 111 | ] 112 | 113 | return lines 114 | }, 115 | 'global_var': function (node) { 116 | var lines = [ 117 | node.temp_names[0] + ' = None' 118 | ] 119 | return lines 120 | }, 121 | 'none': function (node) { 122 | return [] 123 | }, 124 | } 125 | 126 | property var executers: { 127 | 'tf_node': function (node) { 128 | var lines = [ 129 | '_ = session.run(' + node.temp_names[0] + ', feed_dict)', 130 | 'if _ is not None: print(\'' + (node.temp_params.name ? node.temp_params.name.value : '') + ': {0}\'.format(_))', 131 | ] 132 | 133 | return lines 134 | }, 135 | 'multi_exec': function (node) { 136 | var lines = [] 137 | for (var i in node.connections) { 138 | if (!node.connections[i]) continue 139 | extend_array(lines, node.connections[i].from_node.get_execution()) 140 | } 141 | 142 | return lines 143 | }, 144 | 'repeater': function (node) { 145 | var lines = [] 146 | lines.push('for i in range(' + node.temp_params.iterations.code_str + '):') 147 | if (node.temp_params.node.value) { 148 | var sub_lines = [] 149 | sub_lines.push('if i % 100 == 0: print(\'iteration {0}...\'.format(i))') 150 | extend_array(sub_lines, node.temp_params.node.value.from_node.get_execution()) 151 | add_prefix_strings(sub_lines, ' ') 152 | extend_array(lines, sub_lines) 153 | } 154 | 155 | return lines 156 | }, 157 | 'set_placeholder': function (node) { 158 | var lines = [ 159 | 'feed_dict[' + node.temp_params.name.code_str + ' + \':0\'] = ' + node.temp_params.value.code_str, 160 | ] 161 | 162 | return lines 163 | }, 164 | 'global_var': function (node) { 165 | var lines = [ 166 | 'if ' + node.temp_names[0] + ' is None: ' + node.temp_names[0] + ' = ' + node.definition.code + '()', 167 | 'session.run(' + node.temp_names[0] + ')', 168 | ] 169 | return lines 170 | }, 171 | 'none': function (node) { 172 | return [] 173 | }, 174 | } 175 | 176 | property var definitions: [ 177 | { 178 | 'title': 'Placeholder', 179 | 'color': color_blue, 180 | 'code': 'tf.placeholder', 181 | 'inputs': [ 182 | { 183 | 'name': 'Name', 184 | 'type': 'string', 185 | 'default': '', 186 | 'code': 'name', 187 | }, 188 | { 189 | 'name': 'Type', 190 | 'type': 'type', 191 | 'default': 'tf.float32', 192 | 'code': 'dtype', 193 | }, 194 | ], 195 | 'outputs': [ 196 | { 197 | 'name': 'Value', 198 | }, 199 | ], 200 | 'declarer': 'tf_node', 201 | 'executer': 'tf_node', 202 | }, 203 | { 204 | 'title': 'Uniform Random', 205 | 'color': color_blue, 206 | 'code': 'tf.random_uniform', 207 | 'inputs': [ 208 | { 209 | 'name': 'Shape', 210 | 'type': 'code', 211 | 'default': '[1]', 212 | 'code': 'shape', 213 | }, 214 | { 215 | 'name': 'Min', 216 | 'type': 'number', 217 | 'default': '0.0', 218 | 'code': 'minval', 219 | }, 220 | { 221 | 'name': 'Max', 222 | 'type': 'number', 223 | 'default': '1.0', 224 | 'code': 'maxval', 225 | }, 226 | ], 227 | 'outputs': [ 228 | { 229 | 'name': 'Value', 230 | }, 231 | ], 232 | 'declarer': 'tf_node', 233 | 'executer': 'tf_node', 234 | }, 235 | { 236 | 'title': 'Constant', 237 | 'color': color_blue, 238 | 'code': 'tf.constant', 239 | 'inputs': [ 240 | { 241 | 'name': 'Name', 242 | 'type': 'string', 243 | 'default': '', 244 | 'code': 'name', 245 | }, 246 | { 247 | 'name': 'Value', 248 | 'type': 'code', 249 | 'default': 1.0, 250 | 'code': 'value', 251 | }, 252 | { 253 | 'name': 'Type', 254 | 'type': 'type', 255 | 'default': 'tf.float32', 256 | 'code': 'dtype', 257 | }, 258 | ], 259 | 'outputs': [ 260 | { 261 | 'name': 'Value', 262 | }, 263 | ], 264 | 'declarer': 'tf_node', 265 | 'executer': 'tf_node', 266 | }, 267 | { 268 | 'title': 'Variable', 269 | 'color': color_blue, 270 | 'code': 'tf.Variable', 271 | 'inputs': [ 272 | { 273 | 'name': 'Name', 274 | 'type': 'string', 275 | 'default': '', 276 | 'code': 'name', 277 | }, 278 | { 279 | 'name': 'Init Value', 280 | 'type': 'reference', 281 | 'default': '', 282 | 'code': 'initial_value', 283 | }, 284 | { 285 | 'name': 'Type', 286 | 'type': 'type', 287 | 'default': 'tf.float32', 288 | 'code': 'dtype', 289 | }, 290 | ], 291 | 'outputs': [ 292 | { 293 | 'name': 'Value', 294 | }, 295 | ], 296 | 'declarer': 'tf_node', 297 | 'executer': 'tf_node', 298 | }, 299 | { 300 | 'title': 'Add', 301 | 'color': color_red, 302 | 'code': 'tf.add', 303 | 'inputs': [ 304 | { 305 | 'name': 'Name', 306 | 'type': 'string', 307 | 'default': '', 308 | 'code': 'name', 309 | }, 310 | { 311 | 'name': 'Input 1', 312 | 'type': 'reference', 313 | 'default': null, 314 | 'code': 'x', 315 | }, 316 | { 317 | 'name': 'Input 2', 318 | 'type': 'reference', 319 | 'default': null, 320 | 'code': 'y', 321 | }, 322 | ], 323 | 'outputs': [ 324 | { 325 | 'name': 'Result', 326 | }, 327 | ], 328 | 'declarer': 'tf_node', 329 | 'executer': 'tf_node', 330 | }, 331 | { 332 | 'title': 'Subtract', 333 | 'color': color_red, 334 | 'code': 'tf.subtract', 335 | 'inputs': [ 336 | { 337 | 'name': 'Name', 338 | 'type': 'string', 339 | 'default': '', 340 | 'code': 'name', 341 | }, 342 | { 343 | 'name': 'Input 1', 344 | 'type': 'reference', 345 | 'default': null, 346 | 'code': 'x', 347 | }, 348 | { 349 | 'name': 'Input 2', 350 | 'type': 'reference', 351 | 'default': null, 352 | 'code': 'y', 353 | }, 354 | ], 355 | 'outputs': [ 356 | { 357 | 'name': 'Result', 358 | }, 359 | ], 360 | 'declarer': 'tf_node', 361 | 'executer': 'tf_node', 362 | }, 363 | { 364 | 'title': 'Multiply', 365 | 'color': color_red, 366 | 'code': 'tf.multiply', 367 | 'inputs': [ 368 | { 369 | 'name': 'Name', 370 | 'type': 'string', 371 | 'default': '', 372 | 'code': 'name', 373 | }, 374 | { 375 | 'name': 'Input 1', 376 | 'type': 'reference', 377 | 'default': null, 378 | 'code': 'x', 379 | }, 380 | { 381 | 'name': 'Input 2', 382 | 'type': 'reference', 383 | 'default': null, 384 | 'code': 'y', 385 | }, 386 | ], 387 | 'outputs': [ 388 | { 389 | 'name': 'Result', 390 | }, 391 | ], 392 | 'declarer': 'tf_node', 393 | 'executer': 'tf_node', 394 | }, 395 | { 396 | 'title': 'Matrix Multiply', 397 | 'color': color_red, 398 | 'code': 'tf.matmul', 399 | 'inputs': [ 400 | { 401 | 'name': 'Name', 402 | 'type': 'string', 403 | 'default': '', 404 | 'code': 'name', 405 | }, 406 | { 407 | 'name': 'Input 1', 408 | 'type': 'reference', 409 | 'default': null, 410 | 'code': 'a', 411 | }, 412 | { 413 | 'name': 'Input 2', 414 | 'type': 'reference', 415 | 'default': null, 416 | 'code': 'b', 417 | }, 418 | ], 419 | 'outputs': [ 420 | { 421 | 'name': 'Result', 422 | }, 423 | ], 424 | 'declarer': 'tf_node', 425 | 'executer': 'tf_node', 426 | }, 427 | { 428 | 'title': 'Negative', 429 | 'color': color_red, 430 | 'code': 'tf.negative', 431 | 'inputs': [ 432 | { 433 | 'name': 'Name', 434 | 'type': 'string', 435 | 'default': '', 436 | 'code': 'name', 437 | }, 438 | { 439 | 'name': 'Input', 440 | 'type': 'reference', 441 | 'default': null, 442 | 'code': 'x', 443 | }, 444 | ], 445 | 'outputs': [ 446 | { 447 | 'name': 'Result', 448 | }, 449 | ], 450 | 'declarer': 'tf_node', 451 | 'executer': 'tf_node', 452 | }, 453 | { 454 | 'title': 'Log', 455 | 'color': color_red, 456 | 'code': 'tf.log', 457 | 'inputs': [ 458 | { 459 | 'name': 'Name', 460 | 'type': 'string', 461 | 'default': '', 462 | 'code': 'name', 463 | }, 464 | { 465 | 'name': 'Input', 466 | 'type': 'reference', 467 | 'default': null, 468 | 'code': 'x', 469 | }, 470 | ], 471 | 'outputs': [ 472 | { 473 | 'name': 'Result', 474 | }, 475 | ], 476 | 'declarer': 'tf_node', 477 | 'executer': 'tf_node', 478 | }, 479 | { 480 | 'title': 'Squared Difference', 481 | 'color': color_red, 482 | 'code': 'tf.squared_difference', 483 | 'inputs': [ 484 | { 485 | 'name': 'Name', 486 | 'type': 'string', 487 | 'default': '', 488 | 'code': 'name', 489 | }, 490 | { 491 | 'name': 'Input 1', 492 | 'type': 'reference', 493 | 'default': null, 494 | 'code': 'x', 495 | }, 496 | { 497 | 'name': 'Input 2', 498 | 'type': 'reference', 499 | 'default': null, 500 | 'code': 'y', 501 | }, 502 | ], 503 | 'outputs': [ 504 | { 505 | 'name': 'Result', 506 | }, 507 | ], 508 | 'declarer': 'tf_node', 509 | 'executer': 'tf_node', 510 | }, 511 | { 512 | 'title': 'Reduce Sum', 513 | 'color': color_red, 514 | 'code': 'tf.reduce_sum', 515 | 'inputs': [ 516 | { 517 | 'name': 'Name', 518 | 'type': 'string', 519 | 'default': '', 520 | 'code': 'name', 521 | }, 522 | { 523 | 'name': 'Input', 524 | 'type': 'reference', 525 | 'default': null, 526 | 'code': 'input_tensor', 527 | }, 528 | { 529 | 'name': 'Axis', 530 | 'type': 'number', 531 | 'default': 0, 532 | 'code': 'axis', 533 | }, 534 | ], 535 | 'outputs': [ 536 | { 537 | 'name': 'Result', 538 | }, 539 | ], 540 | 'declarer': 'tf_node', 541 | 'executer': 'tf_node', 542 | }, 543 | { 544 | 'title': 'Arg Max', 545 | 'color': color_red, 546 | 'code': 'tf.argmax', 547 | 'inputs': [ 548 | { 549 | 'name': 'Name', 550 | 'type': 'string', 551 | 'default': '', 552 | 'code': 'name', 553 | }, 554 | { 555 | 'name': 'Input', 556 | 'type': 'reference', 557 | 'default': null, 558 | 'code': 'input', 559 | }, 560 | { 561 | 'name': 'Axis', 562 | 'type': 'number', 563 | 'default': 0, 564 | 'code': 'axis', 565 | }, 566 | ], 567 | 'outputs': [ 568 | { 569 | 'name': 'Result', 570 | }, 571 | ], 572 | 'declarer': 'tf_node', 573 | 'executer': 'tf_node', 574 | }, 575 | { 576 | 'title': 'Reduce Mean', 577 | 'color': color_red, 578 | 'code': 'tf.reduce_mean', 579 | 'inputs': [ 580 | { 581 | 'name': 'Name', 582 | 'type': 'string', 583 | 'default': '', 584 | 'code': 'name', 585 | }, 586 | { 587 | 'name': 'Input', 588 | 'type': 'reference', 589 | 'default': null, 590 | 'code': 'input_tensor', 591 | }, 592 | { 593 | 'name': 'Axis', 594 | 'type': 'number', 595 | 'default': 0, 596 | 'code': 'axis', 597 | }, 598 | ], 599 | 'outputs': [ 600 | { 601 | 'name': 'Result', 602 | }, 603 | ], 604 | 'declarer': 'tf_node', 605 | 'executer': 'tf_node', 606 | }, 607 | { 608 | 'title': 'Cast', 609 | 'color': color_red, 610 | 'code': 'tf.cast', 611 | 'inputs': [ 612 | { 613 | 'name': 'Name', 614 | 'type': 'string', 615 | 'default': '', 616 | 'code': 'name', 617 | }, 618 | { 619 | 'name': 'Input', 620 | 'type': 'reference', 621 | 'default': null, 622 | 'code': 'x', 623 | }, 624 | { 625 | 'name': 'Type', 626 | 'type': 'type', 627 | 'default': 'tf.float32', 628 | 'code': 'dtype', 629 | }, 630 | ], 631 | 'outputs': [ 632 | { 633 | 'name': 'Result', 634 | }, 635 | ], 636 | 'declarer': 'tf_node', 637 | 'executer': 'tf_node', 638 | }, 639 | { 640 | 'title': 'Equals', 641 | 'color': color_red, 642 | 'code': 'tf.equal', 643 | 'inputs': [ 644 | { 645 | 'name': 'Name', 646 | 'type': 'string', 647 | 'default': '', 648 | 'code': 'name', 649 | }, 650 | { 651 | 'name': 'Input 1', 652 | 'type': 'reference', 653 | 'default': null, 654 | 'code': 'x', 655 | }, 656 | { 657 | 'name': 'Input 2', 658 | 'type': 'reference', 659 | 'default': null, 660 | 'code': 'y', 661 | }, 662 | ], 663 | 'outputs': [ 664 | { 665 | 'name': 'Result', 666 | }, 667 | ], 668 | 'declarer': 'tf_node', 669 | 'executer': 'tf_node', 670 | }, 671 | { 672 | 'title': 'Softmax', 673 | 'color': color_red, 674 | 'code': 'tf.nn.softmax', 675 | 'inputs': [ 676 | { 677 | 'name': 'Name', 678 | 'type': 'string', 679 | 'default': '', 680 | 'code': 'name', 681 | }, 682 | { 683 | 'name': 'Input', 684 | 'type': 'reference', 685 | 'default': null, 686 | 'code': 'logits', 687 | }, 688 | ], 689 | 'outputs': [ 690 | { 691 | 'name': 'Result', 692 | }, 693 | ], 694 | 'declarer': 'tf_node', 695 | 'executer': 'tf_node', 696 | }, 697 | { 698 | 'title': 'Initialize', 699 | 'color': color_green, 700 | 'code': 'tf.global_variables_initializer', 701 | 'inputs': [ 702 | 703 | ], 704 | 'outputs': [ 705 | { 706 | 'name': 'Run', 707 | }, 708 | ], 709 | 'declarer': 'global_var', 710 | 'executer': 'global_var', 711 | }, 712 | { 713 | 'title': 'Execute', 714 | 'color': color_green, 715 | 'code': '', 716 | 'inputs': [ 717 | { 718 | 'name': 'Node 1', 719 | 'type': 'reference', 720 | 'default': null, 721 | 'code': 'node1', 722 | }, 723 | { 724 | 'name': 'Node 2', 725 | 'type': 'reference', 726 | 'default': null, 727 | 'code': 'node2', 728 | }, 729 | { 730 | 'name': 'Node 3', 731 | 'type': 'reference', 732 | 'default': null, 733 | 'code': 'node3', 734 | }, 735 | { 736 | 'name': 'Node 4', 737 | 'type': 'reference', 738 | 'default': null, 739 | 'code': 'node4', 740 | }, 741 | { 742 | 'name': 'Node 5', 743 | 'type': 'reference', 744 | 'default': null, 745 | 'code': 'node5', 746 | }, 747 | ], 748 | 'outputs': [ 749 | { 750 | 'name': 'Run', 751 | }, 752 | ], 753 | 'declarer': 'none', 754 | 'executer': 'multi_exec', 755 | }, 756 | { 757 | 'title': 'Repeater', 758 | 'color': color_green, 759 | 'code': '', 760 | 'inputs': [ 761 | { 762 | 'name': 'Name', 763 | 'type': 'string', 764 | 'default': '', 765 | 'code': 'name', 766 | }, 767 | { 768 | 'name': 'Node', 769 | 'type': 'reference', 770 | 'default': null, 771 | 'code': 'node', 772 | }, 773 | { 774 | 'name': 'Iterations', 775 | 'type': 'number', 776 | 'default': 100, 777 | 'code': 'iterations', 778 | }, 779 | ], 780 | 'outputs': [ 781 | { 782 | 'name': 'Run', 783 | }, 784 | ], 785 | 'declarer': 'none', 786 | 'executer': 'repeater', 787 | }, 788 | { 789 | 'title': 'Set Placeholder', 790 | 'color': color_green, 791 | 'code': '', 792 | 'inputs': [ 793 | { 794 | 'name': 'Placeholder', 795 | 'type': 'string', 796 | 'default': '', 797 | 'code': 'name', 798 | }, 799 | { 800 | 'name': 'Value', 801 | 'type': 'code', 802 | 'default': '', 803 | 'code': 'value', 804 | }, 805 | ], 806 | 'outputs': [ 807 | { 808 | 'name': 'Run', 809 | }, 810 | ], 811 | 'declarer': 'none', 812 | 'executer': 'set_placeholder', 813 | }, 814 | { 815 | 'title': 'Set Placeholder Ref', 816 | 'color': color_green, 817 | 'code': '', 818 | 'inputs': [ 819 | { 820 | 'name': 'Placeholder', 821 | 'type': 'string', 822 | 'default': '', 823 | 'code': 'name', 824 | }, 825 | { 826 | 'name': 'Value', 827 | 'type': 'reference', 828 | 'default': null, 829 | 'code': 'value', 830 | }, 831 | ], 832 | 'outputs': [ 833 | { 834 | 'name': 'Run', 835 | }, 836 | ], 837 | 'declarer': 'none', 838 | 'executer': 'set_placeholder', 839 | }, 840 | { 841 | 'title': 'Minimize Step', 842 | 'color': color_purple, 843 | 'code': 'tf.train.GradientDescentOptimizer(0.5).minimize', 844 | 'inputs': [ 845 | { 846 | 'name': 'Name', 847 | 'type': 'string', 848 | 'default': '', 849 | 'code': 'name', 850 | }, 851 | { 852 | 'name': 'Cost Function', 853 | 'type': 'reference', 854 | 'default': null, 855 | 'code': 'loss', 856 | }, 857 | ], 858 | 'outputs': [ 859 | { 860 | 'name': 'Run', 861 | }, 862 | ], 863 | 'declarer': 'tf_node', 864 | 'executer': 'tf_node', 865 | }, 866 | { 867 | 'title': 'MNIST Data', 868 | 'color': color_grey, 869 | 'code': '', 870 | 'inputs': [ 871 | 872 | ], 873 | 'outputs': [ 874 | { 875 | 'name': 'Train Input', 876 | }, 877 | { 878 | 'name': 'Train Labels', 879 | }, 880 | { 881 | 'name': 'Test Input', 882 | }, 883 | { 884 | 'name': 'Test Labels', 885 | }, 886 | ], 887 | 'declarer': 'mnist', 888 | 'executer': 'none', 889 | }, 890 | ] 891 | 892 | function repeat_str(string, count) { 893 | var result = string 894 | for (var i = 1; i < count; ++i) { 895 | result += string 896 | } 897 | return result 898 | } 899 | 900 | function clamp(x, a, b) { 901 | return Math.min(Math.max(x, a), b) 902 | } 903 | 904 | function lerp(a, b, x) { 905 | return a + (b - a) * x 906 | } 907 | 908 | function random(a, b) { 909 | return a + Math.random() * (b - a) 910 | } 911 | 912 | function hsl(r, g, b) { 913 | 914 | //http://www.easyrgb.com/index.php?X=MATH&H=18#text18 915 | 916 | var var_Min = Math.min( r, g, b ) //Min. value of RGB 917 | var var_Max = Math.max( r, g, b ) //Max. value of RGB 918 | var del_Max = var_Max - var_Min //Delta RGB value 919 | 920 | var L = ( var_Max + var_Min ) / 2 921 | var H = 0.0, S = 0.0 922 | 923 | if ( del_Max == 0 ) //This is a gray, no chroma... 924 | { 925 | H = 0 //HSL results from 0 to 1 926 | S = 0 927 | } 928 | else //Chromatic data... 929 | { 930 | if ( L < 0.5 ) S = del_Max / ( var_Max + var_Min ) 931 | else S = del_Max / ( 2 - var_Max - var_Min ) 932 | 933 | var del_R = ( ( ( var_Max - r ) / 6 ) + ( del_Max / 2 ) ) / del_Max 934 | var del_G = ( ( ( var_Max - g ) / 6 ) + ( del_Max / 2 ) ) / del_Max 935 | var del_B = ( ( ( var_Max - b ) / 6 ) + ( del_Max / 2 ) ) / del_Max 936 | 937 | if ( r == var_Max ) H = del_B - del_G 938 | else if ( g == var_Max ) H = ( 1 / 3 ) + del_R - del_B 939 | else if ( b == var_Max ) H = ( 2 / 3 ) + del_G - del_R 940 | 941 | if ( H < 0 ) H += 1 942 | if ( H > 1 ) H -= 1 943 | } 944 | 945 | return {h: H, s: S, l: L}; 946 | } 947 | 948 | function luma(r, g, b){ 949 | return 0.299 * r + 0.587 * g + 0.114 * b; 950 | } 951 | 952 | function add_prefix_strings(strings, prefix) { 953 | for (var i = 0; i < strings.length; i++){ 954 | strings[i] = prefix + strings[i] 955 | } 956 | } 957 | 958 | function extend_array(array1, array2) { 959 | for (var i = 0; i < array2.length; i++){ 960 | array1.push(array2[i]) 961 | } 962 | } 963 | 964 | Component.onCompleted: { 965 | showMaximized() 966 | } 967 | 968 | 969 | Item { 970 | anchors.top: top_bar.bottom 971 | anchors.left: parent.left 972 | anchors.right: parent.right 973 | anchors.bottom: parent.bottom 974 | GraphDisplay { 975 | id: graphDisplay 976 | anchors.left: modelBrowser.right 977 | anchors.right: parent.right 978 | anchors.top: parent.top 979 | anchors.bottom: parent.bottom 980 | } 981 | 982 | ModelBrowser { 983 | id: modelBrowser 984 | anchors.left: parent.left 985 | anchors.top: parent.top 986 | anchors.bottom: parent.bottom 987 | width: 320 988 | } 989 | } 990 | Rectangle { 991 | id: top_bar 992 | anchors.left: parent.left 993 | anchors.right: parent.right 994 | anchors.top: parent.top 995 | height: 60 996 | color: '#d66321' 997 | 998 | MyLabel { 999 | anchors.verticalCenter: parent.verticalCenter 1000 | anchors.left: parent.left 1001 | anchors.leftMargin: 30 1002 | font.pixelSize: 25 1003 | text: qsTr('TensorBuilder') 1004 | color: '#eeeeee' 1005 | } 1006 | 1007 | ToolButton { 1008 | anchors.right: parent.right 1009 | anchors.rightMargin: 30 1010 | anchors.verticalCenter: parent.verticalCenter 1011 | text: qsTr('Help') 1012 | onClicked: graphDisplay.show_help() 1013 | } 1014 | } 1015 | DropShadow { 1016 | anchors.fill: top_bar 1017 | horizontalOffset: 0 1018 | verticalOffset: 0 1019 | radius: 12.0 1020 | samples: 16 1021 | color: "#80000000" 1022 | source: top_bar 1023 | } 1024 | 1025 | 1026 | // SwipeView { 1027 | // id: swipeView 1028 | // anchors.fill: parent 1029 | // currentIndex: tabBar.currentIndex 1030 | 1031 | // Page1 { 1032 | 1033 | // } 1034 | 1035 | // Page { 1036 | // Label { 1037 | // text: qsTr("Second page") 1038 | // anchors.centerIn: parent 1039 | // } 1040 | // } 1041 | // } 1042 | 1043 | // footer: TabBar { 1044 | // id: tabBar 1045 | // currentIndex: swipeView.currentIndex 1046 | // TabButton { 1047 | // text: qsTr("First") 1048 | // } 1049 | // TabButton { 1050 | // text: qsTr("Second") 1051 | // } 1052 | // } 1053 | } 1054 | -------------------------------------------------------------------------------- /TensorBuilder/native.cpp: -------------------------------------------------------------------------------- 1 | #include "native.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | Native* Native::current = nullptr; 9 | 10 | Native::Native(QObject *parent) : QObject(parent) 11 | { 12 | this->python_process = nullptr; 13 | this->python_running = false; 14 | 15 | Native::current = this; 16 | } 17 | 18 | void Native::init(QGuiApplication& app, QQmlApplicationEngine& engine) { 19 | engine.rootContext()->setContextProperty("Native", this); 20 | this->app_path = app.applicationDirPath(); 21 | } 22 | 23 | bool Native::is_python_running() { 24 | this->python_running_mutex.lock(); 25 | bool result = this->python_running; 26 | this->python_running_mutex.unlock(); 27 | return result; 28 | } 29 | 30 | QString Native::get_python_stream() { 31 | this->python_stream_mutex.lock(); 32 | QString result = this->python_stream; 33 | this->python_stream.clear(); 34 | this->python_stream_mutex.unlock(); 35 | return result; 36 | } 37 | 38 | void Native::run_python(QString script) { 39 | Native::current->python_running_mutex.lock(); 40 | bool running = this->python_running; 41 | Native::current->python_running_mutex.unlock(); 42 | if (running) return; 43 | 44 | this->python_temp_path = Native::current->app_path + "/temp.py"; 45 | qDebug() << "writing: " << this->python_temp_path; 46 | 47 | QFile file(this->python_temp_path); 48 | if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)){ 49 | QTextStream outText(&file); 50 | outText << script; 51 | 52 | file.close(); 53 | } 54 | else { 55 | qDebug() << "!!!WARNING: writing failed!!!"; 56 | } 57 | 58 | Native::current->python_running_mutex.lock(); 59 | Native::current->python_running = true; 60 | Native::current->python_running_mutex.unlock(); 61 | 62 | QtConcurrent::run(Native::python_thread); 63 | } 64 | 65 | void Native::python_thread() { 66 | QStringList arguments; 67 | arguments << Native::current->python_temp_path; 68 | 69 | QProcess process; 70 | process.setWorkingDirectory(Native::current->app_path); 71 | process.start("python", arguments); 72 | 73 | QString output; 74 | while (true) { 75 | if (process.state() == QProcess::NotRunning) break; 76 | process.waitForReadyRead(); 77 | Native::current->python_stream_mutex.lock(); 78 | 79 | QString output; 80 | output += process.readAllStandardOutput(); 81 | output += process.readAllStandardError(); 82 | output.replace("\r\n", "\n"); 83 | Native::current->python_stream += output; 84 | // qDebug() << output; 85 | // qDebug() << error; 86 | Native::current->python_stream_mutex.unlock(); 87 | } 88 | 89 | Native::current->python_running_mutex.lock(); 90 | Native::current->python_running = false; 91 | Native::current->python_running_mutex.unlock(); 92 | } 93 | -------------------------------------------------------------------------------- /TensorBuilder/native.h: -------------------------------------------------------------------------------- 1 | #ifndef NATIVE_H 2 | #define NATIVE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | class Native : public QObject 15 | { 16 | Q_OBJECT 17 | public: 18 | explicit Native(QObject *parent = nullptr); 19 | 20 | void init(QGuiApplication&, QQmlApplicationEngine&); 21 | 22 | Q_INVOKABLE void run_python(QString); 23 | Q_INVOKABLE bool is_python_running(); 24 | Q_INVOKABLE QString get_python_stream(); 25 | 26 | 27 | private: 28 | QProcess* python_process; 29 | QString app_path, python_temp_path; 30 | QMutex python_stream_mutex, python_running_mutex; 31 | QString python_stream; 32 | bool python_running; 33 | 34 | static void python_thread(); 35 | 36 | static Native* current; 37 | 38 | signals: 39 | 40 | public slots: 41 | }; 42 | 43 | #endif // NATIVE_H 44 | -------------------------------------------------------------------------------- /TensorBuilder/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | Page1.qml 5 | Page1Form.ui.qml 6 | qtquickcontrols2.conf 7 | SelectionPanel.qml 8 | GraphDisplay.qml 9 | GraphNode.qml 10 | MyLabel.qml 11 | Connection.qml 12 | MyDialog.qml 13 | MyButton.qml 14 | NewNodeDialog.qml 15 | CodeEditDialog.qml 16 | ModelBrowser.qml 17 | ConsoleDialog.qml 18 | LoadingDialog.qml 19 | HelpDialog.qml 20 | 21 | 22 | -------------------------------------------------------------------------------- /TensorBuilder/qtquickcontrols2.conf: -------------------------------------------------------------------------------- 1 | ; This file can be edited to change the style of the application 2 | ; See Styling Qt Quick Controls 2 in the documentation for details: 3 | ; http://doc.qt.io/qt-5/qtquickcontrols2-styles.html 4 | 5 | [Controls] 6 | Style=Material 7 | 8 | [Universal] 9 | Theme=Light 10 | ;Accent=Steel 11 | 12 | [Material] 13 | Theme=Light 14 | ;Accent=BlueGrey 15 | ;Primary=BlueGray 16 | -------------------------------------------------------------------------------- /pics/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TommyX12/tensorbuilder/dccdbf302062aaf93940939d7685a0284072b710/pics/1.png -------------------------------------------------------------------------------- /pics/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TommyX12/tensorbuilder/dccdbf302062aaf93940939d7685a0284072b710/pics/2.png -------------------------------------------------------------------------------- /pics/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TommyX12/tensorbuilder/dccdbf302062aaf93940939d7685a0284072b710/pics/3.png -------------------------------------------------------------------------------- /pics/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TommyX12/tensorbuilder/dccdbf302062aaf93940939d7685a0284072b710/pics/4.png --------------------------------------------------------------------------------