我在尝试使用估算器进行预测时,遇到了这个错误:
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 dbpredictions = classifier.predict( input_fn=lambda: pred_fn(pred))print(list(predictions))
我按照标准指南尝试了各种方法,但没有任何效果
回答:
以下更改解决了问题
db = tf.data.Dataset.from_tensor_slices((dict(features))).batch(batch_size)
改为
db = tf.data.Dataset.from_tensors(dict(features)).batch(batch_size)