簡體   English   中英

TensorFlow-TensorBoard的問題

[英]Issue with TensorFlow-TensorBoard

我正在關注本教程 我已經按原樣復制了代碼,所以看不到任何錯誤。 當我嘗試添加以下行以為TensorBoard創建文件時,就會出現錯誤:

logs_path = '/tensor_board'
writer = tf.summary.FileWriter(logs_path, graph=tf.get_default_graph())
# RUN
sess.run(init, writer)

當我運行整個代碼時,Python返回此錯誤:

Traceback (most recent call last):
  File "tf_number_recon.py", line 39, in <module>
    sess.run(init, writer)
  File "C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line 766, in run
    run_metadata_ptr)
  File "C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line 913, in _run
    feed_dict = nest.flatten_dict_items(feed_dict)
  File "C:\Python35\lib\site-packages\tensorflow\python\util\nest.py", line 171, in flatten_dict_items
    raise TypeError("input must be a dictionary")
TypeError: input must be a dictionary

我不明白為什么它不能正常運行。 有人可以幫我嗎?

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

# importing the dataset used to train the Neural Network
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

# importing Tensorflow
import tensorflow as tf                                                          

import argparse
import sys

# Declaring some imjmportant variables
x = tf.placeholder(tf.float32, [None, 784])                                 # x is 
W = tf.Variable(tf.zeros([784, 10]))                                        # W creará 10 vectores de evidencia, uno para cada numero entre 0-9
b = tf.Variable(tf.zeros([10]))                                             # b is 
y = tf.nn.softmax(tf.matmul(x, W) + b)                                      # y será la salida. Aqui definimos el modelo
y_ = tf.placeholder(tf.float32, [None, 10])                                 #

# Cross Entropy: mide lo lejos que nuestra predicción está de la realidad, para así mejorar la red neuronal (no controla lo bien que lo hace, sino más bien lo mal que lo hace)
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))

# Se pide que durante el proceso se minimize el cross entropy
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)

# initializing the variables
init = tf.global_variables_initializer()

# Run a session and initialize the operations
sess = tf.Session()
# Tensor Board
logs_path = '/tensor_board'
writer = tf.summary.FileWriter(logs_path, graph=tf.get_default_graph())
# RUN
sess.run(init, writer)

# Loop for training
for i in range(1000):
  batch_xs, batch_ys = mnist.train.next_batch(100)
  sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})

# Evaluate the model
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
eficacia = sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels})
print(eficacia)

進行這些更改后,代碼可以毫無問題地運行

logs_path = './tensor_board' 

sess.run(init)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM