visualizermodel.h 2.9 KB

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