May 2020
我想请教下,map 这里如果不使用 lambda 表达式的话,直接使用 函数 ,需要怎么写函数?
def preprocess (……):
……
return ……
原文代码如下:
使用 TessorFlow Datasets 载入 “tf_flowers” 数据集
dataset = tfds.load (“tf_flowers”, split=tfds.Split.TRAIN, as_supervised=True)
对 dataset 进行大小调整、打散和分批次操作
dataset = dataset.map (lambda img, label: (tf.image.resize (img, [224, 224]) / 255.0, label))
.shuffle (1024)
.batch (32)
迭代数据
for images, labels in dataset:
# 对 images 和 labels 进行操作
1 reply
May 2020
▶ snowkylin
你好!我尝试了这个代码,提示报错,不知是否是我的代码有问题?
代码如下:
import tensorflow as tf
import tensorflow_datasets as tfds
import matplotlib.pyplot as plt
mnist_dataset = tfds.load (“mnist”, split=tfds.Split.TRAIN)
def rot90 (image, label):
image = tf.image.rot90 (image)
return image, label
mnist_dataset = mnist_dataset.map (rot90)
for image, label in mnist_dataset:
plt.title (label.numpy ())
plt.imshow (image.numpy ()[:, :, 0])
plt.show ()
提示报错信息如下:
Traceback (most recent call last):
File “C:/Users/Administrator/Desktop/certification/Answer/tfds_test3.py”, line 13, in
mnist_dataset = mnist_dataset.map (rot90)
…………
TypeError: in converted code:
TypeError: tf__rot90 () missing 1 required positional argument: 'label'
May 2020
▶ snowkylin
我打印了一下这个 mnist_dataset,是单个完整的结构,我感觉是不是需要 转换 或者 提取 成某种 类似 (image, label) 的结构?
<_OptionsDataset shapes: {image: (28, 28, 1), label: ()}, types: {image: tf.uint8, label: tf.int64}>
我查询了 google 的关于这个数据集的文档,还是没有解决。
1 reply
May 2020
▶ pepure
一个比较简单的方法是载入时直接加入 as_supervised=True
选项。
1 reply
May 2020
▶ snowkylin
可以了, as_supervised=True
可以的,或者通过 Info 里的 Features 名称来索引到也可以。
June 2020
June 2020
▶ snowkylin
请教下,比如 image = tf.image.random_brightness (image, max_delta=0.5) # Random brightness,这条语句,比如输入的 image 参数是 10 张图片(0 维的长度是 10),通过处理,输出的长度是多少?怎么设置数据增强的倍数?就是 哪个参数可以设定 把图片数量增强多少倍?
1 reply
June 2020
▶ pepure
June 2020
请问我 install tensorflow_datasets 后,import tensorflow_datasets 报错提示:ImportError: cannot import name ‘extract_zipped_paths’,这是什么原因呢?
1 reply
June 2020
▶ YangXuanWang
June 2020
▶ snowkylin
谢谢,我按照链接里面更改了 requests 的版本解决了
August 2020
你好,我 load 数据集时,出现这种错误,要怎么处理啊, The last failure: Unavailable: Error executing an HTTP request: libcurl code 6 meaning ‘Couldn’t resolve host name’, error details: Couldn’t resolve host ‘metadata’".感谢
1 reply
August 2020
▶ snow-zhai
看起来是网络问题。TensorFlow Datasets 需要从谷歌的服务器下载数据集,建议设置代理或使用 Colab 测试代码。
October 2020
▶ ai-lijunhua
October 2020
出现版本错误,是否需要升级TensorFlow版本?ImportError: This version of TensorFlow Datasets requires TensorFlow version >= 2.1.0; Detected an installation of version 1.15.3. Please upgrade TensorFlow to proceed.
1 reply