keras-team / keras-cv

Industry-strength Computer Vision workflows with Keras
Other
1k stars 332 forks source link

Some imports are missing in `__init__.py` #1563

Closed james77777778 closed 1 year ago

james77777778 commented 1 year ago

I have noticed that there are some missing imports in __init__.py when I work on KPL vectorizing.

I use following script to roughly check imports in keras_cv/layers/

import pathlib

def take_roll_call(target_init_path, paths):
    contents = pathlib.Path(target_init_path).read_text()
    for path in paths:
        layer_name = path.name.replace(".py", "")
        if layer_name not in contents:
            print(f"Cannot find {path} in {target_init_path}")

if __name__ == "__main__":
    object_detection_paths, object_detection_3d_paths = [], []
    preprocessing_paths, preprocessing_3d_paths = [], []
    regularization_paths = []
    paths = []

    for path in pathlib.Path("keras_cv/layers").rglob("*.py"):
        # ignore unit tests and __init__.py
        if "test" in path.name or "__init__" in path.name:
            continue

        # ignore files without keras.utils.register_keras_serializable
        if "keras.utils.register_keras_serializable" not in path.read_text():
            continue

        if "/object_detection/" in str(path):
            object_detection_paths.append(path)
        elif "/object_detection_3d/" in str(path):
            object_detection_3d_paths.append(path)
        elif "/preprocessing/" in str(path):
            preprocessing_paths.append(path)
        elif "/preprocessing_3d/" in str(path):
            preprocessing_3d_paths.append(path)
        elif "/regularization/" in str(path):
            regularization_paths.append(path)
        paths.append(path)

    take_roll_call(
        "keras_cv/layers/__init__.py",
        paths,
    )
    take_roll_call(
        "keras_cv/layers/object_detection/__init__.py",
        object_detection_paths,
    )
    take_roll_call(
        "keras_cv/layers/object_detection_3d/__init__.py",
        object_detection_3d_paths,
    )
    take_roll_call(
        "keras_cv/layers/preprocessing/__init__.py",
        preprocessing_paths,
    )
    take_roll_call(
        "keras_cv/layers/preprocessing_3d/__init__.py",
        preprocessing_3d_paths,
    )
    take_roll_call(
        "keras_cv/layers/regularization/__init__.py",
        regularization_paths,
    )

and the outputs:

Cannot find keras_cv/layers/preprocessing_3d/base_augmentation_layer_3d.py in keras_cv/layers/__init__.py
Cannot find keras_cv/layers/object_detection/roi_generator.py in keras_cv/layers/__init__.py
Cannot find keras_cv/layers/object_detection/roi_align.py in keras_cv/layers/__init__.py
Cannot find keras_cv/layers/object_detection/rpn_label_encoder.py in keras_cv/layers/__init__.py
Cannot find keras_cv/layers/object_detection/roi_sampler.py in keras_cv/layers/__init__.py
Cannot find keras_cv/layers/object_detection/roi_pool.py in keras_cv/layers/__init__.py
Cannot find keras_cv/layers/object_detection/roi_generator.py in keras_cv/layers/object_detection/__init__.py
Cannot find keras_cv/layers/object_detection/multi_class_non_max_suppression.py in keras_cv/layers/object_detection/__init__.py
Cannot find keras_cv/layers/object_detection/roi_align.py in keras_cv/layers/object_detection/__init__.py
Cannot find keras_cv/layers/object_detection/rpn_label_encoder.py in keras_cv/layers/object_detection/__init__.py
Cannot find keras_cv/layers/object_detection/roi_sampler.py in keras_cv/layers/object_detection/__init__.py
Cannot find keras_cv/layers/object_detection/box_matcher.py in keras_cv/layers/object_detection/__init__.py
Cannot find keras_cv/layers/object_detection/roi_pool.py in keras_cv/layers/object_detection/__init__.py
Cannot find keras_cv/layers/preprocessing/random_aspect_ratio.py in keras_cv/layers/preprocessing/__init__.py
Cannot find keras_cv/layers/preprocessing/jittered_resize.py in keras_cv/layers/preprocessing/__init__.py

I'm not sure the missing imports in keras_cv/layers/object_detection/ is intended or not. But random_aspect_ratio and jittered_resize should be included in keras_cv/layers/preprocessing/__init__.py

I can open a PR once approved.

P.S. This script only works for one class per file pattern. It is not optimal in general but should be effective in keras_cv/layers/.

Sanchariii commented 1 year ago

Is it still open? Can I work on the issue?

LukeWood commented 1 year ago

Hey @james77777778 thanks for opening this bug.

Some of these are true-positives, and some are false positives. We intentionally do NOT have a namespace in keras_cv.layers.object_detection, and the same should be made to be true for keras_cv.layers.preprocessing - these are NOT meant for end users and are instead only supposed to be organizational. The user facing namespace is only keras_cv.layers.

So with that in mind, all of the layers should be present in keras_cv.layers!

LukeWood commented 1 year ago

Closing for now! Thanks for the issue report @james77777778 - the exports will become clearer very soon.

We're working on integrating w/ https://github.com/fchollet/namex to generate our API!