Jensen-holm commited on
Commit
c504867
·
1 Parent(s): 79f3d28

working with serializing the model with to_dict()

Browse files
neural_network/main.py CHANGED
@@ -44,5 +44,4 @@ def main(
44
  X_test=X_test,
45
  y_test=y_test,
46
  )
47
- return model.__dict__
48
-
 
44
  X_test=X_test,
45
  y_test=y_test,
46
  )
47
+ return model.to_dict()
 
neural_network/neural_network.py CHANGED
@@ -25,6 +25,7 @@ class NeuralNetwork:
25
  return self.compute_node(n1, self.w2, self.b2, self.activation_func)
26
 
27
  def set_loss_hist(self, loss_hist: list) -> None:
 
28
  self.loss_history = loss_hist
29
 
30
  def eval(self, X_test, y_test) -> None:
@@ -37,3 +38,16 @@ class NeuralNetwork:
37
  @classmethod
38
  def from_dict(cls, dct):
39
  return cls(**dct)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  return self.compute_node(n1, self.w2, self.b2, self.activation_func)
26
 
27
  def set_loss_hist(self, loss_hist: list) -> None:
28
+ assert (isinstance(loss_hist, list))
29
  self.loss_history = loss_hist
30
 
31
  def eval(self, X_test, y_test) -> None:
 
38
  @classmethod
39
  def from_dict(cls, dct):
40
  return cls(**dct)
41
+
42
+ def to_dict(self) -> dict:
43
+ return {
44
+ "w1": list(self.w1),
45
+ "w2": list(self.w2),
46
+ "b1": list(self.b1),
47
+ "b2": list(self.b2),
48
+ "epochs": self.epochs,
49
+ "learning_rate": self.learning_rate,
50
+ "activation_func": self.activation_func.__name__,
51
+ "func_prime": self.func_prime.__name__,
52
+ "hidden_size": self.hidden_size,
53
+ }