Skip to content

Commit

Permalink
sort imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
lalmei committed Nov 23, 2024
1 parent 5ad6269 commit 18eb376
Show file tree
Hide file tree
Showing 104 changed files with 397 additions and 509 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ test: $(test.python) $(src.python) ## Run tests


.PHONY: format
format: ## Run ruff format
format: ## Run ruff format (Includes sorting of imports)
uv run ruff check --select I --config=config/ruff.toml --fix
uv run ruff format --config=config/ruff.toml $(src.python) $(test.python)

.PHONY: check-format
Expand Down
4 changes: 2 additions & 2 deletions agml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
# If AgML is being imported for the first time, then we need to setup
# the module, namely prepping the config file.
def _setup():
import os as _os
import json as _json
import os as _os

if not _os.path.exists(_os.path.expanduser("~/.agml")):
_os.makedirs(_os.path.expanduser("~/.agml"))
Expand All @@ -39,4 +39,4 @@ def _setup():


# There are no top-level imported functions or classes, only the modules.
from . import data, backend, synthetic, viz, io
from . import backend, data, io, synthetic, viz
25 changes: 12 additions & 13 deletions agml/_internal/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,31 @@
to install the necessary preprocessing packages.
"""

import os
import sys
import json
import glob
import shutil
import argparse
import csv
import glob
import json
import os
import shutil
import sys

import cv2
import numpy as np
import pandas as pd

from PIL import Image

from agml.utils.logging import tqdm
from agml.utils.io import create_dir, nested_dir_list, get_dir_list, get_file_list
from agml.utils.data import load_public_sources
from agml._internal.process_utils import (
read_txt_file,
get_image_info,
get_label2id,
convert_bbox_to_coco,
get_coco_annotation_from_obj,
convert_xmls_to_cocojson,
get_coco_annotation_from_obj,
get_image_info,
get_label2id,
move_segmentation_dataset,
read_txt_file,
)
from agml.utils.data import load_public_sources
from agml.utils.io import create_dir, get_dir_list, get_file_list, nested_dir_list
from agml.utils.logging import tqdm


class PublicDataPreprocessor(object):
Expand Down
4 changes: 2 additions & 2 deletions agml/_internal/s3internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
Internal class for interacting with the AgML public dataset S3 bucket.
"""

import json
import os
import sys
import json
import zipfile
import warnings
import zipfile

import boto3
import botocore.exceptions
Expand Down
1 change: 0 additions & 1 deletion agml/_internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

from agml.utils.io import recursive_dirname


_PERSONAL_ACCESS_TOKEN = None


Expand Down
14 changes: 7 additions & 7 deletions agml/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
AgML, specifically data loaded or generated from the data module.
"""

from . import experimental
from .config import (
clear_all_datasets,
data_save_path,
set_data_save_path,
synthetic_data_save_path,
set_synthetic_save_path,
downloaded_datasets,
model_save_path,
set_data_save_path,
set_model_save_path,
clear_all_datasets,
downloaded_datasets,
set_synthetic_save_path,
synthetic_data_save_path,
)
from .tftorch import get_backend, set_backend
from .random import set_seed
from . import experimental
from .tftorch import get_backend, set_backend
5 changes: 2 additions & 3 deletions agml/backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import json
import shutil
import logging
import os
import shutil

from agml.utils.logging import log


# The super base save directory for AgML. This is the overriding base
# save directory and default original save directory. This is saved here
# because the default path to save datasets to can be overridden by
Expand Down
1 change: 0 additions & 1 deletion agml/backend/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from agml.framework import AgMLSerializable


__all__ = ["allow_nested_data_splitting"]


Expand Down
2 changes: 1 addition & 1 deletion agml/backend/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from agml.backend.tftorch import torch, tf, get_backend
from agml.backend.tftorch import get_backend, tf, torch


def set_seed(seed=None):
Expand Down
15 changes: 7 additions & 8 deletions agml/backend/tftorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@
importing of either library (which takes a significant amount of time).
"""

import types
import functools
import importlib
import inspect
import logging
import importlib
import functools
import types

# Suppress any irrelevant warnings which will pop up from either backend.
import warnings

import numpy as np

from agml.utils.logging import log
from agml.utils.image import consistent_shapes


# Suppress any irrelevant warnings which will pop up from either backend.
import warnings
from agml.utils.logging import log

warnings.filterwarnings("ignore", category=UserWarning, message=".*Named tensors.*Triggered internally.*")

Expand Down
9 changes: 3 additions & 6 deletions agml/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .loader import AgMLDataLoader
from . import experimental, exporters, extensions
from .image_loader import ImageLoader
from .loader import AgMLDataLoader
from .point_cloud import PointCloud
from .public import public_data_sources, source
from .public import download_public_dataset
from .public import download_public_dataset, public_data_sources, source
from .tools import coco_to_bboxes, convert_bbox_format
from . import experimental
from . import exporters
from . import extensions
6 changes: 3 additions & 3 deletions agml/data/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import os
import re
import sys
import json

from agml.framework import AgMLSerializable
from agml.backend.config import data_save_path
from agml.framework import AgMLSerializable
from agml.utils.downloads import download_dataset
from agml.utils.io import get_file_list, get_dir_list, is_image_file
from agml.utils.io import get_dir_list, get_file_list, is_image_file


class DataBuilder(AgMLSerializable):
Expand Down
1 change: 0 additions & 1 deletion agml/data/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import numpy as np


__all__ = ["generate_keras_segmentation_dual_transform"]


Expand Down
3 changes: 2 additions & 1 deletion agml/data/exporters/yolo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import yaml
import shutil

import yaml

import agml
from agml.utils.general import flatten
from agml.utils.logging import log
Expand Down
2 changes: 1 addition & 1 deletion agml/data/extensions/cvat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import os
import shutil
import json


def restructure_cvat_annotations(image_dir, cvat_dir, dataset_name, output_dir=None):
Expand Down
2 changes: 1 addition & 1 deletion agml/data/image_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import cv2
import numpy as np

from agml.framework import AgMLSerializable
from agml.data.loader import AgMLDataLoader
from agml.data.public import public_data_sources
from agml.framework import AgMLSerializable
from agml.utils.io import nested_file_list
from agml.utils.random import inject_random_state

Expand Down
39 changes: 20 additions & 19 deletions agml/data/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,36 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import json
import copy
import glob
import fnmatch
from typing import Union
import glob
import json
import os
from collections.abc import Sequence
from decimal import getcontext, Decimal
from decimal import Decimal, getcontext
from typing import Union

import numpy as np

from agml.framework import AgMLSerializable
from agml.data.manager import DataManager
from agml.data.builder import DataBuilder
from agml.data.metadata import DatasetMetadata, make_metadata
from agml.data.exporters.yolo import export_yolo
from agml.utils.logging import log
from agml.utils.io import get_file_list, get_dir_list
from agml.utils.data import load_public_sources
from agml.utils.general import NoArgument, resolve_list_value
from agml.utils.random import inject_random_state
from agml.backend.config import data_save_path, synthetic_data_save_path, SUPER_BASE_DIR
from agml.backend.config import SUPER_BASE_DIR, data_save_path, synthetic_data_save_path
from agml.backend.experimental import AgMLExperimentalFeatureWrapper
from agml.backend.tftorch import (
StrictBackendError,
_add_dataset_to_mro, # noqa
get_backend,
set_backend,
user_changed_backend,
StrictBackendError,
_add_dataset_to_mro, # noqa
)
from agml.data.builder import DataBuilder
from agml.data.exporters.yolo import export_yolo
from agml.data.manager import DataManager
from agml.data.metadata import DatasetMetadata, make_metadata
from agml.framework import AgMLSerializable
from agml.utils.data import load_public_sources
from agml.utils.general import NoArgument, resolve_list_value
from agml.utils.io import get_dir_list, get_file_list
from agml.utils.logging import log
from agml.utils.random import inject_random_state
from agml.viz.general import show_sample


Expand Down Expand Up @@ -1761,9 +1761,10 @@ def export_torch(self, **loader_kwargs):
-------
A `torch.utils.data.DataLoader` enclosing a copy of this loader.
"""
from agml.backend.tftorch import torch
from torch.utils.data import DataLoader

from agml.backend.tftorch import torch

if get_backend() != "torch":
if user_changed_backend():
raise StrictBackendError(change="torch", obj=self.export_torch)
Expand Down
13 changes: 6 additions & 7 deletions agml/data/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@

import numpy as np

from agml.framework import AgMLSerializable
from agml.data.object import DataObject
from agml.backend.tftorch import convert_to_batch, is_array_like
from agml.data.builder import DataBuilder
from agml.data.metadata import DatasetMetadata
from agml.data.managers.transforms import TransformManager
from agml.data.managers.resize import ImageResizeManager
from agml.data.managers.training import TrainingManager

from agml.data.managers.transforms import TransformManager
from agml.data.metadata import DatasetMetadata
from agml.data.object import DataObject
from agml.framework import AgMLSerializable
from agml.utils.general import NoArgument
from agml.backend.tftorch import convert_to_batch, is_array_like
from agml.utils.random import seed_context
from agml.utils.image import consistent_shapes
from agml.utils.logging import log
from agml.utils.random import seed_context


class DataManager(AgMLSerializable):
Expand Down
4 changes: 2 additions & 2 deletions agml/data/managers/resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import numpy as np

from agml.framework import AgMLSerializable
from agml.utils.logging import log
from agml.utils.image import imread_context
from agml.utils.general import resolve_tuple
from agml.utils.image import imread_context
from agml.utils.io import recursive_dirname
from agml.utils.logging import log


class ImageResizeManager(AgMLSerializable):
Expand Down
14 changes: 7 additions & 7 deletions agml/data/managers/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@

import numpy as np

from agml.framework import AgMLSerializable
from agml.utils.image import needs_batch_dim
from agml.backend.tftorch import (
tf,
torch,
set_backend,
get_backend,
user_changed_backend,
StrictBackendError,
_convert_image_to_torch,
get_backend,
is_array_like,
set_backend,
tf,
torch,
user_changed_backend,
)
from agml.framework import AgMLSerializable
from agml.utils.image import needs_batch_dim


class TrainState(Enum):
Expand Down
Loading

0 comments on commit 18eb376

Please sign in to comment.