tensorflow 程序运行时,tf.reshape()出现
TypeError: Failed to convert object of type <class 'list'> to Tensor. Contents: [-1, None, 17]. Consider casting elements to a supported type.
这是由于中间的None导致的,可以给它一个明确的值。
#max_seq_length = FLAGS.max_seq_length
# 算序列真实长度
used = tf.sign(tf.abs(input_ids))
lengths = tf.reduce_sum(used, reduction_indices=1) # [batch_size] 大小的向量,包含了当前batch中的序列长度
# 添加CRF output layer
blstm_crf = BLSTM_CRF(embedded_chars=embedding, hidden_unit=lstm_size, cell_type=cell, num_layers=num_layers,
dropout_rate=dropout_rate, initializers=initializers, num_labels=num_labels,
seq_length=FLAGS.max_seq_length, labels=labels, lengths=lengths, is_training=is_training)
原本是 FLAGS.max_seq_length赋值给max_seq_length
改为seq_length=FLAGS.max_seq_length 解决