Update app.py
Browse files
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 |
-
|
105 |
-
|
106 |
-
|
|
|
107 |
|
108 |
-
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
|
118 |
-
|
119 |
-
|
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
|