简体   繁体   中英

Deep Learning with Python using Tensorflow and Keras on AMD GPU with ROCm gives errors when I run the program below

I have an AMD GPU pc which I have recently started to use with Linux Mint OS I've seen a way of installing ROCm on this pc following this tutorial, but when I tried to write a Python program using Keras it threw these errors. Here is my code:

import numpy as np
from numpy import genfromtxt
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import Dense

data=genfromtxt('../DATA/bank_note_data.txt',delimiter=',')
labels=data[:,4]
features=data[:,0:4]
X=features
y=labels 

X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.33,random_state=42)

scalerObject=MinMaxScaler()
scalerObject.fit(X_train)
scaled_X_train=scalerObject.transform(X_train)
scaled_X_test=scalerObject.transform(X_test)

model=Sequential()
model.add(Dense(4,input_dim=4,activation='relu'))
model.add(Dense(8,activation='relu'))
model.add(Dense(1,activation='sigmoid'))

model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])

model.fit(scaled_X_train,y_train,epochs=50,verbose=2)
print(model.fit(scaled_X_train,y_train,epochs=50,verbose=2))

These were the errors:

Traceback (most recent call last):
  File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/usr/lib/python3.6/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/lib/python3.6/imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: librccl.so: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/cemosambora/eclipse-workspace/Deep_Learning_OpenCV/kerasBasics.py", line 5, in <module>
    from keras.models import Sequential
  File "/home/cemosambora/.local/lib/python3.6/site-packages/keras/__init__.py", line 3, in <module>
    from . import utils
  File "/home/cemosambora/.local/lib/python3.6/site-packages/keras/utils/__init__.py", line 6, in <module>
    from . import conv_utils
  File "/home/cemosambora/.local/lib/python3.6/site-packages/keras/utils/conv_utils.py", line 9, in <module>
    from .. import backend as K
  File "/home/cemosambora/.local/lib/python3.6/site-packages/keras/backend/__init__.py", line 89, in <module>
    from .tensorflow_backend import *
  File "/home/cemosambora/.local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 5, in <module>
    import tensorflow as tf
  File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/__init__.py", line 28, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/cemosambora/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/usr/lib/python3.6/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/lib/python3.6/imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: librccl.so: cannot open shared object file: No such file or directory


Failed to load the native TensorFlow runtime.

This page has some common reasons and solutions.

This error was caused by missing rccl library. After installing rocm, you need to install some ROCm Libraries :

sudo apt-get update && sudo apt-get install -y --allow-unauthenticated  rocm-dkms rocm-dev rocm-libs rccl rocm-device-libs hsa-ext-rocr-dev hsakmt-roct-dev hsa-rocr-dev rocm-opencl rocm-opencl-dev   rocm-utils  rocm-profiler cxlactivitylogger miopen-hip miopengemm

Bit late to respond, but here's my two-cents for what it may be worth. It is highly recommended that we use Ubuntu 18.04 per the pre-requisites and official support offered by ROCm Considering the holistic aspects of the way many eco-system oriented support that you might bump onto in this regard vis-a-vis Python Packages, GPU Support etc., this should be the best bet for you to consider; should you be serious about your endeavour in this regard.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM