具有动态维度的Tensorflow占位符实例
我正在使用Tensorflow对MNIST进行分类,并尝试实现两个函数具有动态维度的Tensorflow占位符实例,tensorflow,Tensorflow,我正在使用Tensorflow对MNIST进行分类,并尝试实现两个函数 data = model.x # placeholder of data. shape is (None, 782) label = model.y #placeholder of label. shape is (None,) logit = model.logit # placeholder of logit. shape is (None, 10) 这三个是我在自定义类中处理的占位符变量 我想做的是让logits对应
data = model.x # placeholder of data. shape is (None, 782)
label = model.y #placeholder of label. shape is (None,)
logit = model.logit # placeholder of logit. shape is (None, 10)
这三个是我在自定义类中处理的占位符变量
我想做的是让logits对应的标签
want=logit[tf.range(n),label]
但是,我无法从变量中获取n
,因为它被声明为动态维度。
另外,当我把n作为随机值,比如100,我得到了错误消息
TypeError: Only integers, slices (`:`), ellipsis (`...`), tf.newaxis (`None`) and scalar tf.int32/tf.int64 tensors are valid indices, got <tf.Tensor 'range_14:0' shape=(100,) dtype=int32>
TypeError:只有整数、切片(`:`)、省略号(`…`)、tf.newaxis(`None`)和标量tf.int32/tf.int64张量是有效的索引,明白了吗
我现在该怎么办?如何使用标签
访问和获取值?能否请您共享完整的可复制代码,以便我们可以尝试帮助您。谢谢请您分享完整的可复制代码,以便我们可以尝试帮助您。谢谢