Jupyter:内核似乎已经死亡。它将自动重启

时间:2018-12-07 20:25:02

标签: python tensorflow anaconda jupyter

尝试做一个识别手写数字的项目来学习张量流。使用已成功安装tensorflow的Anaconda环境(已通过线性函数模型进行了测试)。但是,它一直向我显示:内核似乎已经死亡。它将自动重启。

这是我的代码:

    import tensorflow as tf
    old_v = tf.logging.get_verbosity()
    tf.logging.set_verbosity(tf.logging.ERROR)
    from tensorflow.examples.tutorials.mnist import input_data

    mnist = input_data.read_data_sets('DESKTOP/HWnumber',one_hot=True)

    batch_size = 100

    batch_n = mnist.train.num_examples // batch_size

    x = tf.placeholder(tf.float32,[None,784])
    y = tf.placeholder(tf.float32,[None,10])

    m = tf.Variable(tf.zeros([784,10]))
    b = tf.Variable(tf.zeros([10]))
    prediction = tf.nn.softmax(tf.matmul(x,m)+b)

    loss = tf.reduce_mean(tf.square(y-prediction))
    train = tf.train.GradientDescentOptimizer(0.2).minimize(loss)

    init = tf.global_variables_initializer()


    Check = tf.equal(tf.argmax(y,1),tf.argmax(prediction,1))

    accuracy = tf.reduce_mean(tf.cast(Check,tf.float32))

    with tf.Session() as sess:
        sess.run(init)
        for Iter in range (21):
            for batch in range (batch_n):
                batchx,batchy = mnist.train.next_batch(batch_size)
                sess.run(train,feed_dict={x:batchx,y:batchy})

            acc = sess.run(accuracy,feed_dict
    {x:mnist.test.images,y:mnist.test.labels})
    print (str(Iter),str(acc))

0 个答案:

没有答案
相关问题