visualizermodel.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #pragma once
  26. #include <QObject>
  27. #include <QGenericMatrix>
  28. #include "remotecontrol.qpb.h"
  29. #include "remotecontrol_grpc.qpb.h"
  30. #include "valueindicator.h"
  31. #include "abstractdense.h"
  32. #include "layertrigger.h"
  33. class ValueIndicator;
  34. class LayerTrigger;
  35. struct NetworkLayerState {
  36. ValueIndicatorDense m_activations;
  37. ValueIndicatorDense m_biases;
  38. ValueIndicatorDense m_weights;
  39. LayerTrigger m_actiovationTrigger;
  40. LayerTrigger m_weightTrigger;
  41. };
  42. class VisualizerModel : public QObject
  43. {
  44. Q_OBJECT
  45. Q_PROPERTY(QList<int> sizes READ sizes NOTIFY sizesChanged)
  46. Q_PROPERTY(remotecontrol::NetworkState* networkState READ networkState CONSTANT)
  47. public:
  48. explicit VisualizerModel(std::shared_ptr<remotecontrol::RemoteControlClient> &client, QObject *parent = nullptr);
  49. QList<int> sizes() {
  50. return m_networkConfig.sizes();
  51. }
  52. Q_INVOKABLE ValueIndicator *activation(int layer, int row);
  53. Q_INVOKABLE ValueIndicator *weight(int layer, int row, int column);
  54. Q_INVOKABLE LayerTrigger *activationTrigger(int layer);
  55. Q_INVOKABLE LayerTrigger *weightTrigger(int layer);
  56. Q_INVOKABLE void start();
  57. remotecontrol::NetworkState *networkState() const
  58. {
  59. return m_networkState.data();
  60. }
  61. signals:
  62. void sizesChanged();
  63. private:
  64. std::shared_ptr<remotecontrol::RemoteControlClient> &m_client;
  65. remotecontrol::Configuration m_networkConfig;
  66. QList<NetworkLayerState*> m_layers;
  67. QPointer<remotecontrol::NetworkState> m_networkState;
  68. };