Tensorflow,Cifar10数据集遇到的问题,no attribute 'maybe_download_and_extract'

最近在看《TensorFlow 实战》今天看到第五章卷积神经网络时,按照书上的做法遇到了一些问题。

书中使用cifar10类下载导入数据如下

cifar10.maybe_download_and_extract()

之后执行的时候遇到了这个错误

AttributeError: module 'cifar10' has no attribute 'maybe_download_and_extract'

出于好奇,就顺着这个错误去找源头,发现cifar10.py里面已经没有这个函数了。

然后再往下看,发现了这么一句

images_train, labels_train = cifar10_input.distorted_inputs(data_dir = data_dir, batch_size = batch_size)
images_test, labels_test = cifar10_input.inputs(eval_data = True,
                                                data_dir = data_dir,
                                                batch_size = batch_size)

这两个导入数据的函数随便点击一个进去,看源码是这样的

def distorted_inputs(batch_size):
  """Construct distorted input for CIFAR training using the Reader ops.

  Args:
    batch_size: Number of images per batch.

  Returns:
    images: Images. 4D tensor of [batch_size, IMAGE_SIZE, IMAGE_SIZE, 3] size.
    labels: Labels. 1D tensor of [batch_size] size.
  """
  return _get_images_labels(batch_size, tfds.Split.TRAIN, distords=True)

你会发现里面压根没有data_dir参数!

然后就把上面两句里面的data_dir参数去掉了,就正常使用了,也不需要使用cifar10.maybe_download_and_extract()这个方法了。如下:

# 生成训练数据
images_train, labels_train = cifar10_input.distorted_inputs(batch_size = batch_size)

# 生成预测数据
images_test, labels_test = cifar10_input.inputs(eval_data = True,
                                                batch_size = batch_size)

发现这个问题折腾了半天,中间也搜索了很多解决方法,也去github上确认了是不是我下错了的原因(第一次不相信git clone,dbq)。如果对这个有兴趣,可以继续顺着源码看下去(本人功底不太行,看不下去了),这个改动很方便,也不需要在后面的代码里面设置路径了,避免了一些可能因为路径导致的错误。

你可能感兴趣的:(Tensorflow,Cifar10数据集遇到的问题,no attribute 'maybe_download_and_extract')