Fine-tuning CaffeNet for Style Recognition on “Flickr Style” Data 数据下载遇到的问题
(下载的时候没有提示 不知道是正在下 还是出现错误 卡着了)。。一直没有反应
下载前要以管理员身份运行 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、数据下不下来。
- python examples/finetune_flickr_style/assemble_data.py --workers=1 --images=2000 --seed 831486
运行上述指令时,程序莫名其妙就不动了,也不下载文件,程序也没有挂掉,好像进入了死锁状态。
查看源程序:assemble_data.py,可以看出assemble_data.py用了大量多线程,多进程。我的解决方案就是改源程序,不使用进程来下载了。并且,对下载进行了超时限定,超过6s就认为超时,进而不下载。
====================================================================================================
assemble_data.py中使用多线程,多进程的源代码如下:
- pool = multiprocessing.Pool(processes=num_workers)
- map_args = zip(df['image_url'], df['image_filename'])
- results = pool.map(download_image, map_args)
===================================================================================================
我修改后的源码如下:
- #!/usr/bin/env python3
- """
- Form a subset of the Flickr Style data, download images to dirname, and write
- Caffe ImagesDataLayer training file.
- """
- import os
- import urllib
- import hashlib
- import argparse
- import numpy as np
- import pandas as pd
- from skimage import io
- import multiprocessing
- import socket
- # Flickr returns a special image if the request is unavailable.
- MISSING_IMAGE_SHA1 = '6a92790b1c2a301c6e7ddef645dca1f53ea97ac2'
- example_dirname = os.path.abspath(os.path.dirname(__file__))
- caffe_dirname = os.path.abspath(os.path.join(example_dirname, '../..'))
- training_dirname = os.path.join(caffe_dirname, 'data/flickr_style')
- def download_image(args_tuple):
- "For use with multiprocessing map. Returns filename on fail."
- try:
- url, filename = args_tuple
- if not os.path.exists(filename):
- urllib.urlretrieve(url, filename)
- with open(filename) as f:
- assert hashlib.sha1(f.read()).hexdigest() != MISSING_IMAGE_SHA1
- test_read_image = io.imread(filename)
- return True
- except KeyboardInterrupt:
- raise Exception() # multiprocessing doesn't catch keyboard exceptions
- except:
- return False
- def mydownload_image(args_tuple):
- "For use with multiprocessing map. Returns filename on fail."
- try:
- url, filename = args_tuple
- if not os.path.exists(filename):
- urllib.urlretrieve(url, filename)
- with open(filename) as f:
- assert hashlib.sha1(f.read()).hexdigest() != MISSING_IMAGE_SHA1
- test_read_image = io.imread(filename)
- return True
- except KeyboardInterrupt:
- raise Exception() # multiprocessing doesn't catch keyboard exceptions
- except:
- return False
- if __name__ == '__main__':
- parser = argparse.ArgumentParser(
- description='Download a subset of Flickr Style to a directory')
- parser.add_argument(
- '-s', '--seed', type=int, default=0,
- help="random seed")
- parser.add_argument(
- '-i', '--images', type=int, default=-1,
- help="number of images to use (-1 for all [default])",
- )
- parser.add_argument(
- '-w', '--workers', type=int, default=-1,
- help="num workers used to download images. -x uses (all - x) cores [-1 default]."
- )
- parser.add_argument(
- '-l', '--labels', type=int, default=0,
- help="if set to a positive value, only sample images from the first number of labels."
- )
- args = parser.parse_args()
- np.random.seed(args.seed)
- # Read data, shuffle order, and subsample.
- csv_filename = os.path.join(example_dirname, 'flickr_style.csv.gz')
- df = pd.read_csv(csv_filename, index_col=0, compression='gzip')
- df = df.iloc[np.random.permutation(df.shape[0])]
- if args.labels > 0:
- df = df.loc[df['label'] < args.labels]
- if args.images > 0 and args.images < df.shape[0]:
- df = df.iloc[:args.images]
- # Make directory for images and get local filenames.
- if training_dirname is None:
- training_dirname = os.path.join(caffe_dirname, 'data/flickr_style')
- images_dirname = os.path.join(training_dirname, 'images')
- if not os.path.exists(images_dirname):
- os.makedirs(images_dirname)
- df['image_filename'] = [
- os.path.join(images_dirname, _.split('/')[-1]) for _ in df['image_url']
- ]
- # Download images.
- num_workers = args.workers
- if num_workers <= 0:
- num_workers = multiprocessing.cpu_count() + num_workers
- print('Downloading {} images with {} workers...'.format(
- df.shape[0], num_workers))
- #pool = multiprocessing.Pool(processes=num_workers)
- map_args = zip(df['image_url'], df['image_filename'])
- #results = pool.map(download_image, map_args)
- socket.setdefaulttimeout(6)
- results = []
- for item in map_args:
- value = mydownload_image(item)
- results.append(value)
- if value == False:
- print 'Flase'
- else:
- print '1'
- # Only keep rows with valid images, and write out training file lists.
- print len(results)
- df = df[results]
- for split in ['train', 'test']:
- split_df = df[df['_split'] == split]
- filename = os.path.join(training_dirname, '{}.txt'.format(split))
- split_df[['image_filename', 'label']].to_csv(
- filename, sep=' ', header=None, index=None)
- print('Writing train/val for {} successfully downloaded images.'.format(
- df.shape[0]))
修改主要有以下几点:
1、#!/usr/bin/env python3 使用python3
2、
- #pool = multiprocessing.Pool(processes=num_workers)
- map_args = zip(df['image_url'], df['image_filename'])
- #results = pool.map(download_image, map_args)
- socket.setdefaulttimeout(6)
- results = []
- for item in map_args:
- value = mydownload_image(item)
- results.append(value)
- if value == False:
- print 'Flase'
- else:
- print '1'
- # Only keep rows with valid images, and write out training file lists.
- print len(results)
只使用单线程下载,不使用多线程,多进程下载。并且,设定连接的超时时间为6s,socket.setdefaulttimeout(6)。
经过上述改进,就可以把数据下载下来。
===================================================================================================
2、
在运行命令:
- ./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 数据下载遇到的问题的更多相关文章
- CaffeNet用于Flickr Style数据集上的风格识别
转自 http://blog.csdn.net/liumaolincycle/article/details/48501423 微调是基于已经学习好的模型的,通过修改结构,从已学习好的模型权重中继续训 ...
- (原)caffe中fine tuning及使用snapshot时的sh命令
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5946041.html 参考网址: http://caffe.berkeleyvision.org/tu ...
- Fine Tuning
(转载自:WikiPedia) Fine tuning is a process to take a network model that has already been trained for a ...
- L23模型微调fine tuning
resnet185352 链接:https://pan.baidu.com/s/1EZs9XVUjUf1MzaKYbJlcSA 提取码:axd1 9.2 微调 在前面的一些章节中,我们介绍了如何在只有 ...
- style="visibility: hidden" 和 style=“display:none”区别
大多数人很容易将CSS属性display和visibility混淆,它们看似没有什么不同,其实它们的差别却是很大的. visibility属性用来确定元素是显示还是隐藏的,这用visibility=& ...
- Html style="visibility:hidden"与style="display:none"的区别
style="visibility:hidden": 使对象在网页上隐藏,但该对象在网页上所占的空间没有改变. style="display:none": 使对 ...
- ckplayer 中的style.swf 中的 style.xml 中的修改方法
style.swf ---- > style.zip ---- > 解压成文件夹 ---- > 打开style.xml ---- > 修改 最重要的是修改保存style.xml ...
- matplotlib 可视化 —— 定制画布风格 Customizing plots with style sheets(plt.style)
Customizing plots with style sheets - Matplotlib 1.5.1 documentation 1. 使用和显示其他画布风格 >> import ...
- style="visibility: hidden"和 style=“display:none”之间的区别
style=“display:none” 隐藏页面元素: <html> <head> <script type="text/javascript"&g ...
随机推荐
- 全能VIP音乐在线解析
浏览器安装暴力猴扩展即可使用 // ==UserScript== // @name 全能VIP音乐在线解析 // @version 0.0.10 // @homepage https://greasy ...
- hdu1385 Minimum Transport Cost 字典序最小的最短路径 Floyd
求最短路的算法最有名的是Dijkstra.所以一般拿到题目第一反应就是使用Dijkstra算法.但是此题要求的好几对起点和终点的最短路径.所以用Floyd是最好的选择.因为其他三种最短路的算法都是单源 ...
- open source project for recommendation system
原文链接:http://blog.csdn.net/cserchen/article/details/14231153 目前互联网上所能找到的知名开源推荐系统(open source project ...
- 我的C++笔记(Hello World)
其实在学习C++之前,是因为自己想学AI,但是发现好多AI教程都是使用C语言来进行讲解的,真心感觉到C真的计算机的基础语言行业的共同语言.至于为什么是C++,主要是C++是从C语言演变而来的,兼容C, ...
- (转)基于MVC4+EasyUI的Web开发框架经验总结(6)--在页面中应用下拉列表的处理
http://www.cnblogs.com/wuhuacong/p/3840321.html 在很多Web界面中,我们都可以看到很多下拉列表的元素,有些是固定的,有些是动态的:有些是字典内容,有些是 ...
- 系统A一定会按照自我的样子改造世界
A一定会按照自己的样子去构建系统A1,A1一定还会按照自己的样子去构建系统A1.1,A1.1一定还是会按照自我的样子去构建A1.1.1……我们编程,我们改造世界,我们的方向是被注定要朝着构建人造人的方 ...
- PuTTY 命令行改进 有效解决 中文乱码
PuTTY 是一个免费且跨平台的并支持SSH和Telnet 的客户端, 包括xterm 终端模拟器. 它由Simon Tatham 编写并维护. http://www.chiark.greenend ...
- Module.exports 和 exports
Module.exports 和 exports 在node中,没有全局作用域,只有模块作用域,外部访问不到内部,内部也访问不到外部,那么模块间如何通信 当加载一个模块的时候,被加载模块的代码在第一次 ...
- [CodeForces]986A Fair
大意:给一张图,每个图上有一个数,问以每个点为源点,经过的点包含k种数字的最小距离. 显然跑最短路会T,但我们注意到边权一定.某次学校考试就是类似题,可以bfs做,复杂度O(n),每种货物做一次,复杂 ...
- vim+astyle安装使用
astyle下载安装 wget https://sourceforge.net/projects/astyle/files/astyle/astyle%203.1/astyle_3.1_linux.t ...