haven-jeon / PyKoSpacing

Automatic Korean word spacing with Python
GNU General Public License v3.0
397 stars 118 forks source link

설치 후 실행할 때 "Shape must be at least rank 3 but is rank 2" 에러 #25

Closed lifefeel closed 2 years ago

lifefeel commented 3 years ago

사용하는 Python 버전은 3.7.4 입니다.

패키지를 git clone을 이용하여 내려 받은 후 파이썬 가상환경에 python setup.py install로 설치하였고 이상없이 설치가 되었습니다.

실행한 코드는 아래와 같습니다.

from pykospacing import Spacing
spacing = Spacing()

위와 같이 실행했는데 아래의 에러가 발생합니다.

Traceback (most recent call last):
  File "/home/project/myenv/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 1880, in _create_c_op
    c_op = pywrap_tf_session.TF_FinishOperation(op_desc)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Shape must be at least rank 3 but is rank 2 for '{{node BiasAdd}} = BiasAdd[T=DT_FLOAT, data_format="NCHW"](MatMul, unstack)' with input shapes: [?,150], [150].

TF 버전 문제인지, 잘 모르겠습니다. 확인 부탁드립니다.

haven-jeon commented 3 years ago

아래와 같이 conda env를 새로 만들어 테스트 한 결과 잘 동작하는걸 확인 했습니다.

$ conda create -n py37 python=3.7
$ conda activate py37
$ pip install git+https://github.com/haven-jeon/PyKoSpacing.git
>>> from pykospacing import Spacing
>>> spacing = Spacing()
>>> spacing('테스트잘되나모르겠다.')
'테스트 잘 되나 모르겠다.'

https://github.com/haven-jeon/PyKoSpacing/blob/master/requirements.txt 에서 버전 확인해보시길 바랍니다.

lifefeel commented 2 years ago

알려주신대로 했을 때 같은 문제가 발생합니다. 저는 conda를 사용하진 않았고, virtualenv로 설치했습니다.

혹시 몰라서 패키지 버전 목록도 같이 올립니다.

Package                 Version
----------------------- -------------------
absl-py                 0.14.1
astunparse              1.6.3
cached-property         1.5.2
cachetools              4.2.4
certifi                 2021.5.30
charset-normalizer      2.0.6
flatbuffers             1.12
gast                    0.4.0
google-auth             1.35.0
google-auth-oauthlib    0.4.6
google-pasta            0.2.0
grpcio                  1.34.1
h5py                    3.1.0
idna                    3.2
importlib-metadata      4.8.1
keras-nightly           2.5.0.dev2021032900
Keras-Preprocessing     1.1.2
Markdown                3.3.4
numpy                   1.19.5
oauthlib                3.1.1
opt-einsum              3.3.0
pip                     21.2.4
protobuf                3.18.0
pyasn1                  0.4.8
pyasn1-modules          0.2.8
pykospacing             0.5
requests                2.26.0
requests-oauthlib       1.3.0
rsa                     4.7.2
setuptools              57.5.0
six                     1.15.0
tensorboard             2.6.0
tensorboard-data-server 0.6.1
tensorboard-plugin-wit  1.8.0
tensorflow              2.5.1
tensorflow-estimator    2.5.0
termcolor               1.1.0
typing-extensions       3.7.4.3
urllib3                 1.26.7
Werkzeug                2.0.1
wheel                   0.37.0
wrapt                   1.12.1
zipp                    3.6.0

혹시 cuda나 cudnn의 문제일수도 있을까요?

haven-jeon commented 2 years ago
python -m venv ./test
source ./test/bin/activate
pip install -r requirements.txt 
pip install .
>>> from pykospacing import Spacing
2021-10-05 13:52:16.433418: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2021-10-05 13:52:16.433487: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2021-10-05 13:52:17.242181: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2021-10-05 13:52:17.242271: W tensorflow/stream_executor/cuda/cuda_driver.cc:326] failed call to cuInit: UNKNOWN ERROR (303)
2021-10-05 13:52:17.242291: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (GOGAMZA-T14s): /proc/driver/nvidia/version does not exist
2021-10-05 13:52:17.242511: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
>>> spacing = Spacing()
>>> spacing('venv에서잘되려나?')
2021-10-05 13:52:23.279219: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:176] None of the MLIR Optimization Passes are enabled (registered 2)
2021-10-05 13:52:23.279634: I tensorflow/core/platform/profile_utils/cpu_utils.cc:114] CPU Frequency: 2095989999 Hz
'venv에서 잘 되려나?'

venv에서도 잘 동작하네요.

이 패키지는 cpu 머신에서 구동하는걸 가정하고 진행했기 때문에.. cuda하고는 상관없을거 같습니다.

lifefeel commented 2 years ago

keras의 설정이 "image_data_format": "channels_first"로 되어있어서 생기는 문제였습니다. 아래 링크를 참고했습니다.

https://github.com/tensorflow/tensorflow/issues/38942#issuecomment-620463213

해결에 도움을 주셔서 감사합니다!