在ML中使用tensorflow,为什么我的内核不断重启



来自内核:

In[1]: runfile('/home/yannick/Documents/ML/MNIST-reco/neural_network_V1.py', wdir='/home/yannick/Documents/ML/MNIST-reco')
Restarting kernel...    
In [1]:  

问题是,当我运行代码时,它没有工作,而是重新启动内核,什么也没发生请帮我

import tensorflow as tf
import input_data
import matplotlib.pyplot as plt
import matplotlib.cm as cm
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
sess = tf.Session(config=config)
mnist = input_data.read_data_sets('MNIST_data', one_hot=True)
img = mnist.train.images[0]
img = img.reshape((28,28))
plt.imshow(img, cmap=cm.Greys)
plt.show()
x = tf.placeholder(tf.float32, [None, 784])
y_ = tf.placeholder(tf.float32, [None, 10])
# ex : [0 0 0 1 0 0 0 0 0 0 0]
W = tf.get_variable('weights', [784,10])
b = tf.get_vairable('bias', [10])
y = tf.add(tf.matmul(x,W), b)
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(labels=y_,logits=y))
train_step = tf.trin.GradientDescentOptimizer(0.001).minimize(cross_entropy)
correct_pred = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))
sess = tf.Session()
sess.run(tf.global_variable_initializer())
def feed_dict(is_training):
if is_training :
batch_x, batch_y = mnist.train.next_batch(100)
else:
batch_x, batch_y = mnist.test.images,mnist.test.labels
return {x: batch_x, y_: batch_y}
for i in range(100):
if i % 10 == 0:
acc = sess.run(accuracy, feed_dict=feed_dict(True))
print('étape %d: Précision du training:%f' % (i, acc))
else :
sess.run([train_step], feed_dict=feed_dict(True))

print('Précision Test: ', sess.run(accuracy,feed_dict=feed_dict(False)))

我需要删除我的tensorflow库,并使用anaconda重新安装它,然后它就可以工作了。这只是重新导入anaconda上的libs并重新启动spyder。hth

最新更新