Skip to content

Commit

Permalink
Saving and loading from json
Browse files Browse the repository at this point in the history
  • Loading branch information
aiaragomes committed Aug 28, 2023
1 parent 2d63c66 commit 49cb712
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions helper_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def initialize(model_centroids: str, **kwargs) -> Dict[str, Any]:
# Save initial centroids
print("Saving initial centroids")
with open(model_centroids, "w+") as f:
json.dump(kwargs["centroids"], f)
json.dump({"centroids": kwargs["centroids"]}, f)

return kwargs

Expand Down Expand Up @@ -80,8 +80,8 @@ def average_weights(model_centroids: str, full_model: str, files: List[str], k:
# Save results
print("Saving average centroids")
with open(model_centroids, "w+") as f:
json.dump(centroids, f)
json.dump({"centroids": centroids}, f)
with open(full_model, "w+") as f:
json.dump(centroids, f)
json.dump({"centroids": centroids}, f)

return change
5 changes: 2 additions & 3 deletions helper_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
from pandas.api.types import is_string_dtype
from scipy.spatial import distance
from typing import Optional, Any, Dict, Callable, Tuple, List
from typing import Optional, List

logger = logging.getLogger("helper_worker_logger")
data: Optional[np.ndarray] = None
Expand Down Expand Up @@ -69,8 +69,7 @@ def train(key: str, starting_centroids: str, k: int, columns: list):
for column in columns:
centroid.append(dfc[column].mean())
centroids.append(centroid)
centroids = {"centroids": centroids}

print("Saving local centroids")
with open(f"centroids.{key}.json", "w+") as f:
json.dump(centroids, f)
json.dump({"centroids": centroids}, f)

0 comments on commit 49cb712

Please sign in to comment.