Tensorflow 实践中常见的错误解决方法

1、ValueError: setting an array element with a sequence.

解决:这个错误通常是由于train_x,train_y 和 mask(test_x,test_y,mask)出现了问题。这个时候可以尝试打印部分train_x,部分train_y或mask。尤其注意他们的长度信息是否对应。遇到过的出错有:
X_train, X_test, y_train, y_test = train_test_split(data_x, data_x,test_size=0.2, random_state=4)

这里的train_y写错了。写成了data_x

2、当在tensorflow中平行的定义两张子图时报如下错误(这里定义两张子图的目的是为了在同一份代码中同时实现训练和测试,并可以在tensorflow中实现交叉验证)

ValueError: Variable bidirectional_rnn/fw/lstm_cell/kernel already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:

解决:将两张图的初始化定义在交叉验证的循环内,代码如下:

    for train_index,test_index in kf.split(data_x):
        g1 = tf.Graph()
        g2 = tf.Graph()

3、ValueError: Initializer type 'dtype: 'float64'' and explicit dtype 'dtype: 'float32'' don't match.}

解决:当用embedding_lookup()时候遇到该问题是载入的词向量数据类型不对。通常在load_embedding()函数中将载入的词向量转成np.float32类型

4、InvalidArgumentError (see above for traceback): indices[1,4,0] = 78 is not in [0, 21) [[Node: Train/model/embedding_lookup_1 = Gather[Tindices=DT_INT64, Tparams=DT_FLOAT, _class=["loc:@model/position_embed"], validate_indices=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](model/position_embed/read, IteratorGetNext:2)]]

解决:这个是由于初始化生成的词向量不够embedding_lookup去索引,因此此时检查position_embed的大小是否正确。

公众号分享机器学习,深度学习知识和技巧,以及学习资料。
在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值