bhky / opennsfw2

Keras implementation of the Yahoo Open-NSFW model
MIT License
361 stars 47 forks source link

Problem with dm-tree dependency #18

Closed ghost closed 1 year ago

ghost commented 1 year ago

It says no module named 'tree' when trying to install or run opennsfw2

bhky commented 1 year ago

Hi! Thanks for your message.

I cannot reproduce your issue. Could you show me what you have done and post the full error message here?

ghost commented 1 year ago

First of all I installed Python 3.11.6 After that I openend a terminal and created a new virtual environment with "python -m venv test" and activated that virtual environment Then I run the command "pip install opennsfw2 mysql-connector-python" I tried to run my python script, but I got this error: (metadata) PS C:\Users\Gabriel\PycharmProjects\Image-Filter\nsfw-score-and-model-filter> python .\metadata-extraction.py Traceback (most recent call last): File "C:\Users\Gabriel\PycharmProjects\Image-Filter\nsfw-score-and-model-filter\metadata-extraction.py", line 242, in extracted_metadata = extract_metadata_from_parameter(parameters_metadata, image_path, nsfw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Gabriel\PycharmProjects\Image-Filter\nsfw-score-and-model-filter\metadata-extraction.py", line 35, in extract_metadata_from_paramet er import opennsfw2 as n2 File "C:\Users\Gabriel\PycharmProjects\Image-Filter\metadata\Lib\site-packages\opennsfw2__init.py", line 4, in from ._inference import Aggregation File "C:\Users\Gabriel\PycharmProjects\Image-Filter\metadata\Lib\site-packages\opennsfw2_inference.py", line 14, in from ._model import make_open_nsfw_model File "C:\Users\Gabriel\PycharmProjects\Image-Filter\metadata\Lib\site-packages\opennsfw2_model.py", line 11, in from keras_core import layers, KerasTensor, Model # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Gabriel\PycharmProjects\Image-Filter\metadata\Lib\site-packages\keras_core\init.py", line 8, in from keras_core import _tf_keras File "C:\Users\Gabriel\PycharmProjects\Image-Filter\metadata\Lib\site-packages\keras_core_tf_keras\init.py", line 8, in from keras_core import activations File "C:\Users\Gabriel\PycharmProjects\Image-Filter\metadata\Lib\site-packages\keras_core\activations\init.py", line 8, in from keras_core.src.activations import deserialize File "C:\Users\Gabriel\PycharmProjects\Image-Filter\metadata\Lib\site-packages\keras_core\src\init.py", line 1, in from keras_core.src import activations File "C:\Users\Gabriel\PycharmProjects\Image-Filter\metadata\Lib\site-packages\keras_core\src\activations\init.py", line 3, in
from keras_core.src.activations.activations import elu File "C:\Users\Gabriel\PycharmProjects\Image-Filter\metadata\Lib\site-packages\keras_core\src\activations\activations.py", line 1, in
from keras_core.src import backend File "C:\Users\Gabriel\PycharmProjects\Image-Filter\metadata\Lib\site-packages\keras_core\src\backend\
init.py", line 9, in from keras_core.src.backend.common.keras_tensor import KerasTensor File "C:\Users\Gabriel\PycharmProjects\Image-Filter\metadata\Lib\site-packages\keras_core\src\backend\common\keras_tensor.py", line 1, in import tree File "C:\Users\Gabriel\PycharmProjects\Image-Filter\metadata\Lib\site-packages\tree\init__.py", line 23, in from .sequence import _is_attrs File "C:\Users\Gabriel\PycharmProjects\Image-Filter\metadata\Lib\site-packages\tree\sequence.py", line 19, in from tree import _tree ImportError: DLL load failed while importing _tree: The specified module could not be found.

ghost commented 1 year ago

I somehow made it work on another pc (linux with python 3.9) by additionally installing tensorflow

bhky commented 1 year ago

Thanks for the error message and your update!

Yes, from this line:

from keras_core import layers, KerasTensor, Model # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

we can see that the problem came from importing Keras, which would also import TensorFlow if you are using TensorFlow backend.

I have Googled a bit and it seems that DDL load failed has been a common issue for using TensorFlow in Windows, and it's related to the version mismatch, but I don't know much about that as well.

This time, I guess the issue probably came from Python 3.11, as you have tested. I'm glad that you have found a workaround.

There is no "fix" on our side, so hopefully in some future versions TensorFlow/Keras will solve it (again).