【发布时间】:2021-02-23 17:04:29
【问题描述】:
我使用 Keras 编写了一个程序。当我运行程序时,它会崩溃并出现如下错误:
2021-02-23 18:50:50. : W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2021-02-23 18:50:50. : 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.
Traceback (most recent call last):
File "C:/Users/USER/PycharmProjects/Sofia/main.py", line 26, in <module>
X = dataset[:,0:8]
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\frame.py", line 3024, in __getitem__
indexer = self.columns.get_loc(key)
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\indexes\base.py", line 3080, in get_loc
return self._engine.get_loc(casted_key)
File "pandas\_libs\index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index.pyx", line 75, in pandas._libs.index.IndexEngine.get_loc
TypeError: '(slice(None, None, None), slice(0, 8, None))' is an invalid key
这是我的代码:
# Develop Neural Network with Keras
# Load Libraries
# first neural network with keras tutorial
from keras.models import Sequential
from keras.layers import Dense
import numpy
from pandas import read_csv
# fix random seed for reproducibility
seed = 7
numpy.random.seed(seed)
# Load Data
dataset = read_csv('pima-indians-diabetes.data.csv', delimiter=',')
# split into input (X) and output (y) variables
X = dataset[:,0:8]
y = dataset[:,8]
# Define Keras Model
model = Sequential()
model.add(Dense(12, input_dim=8, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
# Compile Keras Model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# Fit Keras Model
model.fit(X, y, epochs=150, batch_size=10)
# Evaluate Keras
_, accuracy = model.evaluate(X, y)
print('Accuracy: %.2f' % (accuracy*100))
我该如何解决这个错误?
【问题讨论】:
-
您的代码不会重现错误。了解如何创建minimal, reproducible example。
标签: python tensorflow keras deep-learning neural-network