CNN:TypeError:期望的int32,得到的列表包含' _Message'代替

时间:2017-09-07 05:39:26

标签: python tensorflow deep-learning

当我尝试用Tensorflow训练CNN方法时,我收到了这个错误:

Traceback (most recent call last):
File "./train.py", line 87, in 
l2_reg_lambda=FLAGS.l2_reg_lambda)

TypeError: Expected int32, got list containing Tensors of type '_Message' instead.

我该如何解决?

这是我的代码:

with tf.Graph().as_default():
    session_conf = tf.ConfigProto(
      allow_soft_placement=FLAGS.allow_soft_placement,
      log_device_placement=FLAGS.log_device_placement)
    sess = tf.Session(config=session_conf)
    with sess.as_default():
        cnn = TextCNN(
            sequence_length=x_train.shape[1],
            num_classes=2,
            vocab_size=len(vocab_processor.vocabulary_),
            embedding_size=FLAGS.embedding_dim,
            filter_sizes=list(map(int, FLAGS.filter_sizes.split(","))),
            num_filters=FLAGS.num_filters,
            l2_reg_lambda=FLAGS.l2_reg_lambda) (line 87)

1 个答案:

答案 0 :(得分:0)

x_train.shape[1]返回Tensor并且在sess.run()之前不会计算它的值,因此您应该传递int32值而不是形状[1]。