25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

43 satır
1.6KB

  1. import tkinter as tk
  2. from ui.app_state import AppState
  3. from ui.components.digit_drawer import DigitDrawer
  4. from ui.front_page.plots.predictions import PredictionsPlot
  5. class TestModelSection(tk.LabelFrame):
  6. def __init__(self, parent, app_state: AppState):
  7. super().__init__(parent, text="Model testing")
  8. self.app_state = app_state
  9. self.update_ui()
  10. def clear_ui(self):
  11. for widget in self.winfo_children():
  12. widget.destroy()
  13. def update_ui(self):
  14. self.clear_ui()
  15. self.digit_drawer = DigitDrawer(self, 100, 100)
  16. self.digit_drawer.pack(fill=tk.BOTH, expand=True)
  17. # Predict Button (converts drawing to 28x28 and shows the array)
  18. self.predict_button = tk.Button(self, text="Predict", command=self.predict_number)
  19. self.predict_button.pack(fill=tk.BOTH, expand=True)
  20. frame_prediction = tk.Frame(self, height=200)
  21. frame_prediction.pack(fill=tk.BOTH, expand=True)
  22. (tk.Label(frame_prediction, text="Prediction: ")
  23. .pack(side=tk.LEFT))
  24. self.lbl_prediction = tk.Label(frame_prediction, text="/")
  25. self.lbl_prediction.pack(side=tk.LEFT)
  26. self.prediction_plot = PredictionsPlot(self)
  27. self.prediction_plot.pack(side=tk.BOTTOM, anchor=tk.S, fill=tk.X, expand=True)
  28. def predict_number(self):
  29. inputs = self.digit_drawer.convert_to_array()
  30. raw_predictions, predictions = self.app_state.neural_net.predict([inputs])
  31. print(predictions)
  32. self.lbl_prediction.config(text=f"{predictions[0]}")
  33. self.prediction_plot.update_data(raw_predictions)