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 ...
随机推荐
- 将Ajax 中数组转换成字符串 封装成类
<?php class Ajax{ //ajax调用的方法 //sql是要执行的语句 //$type是SQL语句的类型,0代表增删改,1代表查询 //$db代表要操作的数据 public fun ...
- 【django入门教程】Django的安装和入门
很多初学django的朋友,都不知道如何安装django开发以及django的入门,今天小编就给大家讲讲django入门教程. 注明:python版本为3.3.1.Django版本为1.5.1,操作系 ...
- table td的宽度详解
前言:一直总觉得td的宽度好难驾驭,但万事万物总是有规律的.就像亮剑说的:不用因为怕八路就敬而远之,应该靠上去,熟悉他们,了解他们. 正文: Table只有Table的宽度是可 ...
- 为什么SQL语句加 1=1
是为了链接下面的查询条件条件,也或者是替换没有查询条件的语句.比如:要把检索条件作为一个参数传递给SQL,那么,当这个检索语句不存在的话就可以给它赋值为1=1.这样就避免了SQL出错,也就可以把加条件 ...
- 作业3-个人项目<词频统计>
上了一天的课,现在终于可以静下来更新我的博客了. 越来越发现,写博客是一种享受.来看看这次小林老师的“作战任务”. 词频统计 单词: 包含有4个或4个以上的字 ...
- bat批处理文件命令详解
bat批处理文件命令详解 echo.@.call.pause.rem(小技巧:用::代替rem)是批处理文件最常用的几个命令 echo 表示显示此命令后的字符 echo off 表示在此语句后所有运 ...
- 解决magento添加产品在前台不显示问题
有时候我们在magento系统添加产品,前台不显示,最模板分析可能 以下几个原因: 1 添加新品要重新index一下,magento是静态的.html页面,不reindex不出来的.在System→I ...
- 阅读<构建之法>第三10、11、12章
第10章:典型用户和场景 阅读了第10章之后,我知道典型用户很重要,典型用户是某类群体的代表,他们的观点能够反映一类人的观点与对产品的要求,那么要怎么样才能够从一类群体里,选择正确的典型用户反映我们研 ...
- Android 常用的常量
常用的Android常量 1.Activity Action 字符串常量("android.intent.action."+) 描述ALL_APPS ...
- bedtools 每天都会用到的工具
详细的使用说明:http://bedtools.readthedocs.org/en/latest/ Collectively, the bedtools utilities are a swiss- ...