【问题标题】:Unable to make predictions from Keras model due to CUDA errors由于 CUDA 错误,无法从 Keras 模型进行预测
【发布时间】:2020-10-09 06:36:38
【问题描述】:

我是 Python 新手。我按照this website 作为指导来做一些未来的预测。在我做完所有事情后,图表没有显示出来,我得到了这些错误:

2020-10-09 08:27:09.619051: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-10-09 08:27:09.620905: 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.
2020-10-09 08:27:16.105403: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2020-10-09 08:27:16.107108: W tensorflow/stream_executor/cuda/cuda_driver.cc:312] failed call to cuInit: UNKNOWN ERROR (303)
2020-10-09 08:27:16.110329: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: kwk-tech-05
2020-10-09 08:27:16.110968: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: kwk-tech-05
2020-10-09 08:27:16.111746: 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
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-10-09 08:27:16.119507: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x2624680e450 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-10-09 08:27:16.120408: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version

这是我写的代码:

import pandas as pd
import numpy as np
import tensorflow as tf
import keras
from keras.preprocessing.sequence import TimeseriesGenerator
from keras.models import Sequential
from keras.layers import LSTM, Dense
import plotly.graph_objects as go

df = pd.read_excel('T:/Python/NRN-Netze_Python/Stromverbrauch2Jahren.xlsx')
print(df.info())

df['Datum'] = pd.to_datetime(df['Datum'])
df.set_axis(df['Datum'], inplace = True)
df.drop(columns = ['Datum_u_Uhrzeit', 'Stunden', 'Minuten', 'Uhrzeit'], inplace = True)

value = df['Werte'].values
value = value.reshape((-1, 1))

split_percent = 0.80
split = int(split_percent * len(value))

value_train = value[:split]
value_test = value[split:]
date_train = df['Datum'][:split]
date_test = df['Datum'][split:]

print('')
print(len(value_train))
print(len(value_test))

look_back = 15

train_generator = TimeseriesGenerator(value_train, value_train, length = look_back, batch_size = 20)
test_generator = TimeseriesGenerator(value_test, value_test, length = look_back, batch_size = 1)

model = Sequential()
model.add(LSTM(10, activation = 'relu', input_shape = (look_back, 1)))
model.add(Dense(1))
model.compile(optimizer = 'adam', loss = 'mse')

num_epochs = 25
model.fit(train_generator, epochs = num_epochs, verbose = 1)

prediction = model.predict(test_generator)

value_train = value_train.reshape((-1))
value_test = value_test.reshape((-1))
prediction = prediction.reshape((-1))

trace1 = go.Scatter(
    x = date_train,
    y = value_train,
    mode = 'lines',
    name = 'Original'
)

trace2 = go.Scatter(
    x = date_test,
    y = value_test,
    mode = 'lines',
    name = 'Prediction'
)

layout = go.Layout(
    title = 'Strom Verbrauch In Der Wasserversorgung',
    xaxis = {'title' : 'Datum'},
    yaxis = {'title' : 'Werte'}
)

value = value.reshape((-1))

def predict(num_prediction, model):
    prediction_list = value[-look_back:]
    
    for _ in range(num_prediction):
        x = prediction_list[-look_back:]
        x = x.reshape((1, look_back, 1))
        out = model.predict(x)[0][0]
        prediction_list = np.append(prediction_list, out)
    prediction_list = prediction_list[look_back - 1:]
    
    return prediction_list

def predict_dates(num_prediction):
    last_date = df['Datum'].values[-1]
    prediction_dates = pd.date_range(last_date, periods = num_prediction + 1).tolist()
    return prediction_dates

num_prediction = 365
forecast = predict(num_prediction, model)
forecast_dates = predict_dates(num_prediction)
fig = go.Figure(data = [trace1, trace2], layout = layout)
fig.show()

【问题讨论】:

    标签: python pandas tensorflow


    【解决方案1】:

    从错误消息来看,您似乎没有为您的显卡安装 CUDA 驱动程序。

    【讨论】:

    • 我所在的电脑只有Intel HD Graphics 630,还能安装CUDA吗?
    • 没有 CUDA 用于 Nvidia 卡。但我认为你也可以在 cpu 上运行 Tensorflow,但你可能需要不同的版本。
    猜你喜欢
    • 2018-01-23
    • 2018-07-24
    • 2019-10-19
    • 2019-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-08
    • 1970-01-01
    相关资源
    最近更新 更多