def visualize_an_input(self, *args, **kwargs): an_input = self.get_an_input(*args, **kwargs) reshaped_input = reshape_np(an_input, (CAMERA_ROWS, CAMERA_COLS, -1)) root_logger.info(an_input.shape) root_logger.info(reshaped_input.shape) for i in range(reshaped_input.shape[-1]): show_array(reshaped_input[:, :, i])
def visualize_prediction(self): canvas = zeros((960, 640, 3)) hardness = int(input("Hardness[0-100]")) / 100.0 common_input_params = { "rotation_hardness": hardness, "clockwise": True, "row_hardness": hardness, "row_up": False, "col_hardness": hardness, "col_left": False, } root_logger.info(hardness) img_material, mask_material = self.train_DB.get_materials_by_category("Zebra", hardness) expected_one_hot = mask_material.get_an_input(self.train_DB.one_hot_coder, **common_input_params) reshaped_expected_one_hot = reshape_np(expected_one_hot, (CAMERA_ROWS, CAMERA_COLS, -1)) input_img = img_material.get_an_input(**common_input_params, noise_hardness=hardness) predicted_distribution_matrix = self.get_prediction(input_img * 255) canvas[:480] = input_img canvas[480:] = input_img root_logger.info(predicted_distribution_matrix.shape) assert reshaped_expected_one_hot.shape == predicted_distribution_matrix.shape == (480, 640, len(LaneCategory)) for category_i in range(predicted_distribution_matrix.shape[2]): expected_mask = reshaped_expected_one_hot[:, :, category_i] predicted_mask = predicted_distribution_matrix[:, :, category_i] canvas[:480, :, 0] = expected_mask canvas[480:, :, 0] = predicted_mask show_array(canvas)
def last_block_time(self): block_times = self.block_times if not block_times: return last_block_time = block_times[-1] root_logger.info("Timer ({})'s last_block_time: {}".format( self.name, last_block_time)) return last_block_time
def mean_block_time(self): block_times = self.block_times if not block_times: return mean_block_time = mean(block_times) root_logger.info("Timer ({})'s mean_block_time: {}".format( self.name, mean_block_time)) return mean_block_time
def choose_camera(code: int = None) -> Camera: """ Feldob minden egyes működő kamerához egy ablakot. Visszaadja azt az egy kamerát, amit kiválasztottunk egy számleütés segítségével. Nem a konzolba kell beírni a számot enterrel. """ with get_cameras(code) as cameras: cv2_input.wait_keys = [camera.id for camera in cameras] root_logger.info("Waitkeys={}".format(cv2_input.wait_keys)) for camera in cycle(cameras): imshow_cv2("{}-> ({})".format(choose_camera.__name__, camera.name), camera.img) key = cv2_input.pressed_key if key is not None: destroyAllWindows() yield cameras[cv2_input.wait_keys.index(key)] destroyAllWindows() return
def __enter__(self) -> "Camera": """ Megnyitja a kamera fájlt, és megpróbálja használni a vele reprezentált fizikai kamerát. Ha le tud kérdezni egy képet, akkor a fájl egy működő fizikai kamerát reprezentál. """ if self._video_capture is None: self._video_capture = VideoCapture(self.id) self._video_capture.set(CAP_PROP_BUFFERSIZE, 1) # Kisebbre állítjuk a buffert, # hogy ne legyen nagy a késleltetés. Jobb lenne, ha egyáltalán nem lenne buffer, de nem sikerült # rájönnöm, hogyan lehetne kikapcsolni. if not self._video_capture.isOpened( ): # Ne nyissuk meg újra a fájlt, ha már meg volt nyitva. self._video_capture.open(self.id) try: self.img except: self.__exit__(None, None, None) raise ConnectionError("Can't connect to camera ({})".format( self.id)) else: root_logger.info("Connected to camera ({})".format(self.id)) return self
def on_epoch_end(self, epoch, logs=None): root_logger.info(logs)
def on_epoch_begin(self, epoch, logs=None): self.unet.epoch_i = epoch root_logger.info(self.unet.epoch_i)
def on_epoch_end(self, epoch, logs=None): if epoch == (self.unet.min_epochs - 1): root_logger.info("The saver had been reinitialized") super().__init__(*self.args, **self.kwargs) super().on_epoch_end(epoch, logs)
def on_epoch_end(self, epoch, logs=None): if epoch >= (self.unet.min_epochs - 1): super().on_epoch_end(epoch, logs) else: root_logger.info("Early stopper is inactivated")
def visualize_batches(self): canvas = zeros((480, 640, 3)) for image_batch, one_hot_batch, weight_batch in self.train_data: root_logger.info(image_batch.shape) root_logger.info(one_hot_batch.shape) root_logger.info(weight_batch.shape) for sample_i in range(image_batch.shape[0]): image_sample = image_batch[sample_i] one_hot_sample = one_hot_batch[sample_i] weight_sample = weight_batch[sample_i] root_logger.info(image_sample.shape) root_logger.info(one_hot_sample.shape) root_logger.info(weight_sample.shape) reshaped_one_hot_sample = reshape_np(one_hot_sample, (CAMERA_ROWS, CAMERA_COLS, -1)) reshaped_weight_sample = reshape_np(weight_sample, (CAMERA_ROWS, CAMERA_COLS)) root_logger.info(reshaped_one_hot_sample.shape) root_logger.info(reshaped_weight_sample.shape) for category_i in range(reshaped_one_hot_sample.shape[2]): canvas[:, :, 1:3] = image_sample[:, :, 1:3] canvas[:, :, 0] = reshaped_one_hot_sample[:, :, category_i] show_array(canvas) show_array(reshaped_weight_sample) break
def setup_function(function): Camera.cameras = set() GOOD_CAMERA_INDEX, BAD_CAMERA_INDEX = None, 9 for i in range(4): try: cvtColor(VideoCapture(i).read()[1], None) except Exception as e: root_logger.warning(e) else: GOOD_CAMERA_INDEX = i break root_logger.info(GOOD_CAMERA_INDEX) @name(Camera.__new__, "Singleton by id", globals()) def _(): assert Camera.cameras == set() a = Camera(1) assert Camera.cameras == {a} Camera(1) assert Camera.cameras == {a} Camera(1, 1) assert Camera.cameras == {a} c = Camera(2) assert Camera.cameras == {a, c}
def __exit__(self, exc_type, exc_val, exc_tb): actual_block_time = perf_counter() - self._actual_block_start_time self._block_times.append(actual_block_time) root_logger.info("Timer ({})'s actual_block_time: {}".format( self.name, actual_block_time))
def is_droidcam_running(): out = check_output(["ps", "-o", "command"]).decode("ascii") ret = True if DROIDCAM + SPACE in out else False root_logger.info(out) root_logger.info(ret) return ret