Mengatasi Error pada Tensorflow Versi 1.6 keatas (CPU only build) pada Windows
Beberapa waktu yang lalu, saya memutuskan menggunakan backend Tensorflow pada package Keras setelah sebelumnya menggunakan backend Theano. Namun saat pertama kali akan menginstall package Tensorflow, proses installasi tidak berjalan begitu mulus, muncul error di console sebagai berikut
Traceback (most recent call last):
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", line 658, in _load_unlocked
File "", line 571, in module_from_spec
File "", line 922, in create_module
File "", line 219, in _call_with_frames_removed
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "F:\Kuliah\Tesis\Progres Tesis\Script\progress\test LSTM\_LSTM.py", line 12, in
from keras.models import Sequential
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\__init__.py", line 3, in
from . import utils
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\__init__.py", line 6, in
from . import conv_utils
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\conv_utils.py", line 9, in
from .. import backend as K
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\__init__.py", line 84, in
from .tensorflow_backend import *
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in
import tensorflow as tf
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\__init__.py", line 22, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\__init__.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", line 658, in _load_unlocked
File "", line 571, in module_from_spec
File "", line 922, in create_module
File "", line 219, in _call_with_frames_removed
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "C:\Users\abimahan\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_problems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
Setelah berselancar untuk menemukan jawaban, akhirnya saya mengetahui bahwa hal tersebut hanya terjadi jika saya menggunakan Tensorflow versi 1.6 keatas. Dan yang lebih membuat prihatin adalah, error tersebut hanya terjadi pada CPU yang belum support AVX feature (harap maklum, hardware yang saya gunakan sudah agak outdated untuk keperluan Deep Learning dan kawan-kawannya). Untuk itu, saya punya dua opsi jika ingin tetap menggunakan Tensorflow sebagai backend di Keras.
SOLUSI PERTAMA
Solusi pertama yang paling masuk akal adalah dengan melakukan downgrade dari Tensorflow versi 1.6 ke versi 1.5 atau yang lebih rendah dengan mengetikkan perintah berikut pada command prompt
pip install --upgrade --ignore-installed tensorflow==1.5
SOLUSI KEDUA
Solusi yang kedua adalah dengan menginstall package Tensorflow dengan menggunakan file .whl yang dibuild sesuai dengan arsitektur komputer saya. File .whl dapat di download melalui situs https://github.com/fo40225/tensorflow-windows-wheel/tree/master/1.6.0/py36/CPU/sse2 kemudian install file tersebut. Jika belum mengetahui bagaimana cara menginstall file .whl, dapat melihat di tutorial berikut.
Oke sekian, jika ada yang ingin didiskusikan dapat meninggalkan komentar dbawah.
Salam
2 comments
Traceback (most recent call last):
BalasHapusFile "train.py", line 146, in
for (i, l) in enumerate(lossNames):
NameError: name 'lossNames' is not defined
klo eror kaya gt gimana iya ka. saya pake tensorflow 2.1
Kalau dilihat dari error nya sepertinya bukan dari tensorflow nya, kemungkinan besar dari script yg anda buat, variabel lossNames belum/tidak dideklarasikan di awal atau variabel lossNames sudah dideklarasikan di file lain tapi file tersebut tidak terpanggil saat file train.py dieksekusi
Hapus