zoukankan      html  css  js  c++  java
  • tensorflow几个常见错误

    错误一:二分类,标签y

    ValueError: Cannot feed value of shape (128,1) for Tensor u'input_y_2:0', which has shape '(?, 2)'

    我的输入y_train维度为(128,1),即是一个向量,batch_size为128.

    在tensorflow中你在做数据喂养的时候你输入的是一个一维数组如:[0,1,0],他的shape 为(3,)

    在tensorflow中一维数组是不能与同样的一维数组进行运算的,必须通过reshape成为(1,3)而

    另一个一维数组必须是(3,1)才能相乘,但是在numpy中两个一维数组相乘是不会报错的,

    这个原因是在tensorflow中向量是不能和矩阵进行运算的,你需要把他改成二维的矩阵才能运算;

    故:将原来的y_train = [0,1,1,0,1,0,……]改成 [ [ 0] , [1] , [1] , [0], [1] , [0] ,……]形式

    y_train = np.array(y_train[start_index: end_index]).reshape(-1, 1)

    接着产生第二个错误:

    InvalidArgumentError: You must feed a value for placeholder tensor 'input/y-input' with dtype float and shape [?,2]
    记住:二分类的num_classes = 1,这里报错是因为我的num_classes = 2。

    接着产生第三错误:双向RNN的模型

    Tensorflow: unable to share dense/kernel - ValueError: Trying to share variable dense/kernel, but specified shape (128, 1) and found shape (128, 2)

    原因:name_scope可能取相同的名字。

    解决:

    (第一)

    • Give each layer a unique name
    • Put everything in a variable_scope with reuse=tf.AUTO_REUSE (for the Adam optimizer)

    (第二):

    删除这一个代码【虽然不知道原因是什么,merge_all会报错】:merged_summary = tf.summary.merge_all()

  • 相关阅读:
    windbg学习.expr和masm表达式
    ThisCall调用分析
    windbg学习 gc j(Execute IfElse).if
    windbg学习¥{} Alias Interpreter 别名解释器
    windbg学习!vadump和.hh和!vprotc
    windbg学习 .lines
    windbg学习条件断点
    $<, $><, $$<, $$><, $$>a< (Run Script File)
    windbg学习?? 和 ?
    vimbook–OPL –official publications library
  • 原文地址:https://www.cnblogs.com/Lee-yl/p/11233986.html
Copyright © 2011-2022 走看看