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 ...
随机推荐
- date 格式化
以这个为例: yyyy-MM-dd HH:mm:ss 首先得写好你需要的模板 options.sign = options.sign || 'yyyy-MM-dd HH:mm:ss'; 其次就可 ...
- Angular ocLazyLoad 与ui-router的配合使用
1.resolve state(配置路由时)的resolve参数: resolve:object,将会被注入controller去执行的函数,<string,function>形式. 基于 ...
- 动漫绘画软件优动漫PAINT最近所用文件
在使用优动漫PAINT的时候有时候会遇到这样的问题,近期编辑的文件找不见了,或者想要接着之前的文件进行编辑,如何快速找到这些文件呢?其实在最近所用文件中一目了,本文我们一起来看看. 如果您想接着上次未 ...
- Flex元素布局规则总结,以及布局和容器
一.Flex中的元素分类从功能层面可以把Flex中的元素分为组件(Components)和容器(Containers)两大类:组件 - 是指那类具有明确交互或数据展示功能的元素,例如Button.Ch ...
- shell问题-报错即退出
如下: #!/bin/bash set -o errexit 在最开头加上 set -o errexit 即可(或者 set -e) 要关闭的时候 set +o errexit (或者 ...
- Nginx全局变量
一.全局变量 $args #请求中的参数值 $query_string #同 $args $arg_NAME #GET请求中NAME的值 $is_args #如果请求中有参数,值为"?&qu ...
- Javascript中的原型链,__proto__和prototype等问题总结
1.js中除了原始数据类型 都是对象. 包括函数也是对象,可能类似于C++函数对象把 应该是通过解释器 进行()操作符重载或其他操作, 用的时候把它当函数用就行 但是实际上本质是一个对象 原型也是一个 ...
- 漫谈 Google 的 Native Client(NaCl) 技术(二)---- 技术篇(兼谈 LLVM)
转自:http://hzx5.blog.163.com/blog/static/40744388201172531637729/ 漫谈 Google 的 Native Client(NaCl) 技术( ...
- IOS开发:使用lipo合并armv7,i386,armv7s库文件
假设多个版本的lib分别是 libxxx.armv7.a , libxxx.armv7s.a, libxxx.i386.a我们的目标是 把他们合并成超级通用版的libxxx.a 打开命令行 Term ...
- Linux学习二:基于CentOS 6.5的网络配置
查看网卡信息: ifconfig [root@hadoop01 ~]# ifconfig [正常的显示信息] eth0 Link encap:Ethernet HWaddr :0C::::5C ine ...