我正在关注TensorFlow starter guide。它特别说要在虹膜(花)分类的样本项目上进行热切的执行。
导入所需的Python模块,包括TensorFlow,并为该程序启用急切执行。急切执行使TensorFlow立即评估操作,返回具体值,而不是创建稍后执行的计算图。如果你习惯了REPL或python交互式控制台,你会有宾至如归的感觉。
所以我按照说明启用了急切的执行,并继续说明。但是,当我到达讨论如何将数据集准备到张量流数据集的部分时,我遇到了一个错误。
train_dataset = tf.data.TextLineDataset(train_dataset_fp)
train_dataset = train_dataset.skip(1) # skip the first header row
train_dataset = train_dataset.map(parse_csv) # parse each row
train_dataset = train_dataset.shuffle(buffer_size=1000) # randomize
train_dataset = train_dataset.batch(32)
# View a single example entry from a batch
features, label = iter(train_dataset).next()
print("example features:", features[0])
print("example label:", label[0])
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-61bfe99af85b> in <module>()
7
8 # View a single example entry from a batch
----> 9 features, label = iter(train_dataset).next()
10 print("example features:", features[0])
11 print("example label:", label[0])
TypeError: 'BatchDataset' object is not iterable
我只想继续关注这些例子。如何将BatchDataset
对象转换为可迭代的东西?
答案 0 :(得分:3)
事实证明,我实际上没有在导致此问题的项目中执行某些步骤。
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule, { cors: true });
await app.listen(3000);
}
bootstrap();
此代码单元格:
!pip install --upgrade tensorflow
应返回以下输出:
from __future__ import absolute_import, division, print_function
import os
import matplotlib.pyplot as plt
import tensorflow as tf
import tensorflow.contrib.eager as tfe
tf.enable_eager_execution()
print("TensorFlow version: {}".format(tf.VERSION))
print("Eager execution: {}".format(tf.executing_eagerly()))