zoukankan      html  css  js  c++  java
  • TypeError: Fetch argument 0.484375 has invalid type <class 'numpy.float32'>, must be a string or Tensor. (Can not convert a float32 into a Tensor or Operation.)

    报错:

    TypeError: Fetch argument 0.484375 has invalid type <class 'numpy.float32'>, must be a string or Tensor. (Can not convert a float32 into a Tensor or Operation.)

    出错代码:

    1 _, summaries, acc, loss = sess.run([train_step, train_summary_op, acc, cost], feed_dict={cnn.input_x1: x1, cnn.input_x2: x2, cnn.input_y: y, cnn.dropout_keep_prob: 0.5})
    2 time_str = datetime.datetime.now().isoformat()
    3 print("{}: loss {:g}, acc {:g}".format(time_str, loss, acc))

    原因:

      代码迭代了n次,第1次迭代可以打印出acc的值,第2次迭代就开始报错误。主要是因为在同一个session里面用新的acc取代了原来的acc, 第1次迭代时,两个变量都是原始数据,数据类型均为Tensor。但run之后,原来的acc就被新的acc取代了,此时两个变量的数据类型都变成了numpy.float32,所有第2次迭代的时候就会因为数据类型不是Tensor而报错。

    解决方法:


    避免重名引起数据类型输送错误,最好使用不同的命名。

    1 _, summaries, accuracy, loss = sess.run([train_step, train_summary_op, acc, cost], feed_dict={cnn.input_x1: x1, cnn.input_x2: x2, cnn.input_y: y, cnn.dropout_keep_prob: 0.5})
    2 time_str = datetime.datetime.now().isoformat()
    3 print("{}: loss {:g}, acc {:g}".format(time_str, loss, accuracy))
  • 相关阅读:
    jquery设置多个css样式
    html中设置透明遮罩层的兼容性代码
    在html中显示Flash的代码
    js setTimeout()
    jquery live hover
    leetcode第16题--3Sum Closest
    leetcode第15题--3Sum
    leetcode第14题--Longest Common Prefix
    leetcode第13题--Roman to Integer
    leetcode第12题--Integer to Roman
  • 原文地址:https://www.cnblogs.com/zymei/p/10692967.html
Copyright © 2011-2022 走看看