eto-ai / rikai

Parquet-based ML data format optimized for working with unstructured data
https://rikai.readthedocs.io/en/latest/
Apache License 2.0
137 stars 19 forks source link

Notebook example not working #660

Open ffcai opened 2 years ago

ffcai commented 2 years ago

Just tried https://github.com/eto-ai/rikai/blob/main/notebooks/Mojito.ipynb Failed to load Yolo v5 model. I'm not sure if it's my environment. This example notebook was working weeks ago.

spark.sql("""
CREATE MODEL yolov5m
OPTIONS (device="gpu", batch_size=8)
USING "torchhub:///ultralytics/yolov5:v6.0/yolov5m";
""")
Py4JJavaError: An error occurred while calling o97.sql.
: java.lang.RuntimeException: 2022-05-10 23:04:08,169 INFO Rikai (base.py:60): Resolving model yolov5m from torchhub:///ultralytics/yolov5:v6.0/yolov5mTraceback (most recent call last):  File "<string>", line 6, in <module>  File "/usr/local/lib/python3.8/dist-packages/rikai/spark/sql/codegen/base.py", line 125, in command_from_spec    return registry.resolve(row_spec)  File "/usr/local/lib/python3.8/dist-packages/rikai/spark/sql/codegen/base.py", line 61, in resolve    return udf_from_spec(self.make_model_spec(raw_spec))  File "/usr/local/lib/python3.8/dist-packages/rikai/experimental/torchhub/torchhub_registry.py", line 83, in make_model_spec    return TorchHubModelSpec(repo_or_dir, model, raw_spec)  File "/usr/local/lib/python3.8/dist-packages/rikai/experimental/torchhub/torchhub_registry.py", line 48, in __init__    if has_func(model_type + ".MODEL_TYPE"):  File "/usr/local/lib/python3.8/dist-packages/rikai/internal/reflection.py", line 34, in has_func    mod = importlib.import_module(module)  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module    return _bootstrap._gcd_import(name[level:], package, level)  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import  File "<frozen importlib._bootstrap>", line 991, in _find_and_load  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked  File "<frozen importlib._bootstrap_external>", line 783, in exec_module  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed  File "/usr/local/lib/python3.8/dist-packages/rikai/contrib/torchhub/ultralytics/yolov5/__init__.py", line 1, in <module>    from rikai.contrib.torchhub.ultralytics.yolov5 import yolov5  File "/usr/local/lib/python3.8/dist-packages/rikai/contrib/torchhub/ultralytics/yolov5/yolov5.py", line 43, in <module>    from rikai.pytorch.models import TorchModelTypeImportError: cannot import name 'TorchModelType' from 'rikai.pytorch.models' (/usr/local/lib/python3.8/dist-packages/rikai/pytorch/models/__init__.py)
    at ai.eto.rikai.sql.spark.Python$.execute(Python.scala:58)
    at org.apache.spark.sql.rikai.model.ModelResolver$.resolve(ModelResolver.scala:101)
    at ai.eto.rikai.sql.model.PyImplRegistry.resolve(Registry.scala:67)
    at ai.eto.rikai.sql.model.Registry$.resolve(Registry.scala:199)
    at ai.eto.rikai.sql.spark.execution.CreateModelCommand.run(CreateModelCommand.scala:62)
    at org.apache.spark.sql.execution.command.ExecutedCommandExec.sideEffectResult$lzycompute(commands.scala:70)
    at org.apache.spark.sql.execution.command.ExecutedCommandExec.sideEffectResult(commands.scala:68)
    at org.apache.spark.sql.execution.command.ExecutedCommandExec.executeCollect(commands.scala:79)
    at org.apache.spark.sql.Dataset.$anonfun$logicalPlan$1(Dataset.scala:228)
    at org.apache.spark.sql.Dataset.$anonfun$withAction$1(Dataset.scala:3687)
    at org.apache.spark.sql.execution.SQLExecution$.$anonfun$withNewExecutionId$5(SQLExecution.scala:103)
    at org.apache.spark.sql.execution.SQLExecution$.withSQLConfPropagated(SQLExecution.scala:163)
    at org.apache.spark.sql.execution.SQLExecution$.$anonfun$withNewExecutionId$1(SQLExecution.scala:90)
    at org.apache.spark.sql.SparkSession.withActive(SparkSession.scala:775)
    at org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:64)
    at org.apache.spark.sql.Dataset.withAction(Dataset.scala:3685)
    at org.apache.spark.sql.Dataset.<init>(Dataset.scala:228)
    at org.apache.spark.sql.Dataset$.$anonfun$ofRows$2(Dataset.scala:99)
    at org.apache.spark.sql.SparkSession.withActive(SparkSession.scala:775)
    at org.apache.spark.sql.Dataset$.ofRows(Dataset.scala:96)
    at org.apache.spark.sql.SparkSession.$anonfun$sql$1(SparkSession.scala:618)
    at org.apache.spark.sql.SparkSession.withActive(SparkSession.scala:775)
    at org.apache.spark.sql.SparkSession.sql(SparkSession.scala:613)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
    at py4j.Gateway.invoke(Gateway.java:282)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:238)
    at java.base/java.lang.Thread.run(Thread.java:829)
da-liii commented 2 years ago

https://github.com/eto-ai/rikai/pull/671#issuecomment-1169960885

Error message:

Py4JJavaError: An error occurred while calling o36.sql.
: java.lang.RuntimeException: 2022-06-29 20:53:09,545 INFO Rikai (base.py:60): Resolving model yolov5m from torchhub:///ultralytics/yolov5:v6.0/yolov5mTraceback (most recent call last):  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/internal/reflection.py", line 34, in has_func    mod = importlib.import_module(module)
  File "/Users/da/.pyenv/versions/3.8.10/lib/python3.8/importlib/__init__.py", line 127, in import_module    return _bootstrap._gcd_import(name[level:], package, level)  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import  File "<frozen importlib._bootstrap>", line 991, in _find_and_load  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/contrib/torchhub/ultralytics/yolov5/__init__.py", line 1, in <module>    from rikai.contrib.torchhub.ultralytics.yolov5 import yolov5
  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/contrib/torchhub/ultralytics/yolov5/yolov5.py", line 43, in <module>    from rikai.pytorch.models import TorchModelType
  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/pytorch/models/__init__.py", line 17, in <module>    import rikai.pytorch.models.convnext
  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/pytorch/models/convnext.py", line 22, in <module>    "convnext", pretrained_fn=torchvision.models.convnext_baseAttributeError: module 'torchvision.models' has no attribute 'convnext_base'During handling of the above exception, another exception occurred:Traceback (most recent call last):  File "<string>", line 6, in <module>
  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/spark/sql/codegen/base.py", line 125, in command_from_spec    return registry.resolve(row_spec)
  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/spark/sql/codegen/base.py", line 61, in resolve    return udf_from_spec(self.make_model_spec(raw_spec))
  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/experimental/torchhub/torchhub_registry.py", line 83, in make_model_spec    return TorchHubModelSpec(repo_or_dir, model, raw_spec)
  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/experimental/torchhub/torchhub_registry.py", line 48, in __init__    if has_func(model_type + ".MODEL_TYPE"):  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/internal/reflection.py", line 39, in has_func    mod = importlib.import_module(module)  File "/Users/da/.pyenv/versions/3.8.10/lib/python3.8/importlib/__init__.py", line 127, in import_module    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/contrib/torchhub/ultralytics/yolov5/__init__.py", line 1, in <module>    from rikai.contrib.torchhub.ultralytics.yolov5 import yolov5
  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/contrib/torchhub/ultralytics/yolov5/yolov5.py", line 43, in <module>    from rikai.pytorch.models import TorchModelType 
 File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/pytorch/models/__init__.py", line 17, in <module>    import rikai.pytorch.models.convnext
  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/pytorch/models/convnext.py", line 22, in <module>    "convnext", pretrained_fn=torchvision.models.convnext_base
AttributeError: module 'torchvision.models' has no attribute 'convnext_base'

While the following code snippet works fine

Python 3.8.10 (default, May 19 2021, 11:01:55)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import rikai
>>> rikai.__version__.version
'0.1.12'
>>> import rikai.pytorch.models.convnext
>>>
da-liii commented 2 years ago
>>> import rikai.contrib.torchhub.ultralytics.yolov5.MODEL_TYPE
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/contrib/torchhub/ultralytics/yolov5/__init__.py", line 1, in <module>
    from rikai.contrib.torchhub.ultralytics.yolov5 import yolov5
  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/contrib/torchhub/ultralytics/yolov5/yolov5.py", line 43, in <module>
    from rikai.pytorch.models import TorchModelType
ImportError: cannot import name 'TorchModelType' from 'rikai.pytorch.models' (/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/pytorch/models/__init__.py)
>>> from rikai.pytorch.models import TorchModelType
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'TorchModelType' from 'rikai.pytorch.models' (/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/pytorch/models/__init__.py)

Could be fixed by correctly importing TorchModelType.

da-liii commented 2 years ago

There seems to be a breaking change in #606 .

da-liii commented 2 years ago
>>> import rikai.contrib.torchhub.ultralytics.yolov5.MODEL_TYPE
/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/torch/torch_version.py:3: UserWarning: Module rikai was already imported from /Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/__init__.py, but /Users/da/github/Tubitv/rikai-yolov5 is being added to sys.path
  from pkg_resources import packaging  # type: ignore[attr-defined]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/contrib/torchhub/ultralytics/yolov5/__init__.py", line 1, in <module>
    from rikai.contrib.torchhub.ultralytics.yolov5 import yolov5
  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/contrib/torchhub/ultralytics/yolov5/yolov5.py", line 43, in <module>
    from rikai.pytorch.models.torch import TorchModelType
  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/pytorch/models/__init__.py", line 17, in <module>
    import rikai.pytorch.models.convnext
  File "/Users/da/.pyenv/versions/rikai-yolov5/lib/python3.8/site-packages/rikai/pytorch/models/convnext.py", line 22, in <module>
    "convnext", pretrained_fn=torchvision.models.convnext_base
AttributeError: module 'torchvision.models' has no attribute 'convnext_base'