vscode怎么跑不了下面的程序


#1

vscode怎么跑不了下面的程序,已经装过ANACONDA,已经装过Tensorflow
image
#一个只有两层的全连接神经网络
#手写数字识别

import tensorflow as tf
import numpy as np

from tensorflow.examples.tutorials.mnist import input_data

mnist = input_data.read_data_sets(’./MNIST’,one_hot=True) #读取数据

#input_layer
x = tf.placeholder(dtype=tf.float32,shape=[None,786],name=‘x’)
#lables
y = tf.placeholder(dtype=tf.float32,shape=[None,10],name=‘y’)

一次取1000张照片

batchsize = 1000

def add_layer(input_data,intput_num,output_num,activation_functon=None): #add类(一层网络的操作)
# output=input_data * weight + bias
w=tf.Variable(initial_value=tf.random_normal(shape=[intput_num,output_num]),trainable=True)
b=tf.Variable(initial_value=tf.random_normal(shape=[1,output_num]),trainable=True)
output=tf.add(tf.matmul(input_data,w),b)

# activation ? output= activation_functon(output) : output
if activation_functon:
    output = activation_functon(output)
return output

def build_nn(data): #网络搭建
hidden_layer1 = add_layer(data,784,100,activation_functon=tf.nn.sigmoid)
hidden_layer2 = add_layer(hidden_layer1,100,50,activation_functon=tf.nn.sigmoid)
output_layer = add_layer(hidden_layer2,50,10)
return output_layer

def train_nn(data): #训练网络
#output of NN
output = build_nn(data)

loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels = y,logits = output))       
# loss 损失函数(越小越好)
optimizer = tf.train.GradientDescentOptimizer(learning_rate = 1).minimize(loss)
# 采取梯度下降的优化器

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer()) # 对变量进行初始化
    for i in range(50):      # 训练50次
        epoch_cost = 0
        for _ in range(int(mnist.train.num_examples / batchsize)):
            x_data,y_data = mnist.train.next_batch(batchsize)
            cost, _ = sess.run([loss,optimizer],feed_dict={x : x_data,y : y_data})
            epoch_cost += cost
        print('Epoch',i,':',epoch_cost)  
    accuracy = tf.reduce_mean(tf.cast(tf.equal(tf.argmax(y,1),tf.argmax(output,1)),tf.float32))
    acc = sess.run(accuracy,feed_dict={x: mnist.test.images,y:mnist.test.labels})      
    print(acc)

train_nn(x)


#2

只要是跑神经网络模型,都会出现如下的错误

image


#3

有这个错误看起来是配置的问题,首先在命令行是否可以正确的跑起来?


#4

在乌班图下可以运行,但是我在win7下也安装了tensorflow,不知道为什么不行


#5

win7下的环境我也不太了解,可以看看VSCode是不是有调试log之类的输出,可能是环境变量配置的时候么有找到安装了tensorflow的python环境。