繁体   English   中英

TypeError:DataType float32 for attr'Tindices'不在允许值列表中:int32,int64

[英]TypeError:DataType float32 for attr 'Tindices' not in list of allowed values: int32, int64

我正在做斯坦福大学的CS224n课程。 我在依赖解析器中的Assignment2 q2_parser_model.py中收到错误

== Initializing==

    Loading data... took 2.17 seconds
    Building parser... took 0.04 seconds
    Loading pretrained embeddings... took 2.16 seconds
    Vectorizing data... took 0.06 seconds
    Preprocessing training data...
    1000/1000 [==============================] - 1s     
    Building model...
    Traceback (most recent call last):
      File "q2_parser_model.py", line 286, in <module>
        main()
      File "q2_parser_model.py", line 252, in main
        model = ParserModel(config, embeddings)
      File "q2_parser_model.py", line 237, in __init__
        self.build()
      File "/home/jarvis/My projects/Machine Learning/CS224n/My assignments/assignment2/model.py", line 109, in build
        self.pred = self.add_prediction_op()
      File "q2_parser_model.py", line 149, in add_prediction_op
        x = self.add_embedding()
      File "q2_parser_model.py", line 119, in add_embedding
        features = tf.nn.embedding_lookup(embedding, self.input_placeholder)
      File "/home/jarvis/anaconda3/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/embedding_ops.py", line 110, in embedding_lookup
        validate_indices=validate_indices)
      File "/home/jarvis/anaconda3/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1293, in gather
        validate_indices=validate_indices, name=name)
      File "/home/jarvis/anaconda3/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 582, in apply_op
        _Attr(op_def, input_arg.type_attr))
      File "/home/jarvis/anaconda3/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 60, in _SatisfiesTypeConstraint
        ", ".join(dtypes.as_dtype(x).name for x in allowed_list)))
    TypeError: DataType float32 for attr 'Tindices' not in list of allowed values: int32, int64

以下是我遇到错误的代码段和行

def add_embedding(self):
        embedding = tf.Variable(self.pretrained_embeddings, name = "embedding")
    --> features = tf.nn.embedding_lookup(embedding, self.input_placeholder)
        embeddings = tf.reshape(features, [-1, self.config.n_features * 
        self.config.embedding_size])
        ### END YOUR CODE
        return embeddings

您的self.input_placeholder必须作为int32int64数组传递给tf.nn.embedding_lookup ,因此您可以:

features = tf.nn.embedding_lookup(embedding, 
                            np.asarray(self.input_placeholder, dtype=np.int32))

我弄错了,这是由于数据类型定义不正确造成的。 我将占位符定义为float32而不是int32

self.labels_placeholder = tf.placeholder(tf.int32, shape=(self.config.batch_size, self.config.n_classes))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 attr&#39;T&#39;的数据类型float32不在允许值列表中:int32,int64 在张量流中使用CNN的信号处理。 TypeError:attr&#39;Tlabels&#39;的DataType float32不在允许值列表中:int32,int64 TypeError:传递给参数&#39;ref&#39;的值的DataType int64不在允许的值列表中:float32,int32,qint8,quint8,qint32 传递给参数“shape”的值的 DataType float32 不在允许值列表中:int32、int64 KERAS 自定义丢失中的错误“类型错误:传递给参数 'reduction_indices' 的值的数据类型 float32 不在允许值列表中:int32,int64” 了解 Keras 错误:TypeError:传递给参数“shape”的值的 DataType float32 不在允许值列表中:int32、int64 Tensorflow类型错误:传递给参数&#39;shape&#39;的值具有DataType float32不在允许值列表中:int32,int64 类型错误:传递给参数“输入”的值的数据类型布尔值不在允许值列表中:float32、float64、int32、uint8、int16、int8 错误:TypeError:传递给参数“输入”的值的 DataType uint8 不在允许值列表中:float16、bfloat16、float32、float64、int32 错误:传递给参数“输入”的值的数据类型 int64 不在允许值列表中:float16、bfloat16、float32、float64?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM