Пример #1
0
    def __call__(self, frame: Node) -> List[ObjectPrediction]:
        import tensorflow as tf
        tiles = list(
            node_to_tiles(
                frame.resize(STREAM_WIDTH // SCALE, STREAM_HEIGHT // SCALE)))
        y_pred = self.model(
            tf.stack([process_image(tile.image) for (_, _, tile) in tiles]))

        pred_class = [self.classes[i] for i in np.argmax(y_pred, axis=1)]
        confidence = np.max(y_pred, axis=1)

        out = []
        for i in range(len(tiles)):
            x_offset, y_offset, tile = tiles[i]
            rect = Rectangle(x_offset * SCALE, y_offset * SCALE, TILE_WIDTH,
                             TILE_HEIGHT)
            out.append(
                ObjectPrediction(pred_class[i], confidence[i], rect, tile))
        return out
Пример #2
0
def load_relevant_backgrounds() -> Iterable[Node]:
    root = Path(os.environ['GENERATIVE_BGS_SRC'])
    for path in root.glob('*.png'):
        img = cv2.imread(path.as_posix())
        node = Node(img)
        yield node.resize(node.width // 2, node.height // 2)