【问题标题】:ValueError: Value Tensor("normalize_element/component_0:0", shape=(), dtype=int32, device=/device:CPU:0) has insufficient rank for batchingValueError: Value Tensor("normalize_element/component_0:0", shape=(), dtype=int32, device=/device:CPU:0) 用于批处理的等级不足
【发布时间】:2021-05-17 23:36:32
【问题描述】:

我正在尝试使用估算器进行预测,但出现此错误:

ValueError: Value Tensor("normalize_element/component_0:0", shape=(), dtype=int32, device=/device:CPU:0) has insufficient rank for batching.
pred = {"Team1":10764 ,
"Team1Rank":51,
"Team1Prediction":17,
"Team2":8211,
"Team2Rank":81,
"Team2Prediction":1,
"Odds1":1.3,
"Odds2":3.2,
"BestOf":3
}

def pred_fn(features, batch_size=960):
    db = tf.data.Dataset.from_tensor_slices((dict(features))).batch(batch_size)
    return db

predictions = classifier.predict(
    input_fn=lambda: pred_fn(pred))

print(list(predictions))

我遵循标准指南,尝试了不同的方法,但没有任何效果

【问题讨论】:

    标签: python python-3.x tensorflow machine-learning


    【解决方案1】:

    以下更改解决了该问题

    db = tf.data.Dataset.from_tensor_slices((dict(features))).batch(batch_size)
    

    db = tf.data.Dataset.from_tensors(dict(features)).batch(batch_size)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-25
      • 2020-06-09
      • 2019-09-17
      • 2019-10-23
      • 2018-04-27
      • 2019-07-18
      • 2019-11-24
      • 1970-01-01
      相关资源
      最近更新 更多