当使用tensorflow时出现分段错误(核心转储)错误,我的代码是:
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.layers import Embedding
from keras.layers import LSTM
from keras.utils import to_categorical
model = Sequential()
max_features = 100
model.add(Embedding(max_features, output_dim=256))
model.add(LSTM(128))
model.add(Dropout(0.5))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
print("model is ok ")
答案 0 :(得分:0)
Segmentation fault
表示您尝试访问您无权访问的内存。如果您选择正确的 Tensorflow
组合,CUDA
和 cuDNN
将解决此问题。您可以参考tested build configuration。
我能够毫无问题地执行上述代码。请参考下图
import tensorflow as tf
print(tf.__version__)
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Embedding, LSTM
model = Sequential()
max_features = 100
model.add(Embedding(max_features, output_dim=256))
model.add(LSTM(128))
model.add(Dropout(0.5))
model.add(Dense(1, activation='sigmoid'))
model.summary()
model.compile(loss='binary_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
print("model is ok ")
输出:
2.5.0
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
embedding (Embedding) (None, None, 256) 25600
_________________________________________________________________
lstm (LSTM) (None, 128) 197120
_________________________________________________________________
dropout (Dropout) (None, 128) 0
_________________________________________________________________
dense (Dense) (None, 1) 129
=================================================================
Total params: 222,849
Trainable params: 222,849
Non-trainable params: 0
_________________________________________________________________
model is ok