(下载的时候没有提示 不知道是正在下 还是出现错误 卡着了)。。一直没有反应

下载前要以管理员身份运行 sudo su 再 python examples/finetune_flickr_style/assemble_data.py --workers=1 --images=2000 --seed 831486

或者在命令前加sudo

参考了 http://blog.csdn.net/lujiandong1/article/details/50495454

在使用这个教程时,主要遇到了两个问题:

1、数据下不下来。

  1. python examples/finetune_flickr_style/assemble_data.py --workers=1 --images=2000 --seed 831486

运行上述指令时,程序莫名其妙就不动了,也不下载文件,程序也没有挂掉,好像进入了死锁状态。

查看源程序:assemble_data.py,可以看出assemble_data.py用了大量多线程,多进程。我的解决方案就是改源程序,不使用进程来下载了。并且,对下载进行了超时限定,超过6s就认为超时,进而不下载。

====================================================================================================

assemble_data.py中使用多线程,多进程的源代码如下:

  1. pool = multiprocessing.Pool(processes=num_workers)
  2. map_args = zip(df['image_url'], df['image_filename'])
  3. results = pool.map(download_image, map_args)

===================================================================================================

我修改后的源码如下:

  1. #!/usr/bin/env python3
  2. """
  3. Form a subset of the Flickr Style data, download images to dirname, and write
  4. Caffe ImagesDataLayer training file.
  5. """
  6. import os
  7. import urllib
  8. import hashlib
  9. import argparse
  10. import numpy as np
  11. import pandas as pd
  12. from skimage import io
  13. import multiprocessing
  14. import socket
  15. # Flickr returns a special image if the request is unavailable.
  16. MISSING_IMAGE_SHA1 = '6a92790b1c2a301c6e7ddef645dca1f53ea97ac2'
  17. example_dirname = os.path.abspath(os.path.dirname(__file__))
  18. caffe_dirname = os.path.abspath(os.path.join(example_dirname, '../..'))
  19. training_dirname = os.path.join(caffe_dirname, 'data/flickr_style')
  20. def download_image(args_tuple):
  21. "For use with multiprocessing map. Returns filename on fail."
  22. try:
  23. url, filename = args_tuple
  24. if not os.path.exists(filename):
  25. urllib.urlretrieve(url, filename)
  26. with open(filename) as f:
  27. assert hashlib.sha1(f.read()).hexdigest() != MISSING_IMAGE_SHA1
  28. test_read_image = io.imread(filename)
  29. return True
  30. except KeyboardInterrupt:
  31. raise Exception()  # multiprocessing doesn't catch keyboard exceptions
  32. except:
  33. return False
  34. def mydownload_image(args_tuple):
  35. "For use with multiprocessing map. Returns filename on fail."
  36. try:
  37. url, filename = args_tuple
  38. if not os.path.exists(filename):
  39. urllib.urlretrieve(url, filename)
  40. with open(filename) as f:
  41. assert hashlib.sha1(f.read()).hexdigest() != MISSING_IMAGE_SHA1
  42. test_read_image = io.imread(filename)
  43. return True
  44. except KeyboardInterrupt:
  45. raise Exception()  # multiprocessing doesn't catch keyboard exceptions
  46. except:
  47. return False
  48. if __name__ == '__main__':
  49. parser = argparse.ArgumentParser(
  50. description='Download a subset of Flickr Style to a directory')
  51. parser.add_argument(
  52. '-s', '--seed', type=int, default=0,
  53. help="random seed")
  54. parser.add_argument(
  55. '-i', '--images', type=int, default=-1,
  56. help="number of images to use (-1 for all [default])",
  57. )
  58. parser.add_argument(
  59. '-w', '--workers', type=int, default=-1,
  60. help="num workers used to download images. -x uses (all - x) cores [-1 default]."
  61. )
  62. parser.add_argument(
  63. '-l', '--labels', type=int, default=0,
  64. help="if set to a positive value, only sample images from the first number of labels."
  65. )
  66. args = parser.parse_args()
  67. np.random.seed(args.seed)
  68. # Read data, shuffle order, and subsample.
  69. csv_filename = os.path.join(example_dirname, 'flickr_style.csv.gz')
  70. df = pd.read_csv(csv_filename, index_col=0, compression='gzip')
  71. df = df.iloc[np.random.permutation(df.shape[0])]
  72. if args.labels > 0:
  73. df = df.loc[df['label'] < args.labels]
  74. if args.images > 0 and args.images < df.shape[0]:
  75. df = df.iloc[:args.images]
  76. # Make directory for images and get local filenames.
  77. if training_dirname is None:
  78. training_dirname = os.path.join(caffe_dirname, 'data/flickr_style')
  79. images_dirname = os.path.join(training_dirname, 'images')
  80. if not os.path.exists(images_dirname):
  81. os.makedirs(images_dirname)
  82. df['image_filename'] = [
  83. os.path.join(images_dirname, _.split('/')[-1]) for _ in df['image_url']
  84. ]
  85. # Download images.
  86. num_workers = args.workers
  87. if num_workers <= 0:
  88. num_workers = multiprocessing.cpu_count() + num_workers
  89. print('Downloading {} images with {} workers...'.format(
  90. df.shape[0], num_workers))
  91. #pool = multiprocessing.Pool(processes=num_workers)
  92. map_args = zip(df['image_url'], df['image_filename'])
  93. #results = pool.map(download_image, map_args)
  94. socket.setdefaulttimeout(6)
  95. results = []
  96. for item in map_args:
  97. value = mydownload_image(item)
  98. results.append(value)
  99. if value == False:
  100. print 'Flase'
  101. else:
  102. print '1'
  103. # Only keep rows with valid images, and write out training file lists.
  104. print len(results)
  105. df = df[results]
  106. for split in ['train', 'test']:
  107. split_df = df[df['_split'] == split]
  108. filename = os.path.join(training_dirname, '{}.txt'.format(split))
  109. split_df[['image_filename', 'label']].to_csv(
  110. filename, sep=' ', header=None, index=None)
  111. print('Writing train/val for {} successfully downloaded images.'.format(
  112. df.shape[0]))
 

修改主要有以下几点:

1、#!/usr/bin/env python3 使用python3

2、

  1. #pool = multiprocessing.Pool(processes=num_workers)
  2. map_args = zip(df['image_url'], df['image_filename'])
  3. #results = pool.map(download_image, map_args)
  4. socket.setdefaulttimeout(6)
  5. results = []
  6. for item in map_args:
  7. value = mydownload_image(item)
  8. results.append(value)
  9. if value == False:
  10. print 'Flase'
  11. else:
  12. print '1'
  13. # Only keep rows with valid images, and write out training file lists.
  14. print len(results)

只使用单线程下载,不使用多线程,多进程下载。并且,设定连接的超时时间为6s,socket.setdefaulttimeout(6)。

经过上述改进,就可以把数据下载下来。

===================================================================================================

2、

在运行命令:

  1. ./build/tools/caffe train -solver models/finetune_flickr_style/solver.prototxt -weights models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel

时遇到错误:

Failed to parse NetParameter file: models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel

出错的原因是我们传入的数据bvlc_reference_caffenet.caffemodel 并不是二进制的。

原因:因为我是在win7下,把bvlc_reference_caffenet.caffemodel下载下来,再使用winSCP传输到服务器上,直接在服务器上使用wget下载,速度太慢了,但是在传输的过程中winSCP就把bvlc_reference_caffenet.caffemodel的格式给篡改了,导致bvlc_reference_caffenet.caffemodel不是二进制的。

解决方案,把winSCP的传输格式设置成二进制,那么就可以解决这个问题。

详情见博客:http://blog.chinaunix.net/uid-20332519-id-5585964.html

Fine-tuning CaffeNet for Style Recognition on “Flickr Style” Data 数据下载遇到的问题的更多相关文章

  1. CaffeNet用于Flickr Style数据集上的风格识别

    转自 http://blog.csdn.net/liumaolincycle/article/details/48501423 微调是基于已经学习好的模型的,通过修改结构,从已学习好的模型权重中继续训 ...

  2. (原)caffe中fine tuning及使用snapshot时的sh命令

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5946041.html 参考网址: http://caffe.berkeleyvision.org/tu ...

  3. Fine Tuning

    (转载自:WikiPedia) Fine tuning is a process to take a network model that has already been trained for a ...

  4. L23模型微调fine tuning

    resnet185352 链接:https://pan.baidu.com/s/1EZs9XVUjUf1MzaKYbJlcSA 提取码:axd1 9.2 微调 在前面的一些章节中,我们介绍了如何在只有 ...

  5. style="visibility: hidden" 和 style=“display:none”区别

    大多数人很容易将CSS属性display和visibility混淆,它们看似没有什么不同,其实它们的差别却是很大的. visibility属性用来确定元素是显示还是隐藏的,这用visibility=& ...

  6. Html style="visibility:hidden"与style="display:none"的区别

    style="visibility:hidden": 使对象在网页上隐藏,但该对象在网页上所占的空间没有改变. style="display:none": 使对 ...

  7. ckplayer 中的style.swf 中的 style.xml 中的修改方法

    style.swf ---- > style.zip ---- > 解压成文件夹 ---- > 打开style.xml ---- > 修改 最重要的是修改保存style.xml ...

  8. matplotlib 可视化 —— 定制画布风格 Customizing plots with style sheets(plt.style)

    Customizing plots with style sheets - Matplotlib 1.5.1 documentation 1. 使用和显示其他画布风格 >> import ...

  9. style="visibility: hidden"和 style=“display:none”之间的区别

    style=“display:none” 隐藏页面元素: <html> <head> <script type="text/javascript"&g ...

随机推荐

  1. 全能VIP音乐在线解析

    浏览器安装暴力猴扩展即可使用 // ==UserScript== // @name 全能VIP音乐在线解析 // @version 0.0.10 // @homepage https://greasy ...

  2. hdu1385 Minimum Transport Cost 字典序最小的最短路径 Floyd

    求最短路的算法最有名的是Dijkstra.所以一般拿到题目第一反应就是使用Dijkstra算法.但是此题要求的好几对起点和终点的最短路径.所以用Floyd是最好的选择.因为其他三种最短路的算法都是单源 ...

  3. open source project for recommendation system

    原文链接:http://blog.csdn.net/cserchen/article/details/14231153 目前互联网上所能找到的知名开源推荐系统(open source project ...

  4. 我的C++笔记(Hello World)

    其实在学习C++之前,是因为自己想学AI,但是发现好多AI教程都是使用C语言来进行讲解的,真心感觉到C真的计算机的基础语言行业的共同语言.至于为什么是C++,主要是C++是从C语言演变而来的,兼容C, ...

  5. (转)基于MVC4+EasyUI的Web开发框架经验总结(6)--在页面中应用下拉列表的处理

    http://www.cnblogs.com/wuhuacong/p/3840321.html 在很多Web界面中,我们都可以看到很多下拉列表的元素,有些是固定的,有些是动态的:有些是字典内容,有些是 ...

  6. 系统A一定会按照自我的样子改造世界

    A一定会按照自己的样子去构建系统A1,A1一定还会按照自己的样子去构建系统A1.1,A1.1一定还是会按照自我的样子去构建A1.1.1……我们编程,我们改造世界,我们的方向是被注定要朝着构建人造人的方 ...

  7. PuTTY 命令行改进 有效解决 中文乱码

    PuTTY  是一个免费且跨平台的并支持SSH和Telnet 的客户端, 包括xterm 终端模拟器. 它由Simon Tatham 编写并维护. http://www.chiark.greenend ...

  8. Module.exports 和 exports

    Module.exports 和 exports 在node中,没有全局作用域,只有模块作用域,外部访问不到内部,内部也访问不到外部,那么模块间如何通信 当加载一个模块的时候,被加载模块的代码在第一次 ...

  9. [CodeForces]986A Fair

    大意:给一张图,每个图上有一个数,问以每个点为源点,经过的点包含k种数字的最小距离. 显然跑最短路会T,但我们注意到边权一定.某次学校考试就是类似题,可以bfs做,复杂度O(n),每种货物做一次,复杂 ...

  10. vim+astyle安装使用

    astyle下载安装 wget https://sourceforge.net/projects/astyle/files/astyle/astyle%203.1/astyle_3.1_linux.t ...