Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TensorFlow:ValueError:不支持任何值_Python_Tensorflow_Neural Network_Deep Learning - Fatal编程技术网

Python TensorFlow:ValueError:不支持任何值

Python TensorFlow:ValueError:不支持任何值,python,tensorflow,neural-network,deep-learning,Python,Tensorflow,Neural Network,Deep Learning,但是当我试图运行这段代码时,我遇到了一个奇怪的错误 import tensorflow as tf import matplotlib.pyplot as plt from tensorflow.examples.tutorials.mnist import input_data mnist=input_data.read_data_sets('MNIST_DATA/',one_hot=True) def init_weights(shape): init_random_dist=t

但是当我试图运行这段代码时,我遇到了一个奇怪的错误

import tensorflow as tf
import matplotlib.pyplot as plt

from tensorflow.examples.tutorials.mnist import input_data

mnist=input_data.read_data_sets('MNIST_DATA/',one_hot=True)
def init_weights(shape):
    init_random_dist=tf.truncated_normal(shape,stddev=0.1)

    return tf.Variable(init_random_dist)
def init_bias(shape):
    init_bias_vals=tf.constant(0.1,shape=shape)
    return tf.Variable(init_bias_vals)
def conv2d(x,W):

    return tf.nn.conv2d(x,W,strides=[1,1,1,1],padding='SAME')
def max_pool_2by2(x):
    tf.nn.max_pool(x,ksize=[1,2,2,1],strides=[1,2,2,1],padding='SAME')
def conv(input_x,shape):
    W=init_weights(shape)
    b=init_bias([shape[3]])
    return tf.nn.relu(conv2d(input_x,W)+b )
def normal(input_layer,size):
    input_size=int(input_layer.get_shape()[1])
    W=init_weights([input_size,size])
    b=init_bias([size])
    return tf.matmul(input_layer,W)+b
x=tf.placeholder(tf.float32,shape=[None,784])
y_true=tf.placeholder(tf.float32,shape=[None,10])
x_image=tf.reshape(x,[-1,28,28,1])

 conv1=conv(x_image,shape=[5,5,1,32])
 conv1_pooling=max_pool_2by2(conv1)
# # conv2=conv(conv1_pooling,shape=[5,5,32,64])
 conv2=conv(conv1_pooling,shape=[5,5,32,64])
 conv2_pooling=max_pool_2by2(conv2)
 conv2_flat=tf.reshape(conv2_pooling,[-1,7*7*64])
 full_layer=tf.nn.relu(normal(conv2_flat,1024))
所有这些代码都不是从教程中学习的,但当我尝试运行该教程的jupyter笔记本时,代码执行得很好,执行后没有问题或错误 我不知道我的代码出现错误的原因

感谢您的任何帮助 EDIT1:我没有在tensorflow会话中运行此代码
教程结束后,导师要求运行此代码以检查任何类型的问题,因此问题在于您忘记了在
max_pool_2by2
中返回,即:

ValueError: None values not supported.

During handling of the above exception, another exception occurred:
因此,完整的代码应为:

def max_pool_2by2(x):
    return tf.nn.max_pool(x,ksize=[1,2,2,1],strides=[1,2,2,1],padding='SAME')

函数名不是conv,而是convulation\u layer,我编辑了这段代码,你能再试一次吗
import tensorflow as tf
import matplotlib.pyplot as plt

from tensorflow.examples.tutorials.mnist import input_data

mnist=input_data.read_data_sets('MNIST_DATA/',one_hot=True)
def init_weights(shape):
    init_random_dist=tf.truncated_normal(shape,stddev=0.1)
    return tf.Variable(init_random_dist)

def init_bias(shape):
    init_bias_vals=tf.constant(0.1,shape=shape)
    return tf.Variable(init_bias_vals)

def conv2d(x,W, name):
    return tf.nn.conv2d(x,W,strides=[1,1,1,1],padding='SAME',name=name)

def max_pool_2by2(x):
    return tf.nn.max_pool(x,ksize=[1,2,2,1],strides=[1,2,2,1],padding='SAME')

def convolutional_layer(input_x,shape,name):
    W=init_weights(shape)
    b=init_bias([shape[3]])
    return tf.nn.relu(conv2d(input_x,W, name)+b )

def normal(input_layer,size):
    input_size=int(input_layer.get_shape()[1])
    W=init_weights([input_size,size])
    b=init_bias([size])
    return tf.matmul(input_layer,W)+b

x=tf.placeholder(tf.float32,shape=[None,784], name='x')
y_true=tf.placeholder(tf.float32,shape=[None,10], name='y_true')
x_image=tf.reshape(x,[1,28,28,1])
conv1=convolutional_layer(x_image,shape=[5,5,1,32],name='conv1')
print(conv1.get_shape())
conv1_pooling=max_pool_2by2(conv1)
print(conv1_pooling.get_shape())
conv2=convolutional_layer(conv1_pooling,shape=[5,5,32,64], name='conv2')
conv2_pooling=max_pool_2by2(conv2)
conv2_flat=tf.reshape(conv2_pooling,[-1,7*7*64])
full_layer=tf.nn.relu(normal(conv2_flat,1024))