【发布时间】:2016-11-23 01:46:16
【问题描述】:
我正在关注this link 中的教程并尝试更改模型的评估方法(在底部)。我想获得前 5 名的评估,我正在尝试使用以下代码:
topFiver=tf.nn.in_top_k(y, y_, 5, name=None)
但是,这会产生以下错误:
File "AlexNet.py", line 111, in <module>
topFiver = tf.nn.in_top_k(pred, y, 5, name=None)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_nn_ops.py", line 346, in in_top_k
targets=targets, k=k, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/op_def_library.py", line 486, in apply_op
_Attr(op_def, input_arg.type_attr))
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/op_def_library.py", line 59, in _SatisfiesTypeConstraint
", ".join(dtypes.as_dtype(x).name for x in allowed_list)))
TypeError: DataType float32 for attr 'T' not in list of allowed values: int32, int64
据我所知,问题是tf.nn.in_top_k() 仅适用于tf.int32 或tf.int64 数据,但我的数据是tf.float32 格式。有什么解决方法吗?
【问题讨论】:
标签: tensorflow