def get_x_from_path(self, path: str) -> np.ndarray: img = cv2.imread(path) x = normalize_img(img, with_aug=self.with_aug, width=self.img_w, height=self.img_h) x = np.moveaxis(np.array(x), 2, 0) return x
def preprocess(self, imgs): xs = [] for img in imgs: x = normalize_img(img, width=self.width, height=self.height) xs.append(x) xs = np.moveaxis(np.array(xs), 3, 1) xs = torch.tensor(xs) xs = xs.to(device_torch) return xs
def predict_with_confidence(self, imgs: List[np.ndarray]) -> Tuple: """ TODO: describe method """ xs = [normalize_img(img) for img in imgs] if not bool(xs): return [], [] predicted = self._predict(xs) confidences, orientations = self.unzip_predicted(predicted) return orientations, confidences, predicted
def predict_with_confidence(self, imgs: List[np.ndarray or List]) -> Tuple: """ Predict options(region, count lines) with confidence by numberplate images """ xs = [normalize_img(img) for img in imgs] if not bool(xs): return [], [], [], [] predicted = self._predict(xs) confidences, region_ids, count_lines = self.unzip_predicted(predicted) count_lines = self.custom_count_lines_id_to_all_count_lines( count_lines) return region_ids, count_lines, confidences, predicted
def predict_with_confidence(self, imgs: List[np.ndarray]) -> Tuple: """ Predict options(region, count lines) with confidence by numberplate images """ xs = [normalize_img(img) for img in imgs] predicted = [[], []] if bool(xs): xs = np.moveaxis(np.array(xs), 3, 1) predicted = self.ort_session.run(None, {self.input_name: xs}) confidences, region_ids, count_lines = self.unzip_predicted(predicted) count_lines = self.get_count_lines_labels(count_lines) return region_ids, count_lines, confidences, predicted
def get_x_from_path(self, path: str, bbox: List, angle: int) -> np.ndarray: img = cv2.imread(path) rotated_img, rotated_bbox = rotate_image_and_bboxes( img, np.array([bbox]), int(angle)) rotated_bbox = rotated_bbox[0] rotated_bbox[0] = rotated_bbox[0] if rotated_bbox[0] > 0 else 0 rotated_bbox[1] = rotated_bbox[1] if rotated_bbox[1] > 0 else 0 min_x = rotated_bbox[0] max_x = rotated_bbox[2] min_y = rotated_bbox[1] max_y = rotated_bbox[3] img_part = rotated_img[min_y:max_y, min_x:max_x] img_part = normalize_img(img_part, width=self.img_w, height=self.img_h) img_part = np.moveaxis(np.array(img_part), 2, 0) return img_part
def run_iteration(self, with_aug=False): ys = [] xs = [] paths = [] for _ in np.arange(self.batch_size): x, y = self.next_sample() paths.append(x) img = cv2.imread(x) x = normalize_img(img, with_aug=with_aug, width=self.img_w, height=self.img_h) xs.append(x) ys.append(y) xs = np.moveaxis(np.array(xs), 3, 1) return paths, xs, ys
def preprocess(images): x = convert_cv_zones_rgb_to_bgr(images) x = [normalize_img(img) for img in x] x = np.moveaxis(np.array(x), 3, 1) return x