tensorflow - tf.data.Dataset 迭代器返回 Tensor("IteratorGetNext:1", shape=(None, 16), dtype=int32) 但无法获取张量的值
问题描述
我正在尝试编写一个自定义模型,其中我正在编写一个自定义train_step
函数
我正在从自定义数据生成器创建一个“tf.data.Dataset”,例如
tds = tf.data.Dataset.from_generator(tdg.__iter__,args=None,output_types = (tf.float32,tf.int32),output_shapes = (tf.TensorShape([16,64,64,3]),tf.TensorShape([16])))
tds = tds.batch(1)
在自定义 DataGenerator 中,该__iter__
方法定义为
def __iter__(self):
for item in (self[i] for i in range(len(self))):
yield item
但是,当我试图检索train_step
函数内的数据时,x,y = data
我得到
Tensor("IteratorGetNext:0", shape=(None, 16, 64, 64, 3), dtype=float32)
和
Tensor("IteratorGetNext:1", shape=(None, 16), dtype=int32)
作为输出
如果我跑步,print(x[0])
那么我会得到
Tensor("strided_slice:0", shape=(16,), dtype=int32)
我没有得到带有numpy()
属性的张量
这哪里错了??
解决方案
推荐阅读
- javascript - 每天从 Google Cloud Firebase 存储分区中删除以 .png 结尾的文件
- machine-learning - 我的八度代码函数返回“错误:'num_iters' undefined near line 1 column 37”-Andrew Nguyen coursera machine learning course
- embed - 如何在 SourceSync 嵌入上启用调试模式?
- selenium - 我不断收到一条错误消息:“消息:会话 ID 无效”有人可以帮我吗
- macos - zsh: command not found: heruko - 如何在 Mac Catalina 上使用 Heroku CLI 启动和运行?
- android - 使用协程作用域编译 Kotlin 函数时出现 JVM 错误
- java - 使用 TestNG、Appium 和 Selenium 运行并行和顺序测试
- ruby-on-rails - ActionController::ParameterMissing(参数丢失或值为空:matatu)ruby on rails
- azure - Azure DevOps - 如何使用 TFVC 在管道任务中以编程方式创建分支
- angular - @angular/router:未检索到路由数据