From 8dcf0872b9c2d25529c4690de4f44f65d205ea9e Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Wed, 17 Dec 2025 19:14:57 +0100 Subject: [PATCH] [Rbm] - abort by user [q] - cycle through training patetrn by [+],[-] keys [Status] - improved report interval - added on_report(): called every report iterval --- src/rbm/rbm.py | 27 +++++++++++++++++++-------- src/rbm/status.py | 5 +++-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/rbm/rbm.py b/src/rbm/rbm.py index c078f59..3f09235 100644 --- a/src/rbm/rbm.py +++ b/src/rbm/rbm.py @@ -15,19 +15,30 @@ class MyStatus(Status): Status.__init__(self, update_interval=2) self.stack = _stack self.batch = _batch + self.index = 0 def on_report(self, status: dict) -> bool: - # Show reconstruction + do_continue = True + # print status values + Status.print_status(status) # Shape of training vector shape = self.stack.from_index(0).shape[0:2] + (1,) - for n in range(self.batch.shape[0]): - img = self.stack.pass_down_up(self.batch[n,:]) - cv_show("img", img, shape) - cv.waitKeyEx(1) + # User input + max_index = self.batch.shape[0] + key = cv.waitKeyEx(1) + if key == ord('q'): + do_continue = False + if key == ord('-'): + self.index = max(0, self.index-1) + if key == ord('+'): + self.index = min(max_index, self.index+1) - Status.print_status(status) - return True + # Show reconstruction + img = self.stack.pass_down_up(self.batch[self.index,:]) + cv_show("img", img, shape) + + return do_continue def read_armadillo(filename: str) -> np.ndarray: result = None @@ -76,7 +87,7 @@ def main(prj_name: str = "test"): stack.state_save() if __name__ == "__main__": - main("prims") + main("norb_small_16h") cv.destroyAllWindows() print("Test: [passed]") diff --git a/src/rbm/status.py b/src/rbm/status.py index f52e3a4..dab1511 100644 --- a/src/rbm/status.py +++ b/src/rbm/status.py @@ -15,6 +15,7 @@ class Status: print(f"{key} : {value}{unit}") def on_change(self, status: dict) -> bool: + do_continue = True if status == {}: self.progress = -1 @@ -22,9 +23,9 @@ class Status: progress = status["progress"]['value'] if self.progress < 0 or progress - self.progress >= self.update_interval: self.progress = progress - self.on_report(status=status) + do_continue = self.on_report(status=status) - return True + return do_continue def on_report(self, status: dict) -> bool: return True \ No newline at end of file