Browse Source

Fixed weird global step counter

Clemens-Alexander Brust 5 years ago
parent
commit
548b709a84
2 changed files with 16 additions and 12 deletions
  1. 15 11
      chillax/chillax_classifier.py
  2. 1 1
      setup.py

+ 15 - 11
chillax/chillax_classifier.py

@@ -47,6 +47,7 @@ class CHILLAXKerasHC(
         self.extrapolator = None
         self.extrapolator = None
 
 
         self._reporting_step_counter = 0
         self._reporting_step_counter = 0
+        self._last_reported_step = -1
         self._running_sample_count = 0
         self._running_sample_count = 0
         self._running_changed_samples = 0
         self._running_changed_samples = 0
 
 
@@ -306,13 +307,15 @@ class CHILLAXKerasHC(
         self.report_metric("gain_from_weighting", gain)
         self.report_metric("gain_from_weighting", gain)
         self.loss_weights /= gain
         self.loss_weights /= gain
 
 
-    def loss(self, feature_batch, ground_truth):
+    def loss(self, feature_batch, ground_truth, global_step):
         if not self.is_updated:
         if not self.is_updated:
             raise RuntimeError(
             raise RuntimeError(
                 "This classifier is not yet ready to compute a loss. "
                 "This classifier is not yet ready to compute a loss. "
                 "Check if it has been notified of a hyponymy relation."
                 "Check if it has been notified of a hyponymy relation."
             )
             )
 
 
+        self._reporting_step_counter = global_step
+
         # (1) Predict
         # (1) Predict
         prediction = self.predict_embedded(feature_batch)
         prediction = self.predict_embedded(feature_batch)
 
 
@@ -442,18 +445,19 @@ class CHILLAXKerasHC(
             )
             )
 
 
             if self._reporting_step_counter % 10 == 9:
             if self._reporting_step_counter % 10 == 9:
-                if self._running_sample_count > 0:
-                    self.report_metric(
-                        "extrapolation_changed_sample_fraction",
-                        float(self._running_changed_samples)
-                        / float(self._running_sample_count),
-                        step=self._reporting_step_counter,
-                    )
+                if self._last_reported_step < self._reporting_step_counter:
+                    if self._running_sample_count > 0:
+                        self.report_metric(
+                            "extrapolation_changed_sample_fraction",
+                            float(self._running_changed_samples)
+                            / float(self._running_sample_count),
+                            step=self._reporting_step_counter,
+                        )
 
 
-                self._running_changed_samples = 0
-                self._running_sample_count = 0
+                    self._running_changed_samples = 0
+                    self._running_sample_count = 0
 
 
-            self._reporting_step_counter += 1
+                    self._last_reported_step = self._reporting_step_counter
 
 
             return extrapolated_ground_truth
             return extrapolated_ground_truth
         else:
         else:

+ 1 - 1
setup.py

@@ -17,7 +17,7 @@ setup(
     packages=find_packages(),
     packages=find_packages(),
     python_requires=">=3.7",
     python_requires=">=3.7",
     install_requires=[
     install_requires=[
-        "chia==2.0rc4",
+        "chia==2.0rc5",
     ],
     ],
     # metadata to display on PyPI
     # metadata to display on PyPI
     author="Clemens-Alexander Brust",
     author="Clemens-Alexander Brust",