TensorFlow Python脚本被杀死
我是TensorFlow的初学者。我的TensorFlow脚本突然退出,说TensorFlow Python脚本被杀死,python,tensorflow,Python,Tensorflow,我是TensorFlow的初学者。我的TensorFlow脚本突然退出,说已被杀死。我的代码如下: import tensorflow as tf # Load data X_train, y_train and X_valid, y_valid # An image augmentation pipeline def augment(x): x = tf.image.random_brightness(x, max_delta=0.2) x = tf.image.random
已被杀死
。我的代码如下:
import tensorflow as tf
# Load data X_train, y_train and X_valid, y_valid
# An image augmentation pipeline
def augment(x):
x = tf.image.random_brightness(x, max_delta=0.2)
x = tf.image.random_contrast(x, 0.5, 2)
return x
from sklearn.utils import shuffle
X_train, y_train = shuffle(X_train, y_train)
def LeNet(x):
# Define LeNet architecture
return logits
# Features:
x = tf.placeholder(tf.float32, (None, 32, 32, 3))
# Labels:
y = tf.placeholder(tf.int32, (None))
# Dropout probability
prob = tf.placeholder(tf.float32, (None))
# Learning rate
rate = tf.placeholder(tf.float32, (None))
rate_summary = tf.summary.scalar('learning rate', rate)
logits = LeNet(x)
accuracy_operation = # defined accuracy_operation
accuracy_summary = tf.summary.scalar('validation accuracy', accuracy_operation)
saver = tf.train.Saver()
summary = tf.summary.merge_all()
writer = tf.summary.FileWriter('./summary', tf.get_default_graph())
def evaluate(X_data, y_data):
# Return accuracy with X_data, y_data
return accuracy
with tf.Session() as sess:
saver.restore(sess, './lenet')
for i in range(EPOCHS):
X_train, y_train = shuffle(X_train, y_train)
for offset in range(0, len(X_train), BATCH_SIZE):
end = offset + BATCH_SIZE
batch_x, batch_y = X_train[offset:end], y_train[offset:end]
batch_x = sess.run(augment(batch_x))
# Run the training operation, update learning rate
validation_accuracy = evaluate(X_valid, y_valid)
writer.add_summary(sess.run(summary, feed_dict = {x: X_valid, y: y_valid, prob: 1., rate: alpha}))
我省略了我确信不会引起问题的部分。我知道哪些部分是好的,因为脚本没有给任何麻烦早些时候。在添加某些部分(主要是摘要编写器操作)后,脚本突然说
已终止
,并在执行一定数量的训练操作后退出。我怀疑这是由于内存泄漏造成的,但我无法检测到它。几天前我遇到了类似的问题。在我的例子中,正如我后来学到的那样,我的一些运算结果是计算非常繁重。我一减小张量,消息就消失了,代码也开始运行。
我不能确切地说出您的案例中出现问题的原因,但根据我的经验和您所说的(只有在添加摘要时才会出现该错误),我建议您修改X_valid,Y_valid的大小。可能只是编写器无法处理太多的数据…您可以使用linux
dmesg
命令检查输出吗?您的进程是否因内存不足而被终止?