def on_train_end(self, logs): if self.stopped_from_frontend: red_print("training stopped from JukeBox") else: green_print("training complete, terminated naturally") self.publish_data(payload=None)
def publish_data(self, payload=None, qos=0, retain=True): if isinstance(payload, dict): payload = json.dumps(payload, indent=2) self.client.publish(self.publish_topic, payload=payload, qos=qos, retain=retain) elif payload == None: self.client.publish(self.publish_topic, payload=payload, qos=1, retain=True) #red_print("cleared all meassages under topic name {}".format(self.publish_topic)) else: red_print("payload was not dictionary, did not send")
def update_variables(self): tab_1_cmd = self.msg['tab1'] tab_2_cmd = self.msg['tab2'] if tab_1_cmd['play_status'] in ['play', 'pause', 'stop']: self.play_status = tab_1_cmd['play_status'] self.frontend_learning_rate = tab_2_cmd['learning_rate'] else: red_print( "Play command '{}' in not supported so rejected whole message, retaining previous command '{}'" .format(tab_1_cmd['play_status'], self.play_status)) if self.frontend_learning_rate != self.frontend_learning_rate_prev: self.update_learning_rate = True self.frontend_learning_rate_prev = self.frontend_learning_rate
def tab_2_button_on_click(self, selected_operator='f(x)=x'): assert selected_operator in ('+', '-', '/', '*', 'f(x)=x') self.selected_operandQLabel.setText('\t{}'.format(selected_operator)) #green_print(self.selected_operandQLabel.text().strip()) operand = self.operand_textbox.text() if operand == '': red_print('no command sent since operand field was empty') else: eff_lr = calculate_efffective_lr( initial_lr=self.learning_rate, operator=self.selected_operandQLabel.text().strip(), operand=float(operand)) self.tab2_payload = {'learning_rate': eff_lr} # calculate effective learning rate and publish to backend #print(self.tab2_payload) self.send_payload()
def tab_3_button_click(self): if self.checkpoint_folder == None or self.checkpoint_folder == '': options = QFileDialog.Options() options |= QFileDialog.DontUseNativeDialog self.checkpoint_folder = str( QFileDialog.getExistingDirectory(self, "Select folder location", options=options)) checkpoint_format = self.tab3_dropdown.currentText() checkpoint_name = self.tab3_checkpoint_name_textbox.text() if checkpoint_name == '': red_print('checkpoint name is empty') return self.tab3_payload = { 'take_snapshot': True, 'h5': False, 'ckpt': False, 'checkpoint_name': checkpoint_name, 'checkpoint_path': self.checkpoint_folder } if checkpoint_format == 'both': self.tab3_payload['h5'] = True self.tab3_payload['ckpt'] = True elif checkpoint_format == '.ckpt': self.tab3_payload['ckpt'] = True else: self.tab3_payload['h5'] = True # Send command to take a snapshot self.send_payload() # set flag to flag after you have sent command for checkpointing self.tab3_payload['take_snapshot'] = False
def on_message(self, client, userdata, msg): message = json.loads(msg.payload.decode('utf-8')) #print(message) if self.start == False: #connection has not been acknowledged #message = json.loads(msg.payload.decode('utf-8')) if message['status'] == 'acknowledged': self.start = True else: red_print('did not understand msg::{}'.format(message)) else: #self.subscribe_topic = msg.topic self.msg = message #red_print("got a message") if self.verbose > 0: cyan_print("Received a new command from JukeBox") #cyan_print(self.subscribe_topic+" "+str(self.msg)) self.update_variables()