Caffe-windows上训练自己的数据
1.数据获取
在网上选择特定类别,下载相应的若干张图片。可以网页另存或者图片下载器。本例中保存了小狗、菊花、梅花三类各两百多张。

2.重命名
import os
import os.path
rootdir = "jh"
i=1
for parent,dirnames,filenames in os.walk(rootdir):
for filename in filenames:
newName=a+str(i)+".jpg"
print filename+" -> "+newName
os.rename(os.path.join(parent,filename), os.path.join(parent, newName))
i+=1
3.更改分辨率
from PIL import Image
import glob, os
w,h = 256,256
def timage():
for files in glob.glob('jh\*.jpg'):
filepath,filename = os.path.split(files)
filterame,exts = os.path.splitext(filename)
opfile = r'jh\jhout\\'
if (os.path.isdir(opfile)==False):
os.mkdir(opfile)
im=Image.open(files)
im_ss=im.resize((int(w), int(h)))
try:
im_ss.save(opfile+filterame+'.jpg')
except:
print filterame
os.remove(opfile+filterame+'.jpg') if __name__=='__main__':
timage()
4.获取标签
import glob, os, shutil
def timage():
names=["gg","jh"]
t=open("train.txt",'a')
v=open("val.txt",'a')
for files in glob.glob('jh\jhout\*.jpg'):
filepath,filename = os.path.split(files)
filterame,exts = os.path.splitext(filename)
oldfile = r'jh\jhout\\'
opfile = r'val\\'
if (os.path.isdir(opfile)==False):
os.mkdir(opfile)
if 200< int(filterame[2:]): # test data
shutil.move(oldfile+filterame+'.jpg',opfile+filterame+'.jpg')
v.write(filterame+'.jpg '+str(names.index("jh"))+'\n')
else: # train data
t.write('jhout/'+filterame+'.jpg '+str(names.index("jh"))+'\n')
t.close()
v.close() if __name__=='__main__':
timage()
5.生成对应的leveldb格式数据
SET GLOG_logtostderr=
Build\x64\Release\convert_imageset.exe examples/t/train/ examples/t/train/train.txt examples/t/trainldb
pause
SET GLOG_logtostderr=
Build\x64\Release\convert_imageset.exe examples/t/val/ examples/t/val/val.txt examples/t/valldb
pause
6.计算均值
SET GLOG_logtostderr=
Build\x64\Release\compute_image_mean.exe examples/t/trainldb examples/t/tmean.binaryproto
pause
7.修改网络
models/bvlc_alexnet/train_val.prototxt
修改其中的num_output, batch_size和相应的路径
solver.prototxt如下,其中gamma指的是在学习率为step模式化下,每400次迭代变为原来的0.9倍。
net: "examples/t/train_val.prototxt"
test_iter:
test_interval:
base_lr: 0.0001
lr_policy: "step"
gamma: 0.9
stepsize:
display:
max_iter:
momentum: 0.9
weight_decay: 0.001
snapshot:
snapshot_prefix: "caffe_train"
solver_mode: GPU
8.训练网络
cd ../../
"Build/x64/Release/caffe.exe" train --solver=examples/t/solver.prototxt
pause
9.运行结果
在仅使用小狗和菊花两类,训练200张测试50张,可以达到98%的正确率。
使用小狗、菊花、梅花三类,可以达到89%的正确率。


10.优化
之前将train_val.prototxt中的crop_size: 227改成了128,速度相对快很多。
在三类分类中改回227,正确率在92%左右波动,进一步修改base_lr: 0.00015,gamma: 0.93,正确率可以达到94.6%。

Caffe-windows上训练自己的数据的更多相关文章
- 【神经网络与深度学习】深度学习实战——caffe windows 下训练自己的网络模型
1.相关准备 1.1 手写数字数据集 这篇博客上有.jpg格式的图片下载,附带标签信息,有需要的自行下载,博客附带百度云盘下载地址(手写数字.jpg 格式):http://blog.csdn.net/ ...
- caffe 利用VGG训练自己的数据
写这个是因为有童鞋在跑VGG的时候遇到各种问题,供参考一下. 网络结构 以VGG16为例,自己跑的细胞数据 solver.prototxt: net: "/media/dl/source/E ...
- caffe 如何训练自己的数据图片
申明:此教程加工于caffe 如何训练自己的数据图片 一.准备数据 有条件的同学,可以去imagenet的官网http://www.image-net.org/download-images,下载im ...
- rsync (windows 服务端,linux客户端)将windows上的数据同步到linux服务器,反之也可
一:总体概述. 1.windows上面首先装CW_rsync_Server.4.1.0_installer,安装时要输入的用户名密码要记住哦!接下来就是找到rsyncd.conf进入配置细节 2.li ...
- 大数据高性能数据库Redis在Windows上的使用教程
Redis学习笔记----Redis在windows上的安装配置和使用 Redis简介 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括s ...
- Windows上快速编译caffe CPU版本
windows上快速安装配置Caffe的 cpu_only环境. 一:安装环境: 1.windows10: 2.Visual Studio2013: 3.Caffe版本:http://github.c ...
- caffe学习三:使用Faster RCNN训练自己的数据
本文假设你已经完成了安装,并可以运行demo.py 不会安装且用PASCAL VOC数据集的请看另来两篇博客. caffe学习一:ubuntu16.04下跑Faster R-CNN demo (基于c ...
- 在GPU上训练数据
在GPU上训练数据 模型搬到GPU上 数据搬到GPU上 损失函数计算搬到GPU上
- caffe 用faster rcnn 训练自己的数据 遇到的问题
1 . 怎么处理那些pyx和.c .h文件 在lib下有一些文件为.pyx文件,遇到不能import可以cython 那个文件,然后把lib文件夹重新make一下. 遇到.c 和 .h一样的操作. 2 ...
随机推荐
- jstl表达式替换某些字符
转自:http://www.yiibai.com/jsp/jstl_function_replace.html fn:replace() 函数替换一个字符串与另一个字符串的所有匹配. 语法 fn:re ...
- BZOJ 2467 生成树
当(n-1)条中间的边:4^(n-1)*4*C(n-1,n). ......以此类推Σ. f[n]=Σ(i=0..n-1)4^(i+1)*(n-i)*C(n,i) =Σ(i=0..n-1)4^(i+1 ...
- zf2-tutorial调通,坑爹的init_autoloader.php
zf2-tutorial的作者把init_autoloader.php内容写错了,新建个工程,把其中的这个文件的内容替一下,然后建库/建表,把local.ini打开(不是必须的),用户名/口令等配好, ...
- Unity3D ShaderLab 使用alpha参数创建透明效果
Unity3D ShaderLab 使用alpha参数创建透明效果 其实Unity为了方便我们的工作,为我们内置了很多参数.比如马上用到的透明功能. 准备场景新建Shader Material ,一张 ...
- Linux基础入门(新版)(实验五至实验八)
实验五 环境变量与文件查找 (环境变量的作用与用法,及几种搜索文件的方法) 一.环境变量 1.变量 (1)常变量与值是一对一的关系 (2)变量的作用域即变量的有效范围(比如一个函数中.一个源文 ...
- HDU 4004
http://acm.hdu.edu.cn/showproblem.php?pid=4004 题意:青蛙过长L的河,只能落在石头上,石头数量是n,给出n个坐标,至多跳m次,求在可以过河的条件下,青蛙跳 ...
- HDU 1721
http://acm.hdu.edu.cn/showproblem.php?pid=1721 非常有趣的一道水题,注意到相隔一个点的粒子数是可以相互转移的,所以只要判红点的和与蓝点的和是否相等 #in ...
- [转]Table-Driven and Data Driven Programming
What is Table-Driven and Data-Driven Programming? Data/Table-Driven programming is the technique of ...
- Carthage
Carthage Carthage - 一个简单.去集中化的Cocoa依赖管理器
- nginx的upstream目前支持5种方式的分配(转)
nginx的upstream目前支持5种方式的分配 1.轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除. 2.weight 指定轮询几率,weight ...