예제 #1
0
 def train(self, batch_size=50, epochs=100, weights_name="default_weights"):
     self.X_img, self.X_control, self.y = shuffle(self.X_img,
                                                  self.X_control,
                                                  self.y,
                                                  random_state=0)
     weights_path = self.model_path / "weights" / weights_name
     try_make_dirs(weights_path)
     logs_path = weights_path / "logs"
     try_make_dirs(logs_path)
     logs_path_str = str(logs_path.absolute())
     tb_callback = keras.callbacks.TensorBoard(log_dir=logs_path_str,
                                               histogram_freq=0,
                                               write_graph=True,
                                               write_images=True)
     self.model.compile(loss="mean_squared_error",
                        optimizer=optimizers.adam(lr=0.001))
     launch_tensorboard(logs_path_str)
     self.model.fit([self.X_img, self.X_control],
                    self.y,
                    batch_size=batch_size,
                    epochs=epochs,
                    shuffle=False,
                    validation_split=0.2,
                    callbacks=[tb_callback])
     self.model.save_weights(weights_path / "weights.h5")
     with open(weights_path / "info.json", "w") as info_file:
         json.dump(self.info, info_file)
예제 #2
0
 def start_recording(self):
     self.set_save_dir()
     self.refresh_image = False
     self.predict_button.setEnabled(False)
     self.frame = 1
     try_make_dirs(self.save_dir / "images")
     try_make_dirs(self.save_dir / "key-events")
     info_dict = {"key_labels": self.key_labels}
     with open(self.save_dir / "info.json", "w") as fp:
         json.dump(info_dict, fp)
     self.recording = True
예제 #3
0
    def process(self, data_folder, input_channels_mask=None, img_update_callback=None):    
        with open(data_folder / "info.json") as info_file:
            data_info = json.load(info_file)
        key_labels = np.asarray(data_info["key_labels"])[input_channels_mask]
        self.info = {
                "key_labels": key_labels.tolist()
                }

        self.X, self.y = self.stack_arrays(data_folder / "key-events", 
                                           data_folder / "images", 
                                           img_update_callback)
        if input_channels_mask:
            self.y = self.y[:, input_channels_mask]

        save_path = self.model_path / "data" / data_folder.name
        try_make_dirs(save_path)
        np.save(save_path / "y", self.y)
        np.save(save_path / "X", self.X)
        with open(save_path / "info.json", "w") as info_file:
            json.dump(self.info, info_file)