【问题标题】:arise error Segmentation fault (core dumped) when I use tensorflow当我使用 tensorflow 时出现错误分段错误(核心转储)
【发布时间】:2021-05-26 18:50:32
【问题描述】:

使用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 ")

【问题讨论】:

  • 没有发生在我身上,代码看起来不错。可能和安装过程有关。能否说说 keras 和 tensorflow 的版本,你在哪个平台上,以及你是如何安装这些库的。

标签: tensorflow keras


【解决方案1】:

Segmentation fault 表示您试图访问您无权访问的内存。如果您选择TensorflowCUDAcuDNN 的正确组合将解决此问题。可以参考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 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多