tensorflow1.2训练cifar10步骤以及问题汇总

本文介绍了使用TensorFlow 1.2在CIFAR-10数据集上训练图像识别模型时遇到的问题及解决方法,包括数据集获取、模型代码修改以及运行过程中出现的AttributeError的解决策略。
摘要由CSDN通过智能技术生成

CIFAR-10数据集是机器学习中的一个通用的用于图像识别的基础数据集,官网链接为:http://www.cs.toronto.edu/~kriz/cifar.html ,下载binary version版本
CIFAR-10 网络模型部分参见官网教程下载地址,我因为打不开,在Github上找了一份 https://github.com/tensorflow/models#tensorflow-models
解压网络模型压缩包,修改cifar10.py 函数maybe_download_and_extract()如下:

def maybe_download_and_extract():
  """Download and extract the tarball from Alex's website."""
  dest_directory = FLAGS.data_dir
  if not os.path.exists(dest_directory):
    os.mkdir(dest_directory)
  filename = DATA_URL.split('/')[-1]
  filepath = os.path.join('/home/hmw/tensorflow/cifa10', filename)
  #说明:上面的路径为你下载的cifar10数据集压缩包所在文件夹
  '''if not os.path.exists(filepath):
    def _progress(count, block_size, total_size):
      sys.stdout.write('\r>> Downloading %s %.1f%%' % (filename,
          float(count * block_size) / float(total_size) * 100.0))
      sys.stdout.flush()
    filepath, _ = urllib.request.urlretrieve(DATA_URL, filepath,
                                             reporthook=_progress)
    print()
    '''
  statinfo = os.stat(filepath)
  print('Successfully downloaded', filename, statinfo.st_size, 'bytes.')
  tarfile.open(filepath, 'r:gz').extractall(dest_directory)

运行cifar10_train.py,因为tensorflow版本兼容不好会遇到若干问题,解决如下,我的解决方式是不断运行cifar10_train.py,发现错误,修改错误。参见以下几篇博客以及说明进行修改相关代码:
http://blog.csdn.net/zeuseign/article/details/72771598
http://blog.csdn.net/edwards_june/article/details/65652385
http://blog.csdn.net/c2a2o2/article/details/67639356
http://blog.csdn.net/caicai2526/article/details/72963126?utm_source=itdadao&utm_medium=referral
上面几篇博客解决问题有不齐全的,打开这几篇博客这篇找不到就找其他篇,下面附加额外博客没找到的2个解决方案:
额外问题1:AttributeError: ‘module’ object has no attribute ‘mul’
解决方法用tf.multiply替代tf.mul
额外问题2:若按照上面博客修改后仍有AttributeError: ‘module’ object has no attribute ‘summaries’,将tf.summaries修改为tf.summary.

OK,以上问题解决完了就可以开始训练了,再次运行cifar10_train.py,成功开始训练迭代

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值