Esempio n. 1
0
 def handle_control_demod(self, keys):
     # Check for keys we care about
     if "freeze" in keys:
         self.run_mode = "freeze"
         if self.demodtype == 'neural':
             self.logger.info(
                 "neural demod {}: freezing model and saving state".format(
                     self.uuid_str))
             torch.save(self.demod.model.state_dict(),
                        "demod_neural_weights-{}.mdl".format(self.uuid_str))
             print("Saving final demod constellation @{}".format(
                 self.demod_update_cnt))
             data_vis = gen_demod_grid(points_per_dim=100,
                                       min_val=-2.5,
                                       max_val=2.5)['data']
             labels_si_g = self.demod.demodulate(data_c=data_vis,
                                                 mode='exploit')
             np.savez("neural_demod_constellation_{:05d}_{}".format(
                 self.demod_update_cnt, time.strftime('%Y%m%d_%H%M%S')),
                      iq=data_vis,
                      labels=labels_si_g)
     elif "train" in keys:
         self.run_mode = "train"
         self.logger.info("neural demod {}: resuming training".format(
             self.uuid_str))
Esempio n. 2
0
 def train_preamble(self, data_c):
     self.update(inputs=self.preamble_si,
                 actions=[],
                 data_for_rewards=data_c,
                 mode='echo')
     if self.packet_cnt % self.log_constellation_interval == 0:
         print("Saving demod constellation @{}".format(self.packet_cnt))
         data_vis = gen_demod_grid(points_per_dim=40,
                                   min_val=-2.5,
                                   max_val=2.5)['data']
         labels_si_g = self.demodulate(data_c=data_vis, mode='exploit')
         numpy.savez("neural_demod_constellation_{:05d}_{}".format(
             self.packet_cnt, time.strftime('%Y%m%d_%H%M%S')),
                     iq=data_vis,
                     labels=labels_si_g)
Esempio n. 3
0
 def handle_control(self, msg):
     # Test whether message is a dict, per UHD requirements
     if not pmt.is_dict(msg):
         self.logger.info(
             "{} received non-dict control message, ignoring".format(
                 self.uuid_str))
         return
     try:
         keys = pmt.to_python(pmt.dict_keys(msg))
     except pmt.wrong_type as e:
         self.logger.debug(
             "{} received pair instead of dict, fixing".format(
                 self.uuid_str))
         msg = pmt.dict_add(pmt.make_dict(), pmt.car(msg), pmt.cdr(msg))
         keys = pmt.to_python(pmt.dict_keys(msg))
     print("KEYS: {}".format(keys))
     # Check for keys we care about
     if "freeze" in keys:
         self.run_mode = "freeze"
         self.logger.info(
             "neural demod {}: freezing model and saving state".format(
                 self.uuid_str))
         torch.save(self.model.state_dict(),
                    "demod_neural_weights-{}".format(self.uuid_str))
         print("Saving final demod constellation @{}".format(
             self.packet_cnt))
         data_vis = gen_demod_grid(points_per_dim=40,
                                   min_val=-2.5,
                                   max_val=2.5)['data']
         labels_si_g = self.demodulate(data_c=data_vis, mode='exploit')
         numpy.savez("neural_demod_constellation_{:05d}_{}".format(
             self.packet_cnt, time.strftime('%Y%m%d_%H%M%S')),
                     iq=data_vis,
                     labels=labels_si_g)
     elif "train" in keys:
         self.run_mode = "train"
         self.logger.info("neural demod {}: resuming training".format(
             self.uuid_str))
Esempio n. 4
0
 def demod_train_preamble(self, data_c, idxecho):
     try:
         preamble_si = util_data.bits_to_integers(
             self.get_preamble_hist(idxecho), self.bits_per_symbol)
         self.demod.update(inputs=preamble_si,
                           actions=[],
                           data_for_rewards=data_c,
                           mode='echo')
         if self.demod_packet_cnt % self.log_interval == 0:
             print("Saving demod constellation @{}".format(
                 self.demod_packet_cnt))
             data_vis = gen_demod_grid(points_per_dim=100,
                                       min_val=-2.5,
                                       max_val=2.5)['data']
             labels_si_g = self.demod.demodulate(data_c=data_vis,
                                                 mode='exploit')
             np.savez("neural_demod_constellation_{:05d}_{}".format(
                 self.demod_packet_cnt, time.strftime('%Y%m%d_%H%M%S')),
                      iq=data_vis,
                      labels=labels_si_g)
     except KeyError as e:
         self.logger.info(
             "Unable to train demodulator with stored index {}".format(
                 idxecho))