您的位置:首页 > 其它

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

2017-07-19 17:16 651 查看
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,成功开始训练迭代
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: