Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support python 3.7 #72

Closed
VinhLoiIT opened this issue Jan 14, 2022 · 2 comments · Fixed by #76
Closed

Support python 3.7 #72

VinhLoiIT opened this issue Jan 14, 2022 · 2 comments · Fixed by #76
Assignees
Labels
Dependencies Pull requests that update a dependency file Enhancement New feature or request

Comments

@VinhLoiIT
Copy link

Is your feature request related to a problem? Please describe.
I mainly use anomalib on Google Colab but it only supports python=3.7 at the moment. There is an error when running the training command:
python -m tools.train --model_config_path path/to/config.yaml

The error was:

Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/content/anomalib/tools/train.py", line 66, in <module>
    train()
  File "/content/anomalib/tools/train.py", line 55, in train
    model = get_model(config)
  File "/content/anomalib/anomalib/models/__init__.py", line 61, in get_model
    module = import_module(f"anomalib.models.{config.model.name}.model")
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/content/anomalib/anomalib/models/stfpm/__init__.py", line 17, in <module>
    from .model import (  # noqa # pylint: disable=unused-import
  File "/content/anomalib/anomalib/models/stfpm/model.py", line 31, in <module>
    from anomalib.data.tiler import Tiler
  File "/content/anomalib/anomalib/data/tiler.py", line 19, in <module>
    from typing import Optional, Sequence, SupportsIndex, Tuple, Union
ImportError: cannot import name 'SupportsIndex' from 'typing' (/usr/lib/python3.7/typing.py)

Suggestion
AFAIK, SupportsIndex is used for type-hint of classes that have __item__ method, but the default value doesn't seem right and int is better.

After making the below modification:

diff --git a/anomalib/data/tiler.py b/anomalib/data/tiler.py
index 5a274c2..d061337 100644
--- a/anomalib/data/tiler.py
+++ b/anomalib/data/tiler.py
@@ -16,7 +16,7 @@
 
 from itertools import product
 from math import ceil
-from typing import Optional, Sequence, SupportsIndex, Tuple, Union
+from typing import Optional, Sequence, Tuple, Union
 
 import torch
 import torchvision.transforms as T
@@ -161,7 +161,7 @@ class Tiler:
         stride: Union[int, Sequence],
         remove_border_count: int = 0,
         mode: str = "padding",
-        tile_count: SupportsIndex = 4,
+        tile_count: int = 4,
     ) -> None:
 
         self.tile_size_h, self.tile_size_w = self.__validate_size_type(tile_size)

The code works well.

I did not have further investigation, e.g. checking dependencies, other models, etc; but I think supporting python 3.7 is possible with minimal changes. I ran with the STFMP model.

@samet-akcay
Copy link
Contributor

Hi @VinhLoiIT, thank you for your suggestion! We'll try to test the 3.7 support

@samet-akcay samet-akcay added Dependencies Pull requests that update a dependency file Enhancement New feature or request labels Jan 18, 2022
@samet-akcay samet-akcay self-assigned this Jan 18, 2022
@samet-akcay
Copy link
Contributor

@VinhLoiIT your proposed changes have been added the development branch. I'm therefore closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dependencies Pull requests that update a dependency file Enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants