Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.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中获取无效的arguminterror_Python_Numpy_Tensorflow_Conv Neural Network_Invalid Argument - Fatal编程技术网

Python 在Tensorflow中获取无效的arguminterror

Python 在Tensorflow中获取无效的arguminterror,python,numpy,tensorflow,conv-neural-network,invalid-argument,Python,Numpy,Tensorflow,Conv Neural Network,Invalid Argument,我创建了一个用于预测图像标签的CNN。我训练过它。现在我想使用我的模型来预测新图像的标签。我给CNN的代码是:- def LeNet(x): # Arguments used for tf.truncated_normal, randomly defines variables for the weights and biases for each layer mu = 0 sigma = 0.1 # SOLUTION: Layer 1: Con

我创建了一个用于预测图像标签的CNN。我训练过它。现在我想使用我的模型来预测新图像的标签。我给CNN的代码是:-

    def LeNet(x):    
    # Arguments used for tf.truncated_normal, randomly defines variables for the weights and biases for each layer
    mu = 0
    sigma = 0.1

    # SOLUTION: Layer 1: Convolutional. Input = 32x32x3. Output = 28x28x6.
    conv1_W = tf.Variable(tf.truncated_normal(shape=(5, 5, 3, 6), mean = mu, stddev = sigma))
    conv1_b = tf.Variable(tf.zeros(6))
    conv1   = tf.nn.conv2d(x, conv1_W, strides=[1, 1, 1, 1], padding='VALID') + conv1_b

    # SOLUTION: Activation.
    conv1 = tf.nn.relu(conv1)


    # SOLUTION: Pooling. Input = 28x28x6. Output = 14x14x6.
    conv1 = tf.nn.max_pool(conv1, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='VALID')

    # SOLUTION: Layer 2: Convolutional. Output = 10x10x16.
    conv2_W = tf.Variable(tf.truncated_normal(shape=(5, 5, 6, 16), mean = mu, stddev = sigma))
    conv2_b = tf.Variable(tf.zeros(16))
    conv2   = tf.nn.conv2d(conv1, conv2_W, strides=[1, 1, 1, 1], padding='VALID') + conv2_b

    # SOLUTION: Activation.
    conv2 = tf.nn.relu(conv2)



    # SOLUTION: Pooling. Input = 10x10x16. Output = 5x5x16.
    conv2 = tf.nn.max_pool(conv2, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='VALID')

    # SOLUTION: Flatten. Input = 5x5x16. Output = 400.
    fc0   = flatten(conv2)

    # SOLUTION: Layer 3: Fully Connected. Input = 400. Output = 120.
    fc1_W = tf.Variable(tf.truncated_normal(shape=(400, 120), mean = mu, stddev = sigma))
    fc1_b = tf.Variable(tf.zeros(120))
    fc1   = tf.matmul(fc0, fc1_W) + fc1_b

    # SOLUTION: Activation.
    fc1    = tf.nn.relu(fc1)
    fc1    = tf.nn.dropout(fc1,0.6)

    # SOLUTION: Layer 4: Fully Connected. Input = 120. Output = 84.
    fc2_W  = tf.Variable(tf.truncated_normal(shape=(120, 84), mean = mu, stddev = sigma))
    fc2_b  = tf.Variable(tf.zeros(84))
    fc2    = tf.matmul(fc1, fc2_W) + fc2_b

    # SOLUTION: Activation.
    fc2    = tf.nn.relu(fc2)
    fc2    = tf.nn.dropout(fc2,0.7)


    # SOLUTION: Layer 5: Fully Connected. Input = 84. Output = 43.
    fc3_W  = tf.Variable(tf.truncated_normal(shape=(84, 43), mean = mu, stddev =        sigma))
    fc3_b  = tf.Variable(tf.zeros(43))

    logits = tf.matmul(fc2, fc3_W) + fc3_b

    return logits

    x = tf.placeholder(tf.float32, (None, 32, 32, 3))
    y = tf.placeholder(tf.int32, (None))
    one_hot_y = tf.one_hot(y, 43)

    rate = 0.001
    logits = LeNet(x)
    cross_entropy = tf.nn.softmax_cross_entropy_with_logits(logits=logits,                     labels=one_hot_y)
    loss_operation = tf.reduce_mean(cross_entropy)
    optimizer = tf.train.AdamOptimizer(learning_rate = rate)
    training_operation = optimizer.minimize(loss_operation)

    correct_prediction = tf.equal(tf.argmax(logits, 1), tf.argmax(one_hot_y, 1))
accuracy_operation = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
saver = tf.train.Saver()

def evaluate(X_data, y_data):
    num_examples = len(X_data)
    total_accuracy = 0
    sess = tf.get_default_session()
    for offset in range(0, num_examples, BATCH_SIZE):
        batch_x, batch_y = X_data[offset:offset+BATCH_SIZE],     y_data[offset:offset+BATCH_SIZE]
        accuracy = sess.run(accuracy_operation, feed_dict={x: batch_x, y: batch_y})
        total_accuracy += (accuracy * len(batch_x))
    return total_accuracy / num_examples

with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
num_examples = len(X_train)

print("Training...")
print()
for i in range(EPOCHS):
    X_train, y_train = shuffle(X_train, y_train)
    for offset in range(0, num_examples, BATCH_SIZE):
        end = offset + BATCH_SIZE
        batch_x, batch_y = X_train[offset:end], y_train[offset:end]
        sess.run(training_operation, feed_dict={x: batch_x, y: batch_y})

    training_accuracy = evaluate(X_train,y_train)  
    validation_accuracy = evaluate(X_valid, y_valid)
    print("EPOCH {} ...".format(i+1))
    print("training Accuracy = {:.3f}".format(training_accuracy))
    print("Validation Accuracy = {:.3f}".format(validation_accuracy))
    print()

saver.save(sess, './lenet')
print("Model saved")
现在我从网上下载了一些图片,并想预测它们的标签。处理图像并将其转换为numpy.ndarray的代码如下:-

from os import listdir
from PIL import Image as PImage
from matplotlib import pyplot as plt

def loadImages(path):
    # return array of images

    imagesList = listdir(path)
    loadedImages = []
    basewidth = 32
    hsize = 32
    for image in imagesList:
        img = PImage.open(path + image)
        img = img.resize((basewidth,hsize),PIL.Image.ANTIALIAS)
        loadedImages.append(img)

    return loadedImages

    path = "C:\\Users\\che\\CarND-Traffic-Sign-Classifier-Project\\images\\"

    image_in_pixels = []

for image in imgs:
    image = np.array(image.getdata(),np.float32).reshape(32, 32, 3)
    image_in_pixels.append(image)

    print(type(image_in_pixels))
    test_images = np.array(image_in_pixels)
    print(test_images.shape)
    print(type(test_images[0]))
    x = tf.placeholder(dtype=tf.float32,shape=(None,32,32,3))
    keep_prob = tf.placeholder(dtype=tf.float32)

    with tf.Session() as sess:
      saver.restore(sess, tf.train.latest_checkpoint('.'))
      vals = sess.run(logits,feed_dict={x:test_images,keep_prob: 1.})
      print (vals)

I am getting the following error.

    InvalidArgumentError                      Traceback (most recent call last)
C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
   1021     try:
-> 1022       return fn(*args)
   1023     except errors.OpError as e:

C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\client\session.py in _run_fn(session, feed_dict, fetch_list, target_list, options, run_metadata)
   1003                                  feed_dict, fetch_list, target_list,
-> 1004                                  status, run_metadata)
   1005 

C:\ProgramData\Anaconda3\envs\carnd-term1\lib\contextlib.py in __exit__(self, type, value, traceback)
     65             try:
---> 66                 next(self.gen)
     67             except StopIteration:

C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\framework\errors_impl.py in raise_exception_on_not_ok_status()
    465           compat.as_text(pywrap_tensorflow.TF_Message(status)),
--> 466           pywrap_tensorflow.TF_GetCode(status))
    467   finally:

InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_2' with dtype float
     [[Node: Placeholder_2 = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]

During handling of the above exception, another exception occurred:

InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-213-6e880af91901> in <module>()
      4 with tf.Session() as sess:
      5   saver.restore(sess, tf.train.latest_checkpoint('.'))
----> 6   vals = sess.run(logits,feed_dict={x:test_images,keep_prob: 1.})
      7   print (vals)

C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata)
    765     try:
    766       result = self._run(None, fetches, feed_dict, options_ptr,
--> 767                          run_metadata_ptr)
    768       if run_metadata:
    769         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
    963     if final_fetches or final_targets:
    964       results = self._do_run(handle, final_targets, final_fetches,
--> 965                              feed_dict_string, options, run_metadata)
    966     else:
    967       results = []

C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\client\session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
   1013     if handle is None:
   1014       return self._do_call(_run_fn, self._session, feed_dict, fetch_list,
-> 1015                            target_list, options, run_metadata)
   1016     else:
   1017       return self._do_call(_prun_fn, self._session, handle, feed_dict,

C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
   1033         except KeyError:
   1034           pass
-> 1035       raise type(e)(node_def, op, message)
   1036 
   1037   def _extend_graph(self):

InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_2' with dtype float
     [[Node: Placeholder_2 = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]

Caused by op 'Placeholder_2', defined at:
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\ipykernel\__main__.py", line 3, in <module>
    app.launch_new_instance()
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
    app.start()
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\ipykernel\kernelapp.py", line 474, in start
    ioloop.IOLoop.instance().start()
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\zmq\eventloop\ioloop.py", line 177, in start
    super(ZMQIOLoop, self).start()
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tornado\ioloop.py", line 887, in start
    handler_func(fd_obj, events)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tornado\stack_context.py", line 275, in null_wrapper
    return fn(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\zmq\eventloop\zmqstream.py", line 440, in _handle_events
    self._handle_recv()
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\zmq\eventloop\zmqstream.py", line 472, in _handle_recv
    self._run_callback(callback, msg)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\zmq\eventloop\zmqstream.py", line 414, in _run_callback
    callback(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tornado\stack_context.py", line 275, in null_wrapper
    return fn(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\ipykernel\kernelbase.py", line 276, in dispatcher
    return self.dispatch_shell(stream, msg)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\ipykernel\kernelbase.py", line 228, in dispatch_shell
    handler(stream, idents, msg)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\ipykernel\kernelbase.py", line 390, in execute_request
    user_expressions, allow_stdin)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\ipykernel\ipkernel.py", line 196, in do_execute
    res = shell.run_cell(code, store_history=store_history, silent=silent)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\ipykernel\zmqshell.py", line 501, in run_cell
    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\IPython\core\interactiveshell.py", line 2717, in run_cell
    interactivity=interactivity, compiler=compiler, result=result)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\IPython\core\interactiveshell.py", line 2821, in run_ast_nodes
    if self.run_code(code, result):
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\IPython\core\interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-17-55707f3825d1>", line 1, in <module>
    x = tf.placeholder(tf.float32, (None, 32, 32, 3))
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\ops\array_ops.py", line 1502, in placeholder
    name=name)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 2149, in _placeholder
    name=name)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 763, in apply_op
    op_def=op_def)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\framework\ops.py", line 2327, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\framework\ops.py", line 1226, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder_2' with dtype float
     [[Node: Placeholder_2 = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
现在,我需要使用保存的模型预测这些图像的标签。 我的代码如下:-

from os import listdir
from PIL import Image as PImage
from matplotlib import pyplot as plt

def loadImages(path):
    # return array of images

    imagesList = listdir(path)
    loadedImages = []
    basewidth = 32
    hsize = 32
    for image in imagesList:
        img = PImage.open(path + image)
        img = img.resize((basewidth,hsize),PIL.Image.ANTIALIAS)
        loadedImages.append(img)

    return loadedImages

    path = "C:\\Users\\che\\CarND-Traffic-Sign-Classifier-Project\\images\\"

    image_in_pixels = []

for image in imgs:
    image = np.array(image.getdata(),np.float32).reshape(32, 32, 3)
    image_in_pixels.append(image)

    print(type(image_in_pixels))
    test_images = np.array(image_in_pixels)
    print(test_images.shape)
    print(type(test_images[0]))
    x = tf.placeholder(dtype=tf.float32,shape=(None,32,32,3))
    keep_prob = tf.placeholder(dtype=tf.float32)

    with tf.Session() as sess:
      saver.restore(sess, tf.train.latest_checkpoint('.'))
      vals = sess.run(logits,feed_dict={x:test_images,keep_prob: 1.})
      print (vals)

I am getting the following error.

    InvalidArgumentError                      Traceback (most recent call last)
C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
   1021     try:
-> 1022       return fn(*args)
   1023     except errors.OpError as e:

C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\client\session.py in _run_fn(session, feed_dict, fetch_list, target_list, options, run_metadata)
   1003                                  feed_dict, fetch_list, target_list,
-> 1004                                  status, run_metadata)
   1005 

C:\ProgramData\Anaconda3\envs\carnd-term1\lib\contextlib.py in __exit__(self, type, value, traceback)
     65             try:
---> 66                 next(self.gen)
     67             except StopIteration:

C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\framework\errors_impl.py in raise_exception_on_not_ok_status()
    465           compat.as_text(pywrap_tensorflow.TF_Message(status)),
--> 466           pywrap_tensorflow.TF_GetCode(status))
    467   finally:

InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_2' with dtype float
     [[Node: Placeholder_2 = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]

During handling of the above exception, another exception occurred:

InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-213-6e880af91901> in <module>()
      4 with tf.Session() as sess:
      5   saver.restore(sess, tf.train.latest_checkpoint('.'))
----> 6   vals = sess.run(logits,feed_dict={x:test_images,keep_prob: 1.})
      7   print (vals)

C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata)
    765     try:
    766       result = self._run(None, fetches, feed_dict, options_ptr,
--> 767                          run_metadata_ptr)
    768       if run_metadata:
    769         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
    963     if final_fetches or final_targets:
    964       results = self._do_run(handle, final_targets, final_fetches,
--> 965                              feed_dict_string, options, run_metadata)
    966     else:
    967       results = []

C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\client\session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
   1013     if handle is None:
   1014       return self._do_call(_run_fn, self._session, feed_dict, fetch_list,
-> 1015                            target_list, options, run_metadata)
   1016     else:
   1017       return self._do_call(_prun_fn, self._session, handle, feed_dict,

C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
   1033         except KeyError:
   1034           pass
-> 1035       raise type(e)(node_def, op, message)
   1036 
   1037   def _extend_graph(self):

InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_2' with dtype float
     [[Node: Placeholder_2 = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]

Caused by op 'Placeholder_2', defined at:
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\ipykernel\__main__.py", line 3, in <module>
    app.launch_new_instance()
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
    app.start()
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\ipykernel\kernelapp.py", line 474, in start
    ioloop.IOLoop.instance().start()
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\zmq\eventloop\ioloop.py", line 177, in start
    super(ZMQIOLoop, self).start()
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tornado\ioloop.py", line 887, in start
    handler_func(fd_obj, events)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tornado\stack_context.py", line 275, in null_wrapper
    return fn(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\zmq\eventloop\zmqstream.py", line 440, in _handle_events
    self._handle_recv()
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\zmq\eventloop\zmqstream.py", line 472, in _handle_recv
    self._run_callback(callback, msg)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\zmq\eventloop\zmqstream.py", line 414, in _run_callback
    callback(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tornado\stack_context.py", line 275, in null_wrapper
    return fn(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\ipykernel\kernelbase.py", line 276, in dispatcher
    return self.dispatch_shell(stream, msg)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\ipykernel\kernelbase.py", line 228, in dispatch_shell
    handler(stream, idents, msg)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\ipykernel\kernelbase.py", line 390, in execute_request
    user_expressions, allow_stdin)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\ipykernel\ipkernel.py", line 196, in do_execute
    res = shell.run_cell(code, store_history=store_history, silent=silent)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\ipykernel\zmqshell.py", line 501, in run_cell
    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\IPython\core\interactiveshell.py", line 2717, in run_cell
    interactivity=interactivity, compiler=compiler, result=result)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\IPython\core\interactiveshell.py", line 2821, in run_ast_nodes
    if self.run_code(code, result):
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\IPython\core\interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-17-55707f3825d1>", line 1, in <module>
    x = tf.placeholder(tf.float32, (None, 32, 32, 3))
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\ops\array_ops.py", line 1502, in placeholder
    name=name)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 2149, in _placeholder
    name=name)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 763, in apply_op
    op_def=op_def)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\framework\ops.py", line 2327, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site-packages\tensorflow\python\framework\ops.py", line 1226, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder_2' with dtype float
     [[Node: Placeholder_2 = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
x=tf.placeholder(dtype=tf.float32,shape=(无,32,32,3))
keep_prob=tf.placeholder(dtype=tf.float32)
使用tf.Session()作为sess:
saver.restore(sess、tf.train.latest_checkpoint('.'))
运行(logits,feed_dict={x:test_映像,keep_prob:1.})
打印(VAL)
我得到以下错误。
InvalidArgumentError回溯(最后一次最近调用)
C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site packages\tensorflow\python\client\session.py in\u do\u call(self,fn,*args)
1021请尝试:
->1022返回fn(*args)
1023除错误外。操作错误为e:
C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site packages\tensorflow\python\client\session.py in\u run\fn(会话、提要、获取列表、目标列表、选项、运行元数据)
1003进货目录、进货目录、目标目录、,
->1004状态,运行(元数据)
1005
C:\ProgramData\Anaconda3\envs\carnd-term1\lib\contextlib.py in\uuuuuuu exit\uuuuuu(self、type、value、traceback)
65尝试:
--->66下一个(self.gen)
67除停止迭代外:
C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site packages\tensorflow\python\framework\errors\u impl.py在raise\u exception\u on\u not\u ok\u status()中
465兼容as_文本(pywrap_tensorflow.TF_消息(状态)),
-->466 pywrap_tensorflow.TF_GetCode(状态))
467最后:
InvalidArgumentError:必须为带有dtype float的占位符张量“占位符2”提供一个值
[[Node:Placeholder_2=Placeholder[dtype=DT_FLOAT,shape=[],[u device=“/job:localhost/replica:0/task:0/cpu:0”]()]
在处理上述异常期间,发生了另一个异常:
InvalidArgumentError回溯(最后一次最近调用)
在()
4将tf.Session()作为sess:
5.恢复(sess、tf.train.最新检查点('.'))
---->6 vals=sess.run(logits,feed\u dict={x:test\u image,keep\u prob:1.})
7打印(VAL)
C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site packages\tensorflow\python\client\session.py处于运行状态(self、fetches、feed\u dict、options、run\u元数据)
765试试:
766结果=self.\u运行(无、获取、馈送、选项、,
-->767运行(元数据)
768如果运行\u元数据:
769 proto_data=tf_session.tf_GetBuffer(运行元数据ptr)
C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site packages\tensorflow\python\client\session.py in\u run(self、handle、fetches、feed\u dict、options、run\u元数据)
963如果最终用户获取或最终用户目标:
964 results=self.\u do\u run(句柄、最终目标、最终获取、,
-->965提要(文本字符串、选项、运行元数据)
966其他:
967结果=[]
C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site packages\tensorflow\python\client\session.py in\u do\u run(self、handle、target\u list、fetch\u list、feed\u dict、options、run\u元数据)
1013如果句柄为“无”:
1014返回self.\u do\u调用(\u run\u fn,self.\u会话,feed\u dict,fetch\u list,
->1015目标\u列表、选项、运行\u元数据)
1016其他:
1017返回self.\u do.\u调用(\u prun\u fn,self.\u会话,句柄,提要\u dict,
C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site packages\tensorflow\python\client\session.py in\u do\u call(self,fn,*args)
1033除键错误外:
1034通行证
->1035提升类型(e)(节点定义、操作、消息)
1036
1037定义扩展图(自):
InvalidArgumentError:必须为带有dtype float的占位符张量“占位符2”提供一个值
[[Node:Placeholder_2=Placeholder[dtype=DT_FLOAT,shape=[],[u device=“/job:localhost/replica:0/task:0/cpu:0”]()]
由op“占位符2”引起,定义于:
文件“C:\ProgramData\Anaconda3\envs\carnd-term1\lib\runpy.py”,第184行,作为主模块运行
“\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
文件“C:\ProgramData\Anaconda3\envs\carnd-term1\lib\runpy.py”,第85行,在运行代码中
exec(代码、运行\全局)
文件“C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site packages\ipykernel\\uuuuuu main\uuuuuu.py”,第3行,在
app.launch_new_instance()
文件“C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site packages\traitlets\config\application.py”,第658行,在启动实例中
app.start()
文件“C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site packages\ipykernel\kernelapp.py”,第474行,在开始处
ioloop.ioloop.instance().start()
文件“C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site packages\zmq\eventloop\ioloop.py”,第177行,在开始处
super(ZMQIOLoop,self).start()
文件“C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site packages\tornado\ioloop.py”,第887行,在开始处
handler_func(fd_obj,事件)
文件“C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site packages\tornado\stack\u context.py”,第275行,空包装
返回fn(*args,**kwargs)
文件“C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site packages\zmq\eventloop\zmqstream.py”,第440行,位于事件句柄中
self.\u handle\u recv()
文件“C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site packages\zmq\eventloop\zmqstream.py”,第472行,位于
self.\u运行\u回调(回调,消息)
文件“C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site packages\zmq\eventloop\zmqstream.py”,第414行,在运行回调中
回调(*args,**kwargs)
文件“C:\ProgramData\Anaconda3\envs\carnd-term1\lib\site packages\tornado\stack\u context.py”,第行