main.qml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
  5. *
  6. * This file is part of NeuralNetwork project https://git.semlanik.org/semlanik/NeuralNetwork
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. import QtQuick 2.11
  26. import QtQuick.Window 2.11
  27. import QtQuick.Controls 1.4
  28. import QtQuick.Dialogs 1.2
  29. ApplicationWindow {
  30. id: root
  31. visible: true
  32. width: 1120
  33. height: 560
  34. maximumWidth: 1120
  35. maximumHeight: 560
  36. minimumWidth: 1120
  37. minimumHeight: 560
  38. property int tileSize: 20
  39. property int tileCount: 28
  40. property color resetColor: "#333333"
  41. MouseArea {
  42. id: drawingArea
  43. width: tileCount*tileSize
  44. height: tileCount*tileSize
  45. Repeater {
  46. model: 784
  47. Rectangle {
  48. id: tile
  49. width: tileSize
  50. height: tileSize
  51. color: resetColor
  52. x: tileSize*(model.index%tileCount)
  53. y: tileSize*Math.floor(model.index/tileCount)
  54. Connections {
  55. target: drawingArea
  56. onPositionChanged: {
  57. var centerX = tile.x + tile.width/2
  58. var centerY = tile.y + tile.height/2
  59. var diffX = mouse.x - centerX
  60. var diffY = mouse.y - centerY
  61. var dense = Math.sqrt(diffX * diffX + diffY * diffY)
  62. if (dense < tileSize*1.2) {
  63. var newColor = color.r + (tileSize*1.2 - dense)/tileSize*1.2
  64. var newValue = newColor - 0.2
  65. if (newColor > 1.0) {
  66. newColor = 1.0
  67. newValue = 1.0
  68. }
  69. tile.color = Qt.rgba(newColor, newColor, newColor, 1.0)
  70. hwengine.updateValue(model.index, newValue)
  71. }
  72. }
  73. }
  74. Connections {
  75. target: clearButton
  76. onClicked: {
  77. tile.color = resetColor
  78. hwengine.updateValue(model.index, 0.0)
  79. }
  80. }
  81. }
  82. }
  83. }
  84. Column {
  85. id: controls
  86. anchors.left: drawingArea.right
  87. anchors.top: parent.top
  88. anchors.margins: 10
  89. spacing: 10
  90. Text {
  91. text: "Select neural network data"
  92. }
  93. Row {
  94. TextField {
  95. id: pathToNeuralNetwork
  96. enabled: false
  97. width: 300
  98. }
  99. Button {
  100. id: browseButton
  101. text: "Browse"
  102. onClicked: {
  103. neuralNetworkImport.open()
  104. }
  105. }
  106. Button {
  107. id: uploadButton
  108. text: "Upload"
  109. onClicked: {
  110. hwengine.setNeuralNetworkData(pathToNeuralNetwork.text)
  111. }
  112. }
  113. }
  114. Button {
  115. id: tainButton
  116. text: "Re-run trainig"
  117. onClicked: {
  118. hwengine.retrain()
  119. }
  120. }
  121. Button {
  122. id: clearButton
  123. text: "Clear"
  124. }
  125. Button {
  126. id: recognizeButton
  127. text: "Recognize"
  128. onClicked: {
  129. hwengine.recognize()
  130. }
  131. }
  132. }
  133. Text {
  134. id: result
  135. anchors.top: controls.bottom
  136. anchors.topMargin: 100
  137. anchors.horizontalCenter: controls.horizontalCenter
  138. color: "#003b6f" //Tardis blue :)
  139. font.pixelSize: 40
  140. text: hwengine.result
  141. }
  142. FileDialog {
  143. id: neuralNetworkImport
  144. selectMultiple: false
  145. selectFolder: false
  146. nameFilters: ["*.nnd"]
  147. onAccepted: {
  148. pathToNeuralNetwork.text = neuralNetworkImport.fileUrl
  149. }
  150. }
  151. }