alisrbdni commited on
Commit
6fa11b4
·
verified ·
1 Parent(s): e372257

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -101,22 +101,23 @@ class CustomClient(fl.client.NumPyClient):
101
  return float(loss), len(self.testloader.dataset), {"accuracy": float(accuracy)}
102
 
103
  def plot_metrics(self, round_num):
104
- st.write(f"#### Client {self.client_id} Metrics for Round {round_num}")
105
- st.write(f"Loss: {self.losses[-1]:.4f}")
106
- st.write(f"Accuracy: {self.accuracies[-1]:.4f}")
 
107
 
108
- fig, ax1 = plt.subplots()
109
 
110
- ax2 = ax1.twinx()
111
- ax1.plot(range(1, len(self.losses) + 1), self.losses, 'g-')
112
- ax2.plot(range(1, len(self.accuracies) + 1), self.accuracies, 'b-')
113
 
114
- ax1.set_xlabel('Round')
115
- ax1.set_ylabel('Loss', color='g')
116
- ax2.set_ylabel('Accuracy', color='b')
117
 
118
- plt.title(f'Client {self.client_id} Metrics')
119
- st.pyplot(fig)
120
 
121
  def main():
122
  st.write("## Federated Learning with Dynamic Models and Datasets for Mobile Devices")
@@ -198,6 +199,7 @@ if __name__ == "__main__":
198
 
199
 
200
 
 
201
  # # %%writefile app.py
202
 
203
  # import streamlit as st
 
101
  return float(loss), len(self.testloader.dataset), {"accuracy": float(accuracy)}
102
 
103
  def plot_metrics(self, round_num):
104
+ if self.losses and self.accuracies:
105
+ st.write(f"#### Client {self.client_id} Metrics for Round {round_num}")
106
+ st.write(f"Loss: {self.losses[-1]:.4f}")
107
+ st.write(f"Accuracy: {self.accuracies[-1]:.4f}")
108
 
109
+ fig, ax1 = plt.subplots()
110
 
111
+ ax2 = ax1.twinx()
112
+ ax1.plot(range(1, len(self.losses) + 1), self.losses, 'g-')
113
+ ax2.plot(range(1, len(self.accuracies) + 1), self.accuracies, 'b-')
114
 
115
+ ax1.set_xlabel('Round')
116
+ ax1.set_ylabel('Loss', color='g')
117
+ ax2.set_ylabel('Accuracy', color='b')
118
 
119
+ plt.title(f'Client {self.client_id} Metrics')
120
+ st.pyplot(fig)
121
 
122
  def main():
123
  st.write("## Federated Learning with Dynamic Models and Datasets for Mobile Devices")
 
199
 
200
 
201
 
202
+
203
  # # %%writefile app.py
204
 
205
  # import streamlit as st