main.qml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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) {
  63. var newColor = color.r + (tileSize - dense)/tileSize
  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. anchors.left: drawingArea.right
  86. anchors.top: parent.top
  87. anchors.margins: 10
  88. spacing: 10
  89. Text {
  90. text: "Select neural network data"
  91. }
  92. Row {
  93. TextField {
  94. id: pathToNeuralNetwork
  95. enabled: false
  96. width: 300
  97. }
  98. Button {
  99. id: browseButton
  100. text: "Browse"
  101. onClicked: {
  102. neuralNetworkImport.open()
  103. }
  104. }
  105. Button {
  106. id: uploadButton
  107. text: "Upload"
  108. onClicked: {
  109. hwengine.setNeuralNetworkData(pathToNeuralNetwork.text)
  110. }
  111. }
  112. }
  113. Button {
  114. id: tainButton
  115. text: "Re-run trainig"
  116. onClicked: {
  117. hwengine.retrain()
  118. }
  119. }
  120. Button {
  121. id: clearButton
  122. text: "Clear"
  123. }
  124. Button {
  125. id: recognizeButton
  126. text: "Recognize"
  127. onClicked: {
  128. hwengine.recognize()
  129. }
  130. }
  131. }
  132. FileDialog {
  133. id: neuralNetworkImport
  134. selectMultiple: false
  135. selectFolder: false
  136. nameFilters: ["*.nnd"]
  137. onAccepted: {
  138. pathToNeuralNetwork.text = neuralNetworkImport.fileUrl
  139. }
  140. }
  141. }