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()

  • 相关阅读:
    php 函数strpos()
    uploadfy api中文文档
    thinkphp + 美图秀秀api 实现图片裁切上传,带数据库
    mysql 操作用户权限
    window.location 小结)
    turn.js 图书翻页效果
    thinkphp 内置标签volist 控制换行
    js 数据类型转换
    quartz 2.2.1
    Mysql测试链接
  • 原文地址:https://www.cnblogs.com/Lee-yl/p/11233986.html
Copyright © 2011-2022 走看看