Skip to content

Commit

Permalink
[CLEAN] Sort and group imports
Browse files Browse the repository at this point in the history
  • Loading branch information
laclouis5 committed Nov 5, 2023
1 parent b37ddee commit d78bcd1
Show file tree
Hide file tree
Showing 20 changed files with 120 additions and 121 deletions.
14 changes: 7 additions & 7 deletions src/globox/annotation.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from .boundingbox import BoundingBox, BoxFormat
from .errors import ParsingError, FileParsingError
from .atomic import open_atomic
from .file_utils import PathLike

import json
import xml.etree.ElementTree as et
from pathlib import Path
from typing import Mapping, Optional, Union
import xml.etree.ElementTree as et
import json
from warnings import warn

from .atomic import open_atomic
from .boundingbox import BoundingBox, BoxFormat
from .errors import FileParsingError, ParsingError
from .file_utils import PathLike


class Annotation:
"""
Expand Down
39 changes: 20 additions & 19 deletions src/globox/annotationset.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
from .boundingbox import BoundingBox, BoxFormat
from .annotation import Annotation
from .errors import UnknownImageFormat, ParsingError
from .file_utils import glob, PathLike
from .image_utils import get_image_size, IMAGE_EXTENSIONS
from .atomic import open_atomic
from .thread_utils import thread_map

import csv
import json
import xml.etree.ElementTree as et
from collections import defaultdict
from pathlib import Path
from typing import (
Dict,
Any,
Callable,
Dict,
Iterable,
Iterator,
Mapping,
Optional,
TypeVar,
Iterable,
Union,
Optional,
Any,
)
import csv
from pathlib import Path
import xml.etree.ElementTree as et
from collections import defaultdict
import json
from tqdm import tqdm
from warnings import warn

from tqdm import tqdm

from .annotation import Annotation
from .atomic import open_atomic
from .boundingbox import BoundingBox, BoxFormat
from .errors import ParsingError, UnknownImageFormat
from .file_utils import PathLike, glob
from .image_utils import IMAGE_EXTENSIONS, get_image_size
from .thread_utils import thread_map

T = TypeVar("T")


Expand Down Expand Up @@ -1031,8 +1032,8 @@ def show_stats(self, *, verbose: bool = False):
Print in the console a synthetic view of the dataset annotations (distribution of
bounding boxes and images by label).
"""
from rich.table import Table
from rich import print as rprint
from rich.table import Table

box_by_label = defaultdict(int)
im_by_label = defaultdict(int)
Expand Down
4 changes: 2 additions & 2 deletions src/globox/atomic.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from .file_utils import PathLike

import os
import tempfile as tmp
from contextlib import contextmanager
from typing import Optional

from .file_utils import PathLike


@contextmanager
def _tempfile(suffix: str = "~", dir: Optional[PathLike] = None):
Expand Down
7 changes: 3 additions & 4 deletions src/globox/boundingbox.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from .errors import ParsingError

from enum import Enum, auto
from typing import Mapping, Union, Tuple, Optional, Any
import xml.etree.ElementTree as et
from enum import Enum, auto
from typing import Any, Mapping, Optional, Tuple, Union

from .errors import ParsingError

Coordinates = Tuple[float, float, float, float]
"""
Expand Down
10 changes: 5 additions & 5 deletions src/globox/cli.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from .boundingbox import BoxFormat
from .annotationset import AnnotationSet
from .evaluation import COCOEvaluator

import argparse
import sys
from pathlib import Path
from typing import Optional
import sys

from .annotationset import AnnotationSet
from .boundingbox import BoxFormat
from .evaluation import COCOEvaluator

PARSE_CHOICES = {
"coco",
Expand Down
27 changes: 14 additions & 13 deletions src/globox/evaluation.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
from .boundingbox import BoundingBox
from .annotation import Annotation
from .annotationset import AnnotationSet
from .utils import grouping, all_equal, mean
from .atomic import open_atomic
from .file_utils import PathLike

from typing import DefaultDict, Dict, Mapping, Optional, Sequence, Iterable, Any
import csv
from collections import defaultdict
import numpy as np
from copy import copy
from math import isnan
from enum import Enum, auto
from itertools import chain, product
from functools import lru_cache
from itertools import chain, product
from math import isnan
from typing import Any, DefaultDict, Dict, Iterable, Mapping, Optional, Sequence

import numpy as np
from tqdm import tqdm
import csv

from .annotation import Annotation
from .annotationset import AnnotationSet
from .atomic import open_atomic
from .boundingbox import BoundingBox
from .file_utils import PathLike
from .utils import all_equal, grouping, mean


class RecallSteps(Enum):
Expand Down Expand Up @@ -565,8 +566,8 @@ def _evaluate_all(self, *, verbose: bool = False):

def show_summary(self, *, verbose: bool = False):
"""Compute and show the standard COCO metrics."""
from rich.table import Table
from rich import print as pprint
from rich.table import Table

self._evaluate_all(verbose=verbose)

Expand Down
3 changes: 1 addition & 2 deletions src/globox/file_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pathlib import Path
from typing import Union, Iterable

from typing import Iterable, Union

PathLike = Union[str, Path]

Expand Down
23 changes: 7 additions & 16 deletions src/globox/image_utils.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
from .errors import UnknownImageFormat
from .file_utils import PathLike
from pathlib import Path
from struct import unpack, error as struct_error
# Source: https://github.com/scardine/image_size

from os import path
from pathlib import Path
from struct import error as struct_error
from struct import unpack

"""
get_image_size.py
====================
:Name: get_image_size
:Purpose: extract image dimensions given a file path
:Author: Paulo Scardine (based on code from Emmanuel VAÏSSE)
:Created: 26/09/2013
:Copyright: (c) Paulo Scardine 2013
:Licence: MIT
Source: https://github.com/scardine/image_size
"""
from .errors import UnknownImageFormat
from .file_utils import PathLike

IMAGE_EXTENSIONS = [
".jpg",
Expand Down
6 changes: 3 additions & 3 deletions src/globox/thread_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from concurrent.futures import ThreadPoolExecutor
import atexit
from concurrent.futures import ThreadPoolExecutor
from operator import length_hint
from tqdm import tqdm
from typing import Callable, TypeVar, Iterable, Optional
from typing import Callable, Iterable, Optional, TypeVar

from tqdm import tqdm

SHARED_THREAD_POOL = ThreadPoolExecutor()

Expand Down
1 change: 0 additions & 1 deletion src/globox/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from itertools import groupby
from typing import Callable, Hashable, Iterable, TypeVar


U = TypeVar("U")
V = TypeVar("V", bound=Hashable)

Expand Down
16 changes: 8 additions & 8 deletions tests/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from pathlib import Path
from timeit import timeit
from time import perf_counter
from argparse import ArgumentParser
from pathlib import Path
from tempfile import TemporaryDirectory
from time import perf_counter
from timeit import timeit

from rich.table import Table
import globox
from rich import print as rich_print
from rich.table import Table

import globox
import constants as cst
from . import constants as C


def benchmark(repetitions: int = 5):
Expand All @@ -20,8 +20,8 @@ def benchmark(repetitions: int = 5):
labels = sorted(gts._labels())
label_to_id = {l: i for i, l in enumerate(labels)}

coco_gt = globox.AnnotationSet.from_coco(cst.coco_gts_path)
coco_det = coco_gt.from_results(cst.coco_results_path)
coco_gt = globox.AnnotationSet.from_coco(C.coco_gts_path)
coco_det = coco_gt.from_results(C.coco_results_path)

evaluator = globox.COCOEvaluator(
ground_truths=coco_gt,
Expand Down
2 changes: 1 addition & 1 deletion tests/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from globox import AnnotationSet
from pathlib import Path

from globox import AnnotationSet

data_path = (Path(__file__).parent / "globox_test_data/").resolve()
gts_path = data_path / "gts/"
Expand Down
3 changes: 2 additions & 1 deletion tests/pycocotools_results.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path

from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval
from pathlib import Path


def main():
Expand Down
7 changes: 4 additions & 3 deletions tests/test_annotation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from globox import BoundingBox, Annotation, BoxFormat
import pytest
from pathlib import Path
from math import isclose
from pathlib import Path

import pytest
from globox import Annotation, BoundingBox


def test_init():
Expand Down
15 changes: 9 additions & 6 deletions tests/test_annotationset.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from globox import Annotation, AnnotationSet, BoundingBox, BoxFormat
from globox.file_utils import glob
from .constants import *
from math import isclose
from pathlib import Path

import pytest
from globox import Annotation, AnnotationSet, BoundingBox
from globox.file_utils import glob
from PIL import Image
from math import isclose

from . import constants as C


def test_annotationset():
Expand Down Expand Up @@ -35,7 +38,7 @@ def test_annotationset():


def test_annotation_set_2():
files = list(glob(pascal_path, ".xml"))
files = list(glob(C.pascal_path, ".xml"))
set1 = AnnotationSet(Annotation.from_xml(f) for f in files[:50])
set2 = AnnotationSet(Annotation.from_xml(f) for f in files[50:])
set3 = set1 | set2
Expand Down Expand Up @@ -164,7 +167,7 @@ def test_from_txt_conf_last(tmp_path: Path):


def test_from_coco_id_string():
gts = AnnotationSet.from_coco(coco_str_id_path)
gts = AnnotationSet.from_coco(C.coco_str_id_path)

assert len(gts) == 100 # images defined in coco_file
assert gts["2007_001585.jpg"] is not None
Expand Down
3 changes: 2 additions & 1 deletion tests/test_bbox.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from globox import BoxFormat, BoundingBox
from math import isclose

import pytest
from globox import BoundingBox, BoxFormat


def test_init():
Expand Down
10 changes: 6 additions & 4 deletions tests/test_coco_evaluation.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from globox import AnnotationSet, Annotation, BoundingBox, COCOEvaluator
from .constants import *
from math import isclose

import pytest
from globox import Annotation, AnnotationSet, BoundingBox, COCOEvaluator

from . import constants as C


@pytest.fixture
def coco_evaluator() -> COCOEvaluator:
coco_gt = AnnotationSet.from_coco(coco_gts_path)
coco_det = coco_gt.from_results(coco_results_path)
coco_gt = AnnotationSet.from_coco(C.coco_gts_path)
coco_det = coco_gt.from_results(C.coco_results_path)

return COCOEvaluator(
ground_truths=coco_gt,
Expand Down
5 changes: 3 additions & 2 deletions tests/test_conversion.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from pathlib import Path

from globox import AnnotationSet
from globox.utils import all_equal
from pathlib import Path

from .constants import coco2_path, label_to_id, id_to_label, image_folder, labels
from .constants import coco2_path, id_to_label, image_folder, label_to_id, labels


def test_conversion(tmp_path: Path):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Test EvaluationItem and similar for invariants
# Test AP computation

from globox import *
import globox
import pytest


Expand Down
Loading

0 comments on commit d78bcd1

Please sign in to comment.