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上训练自己的数据的更多相关文章

  1. 【神经网络与深度学习】深度学习实战——caffe windows 下训练自己的网络模型

    1.相关准备 1.1 手写数字数据集 这篇博客上有.jpg格式的图片下载,附带标签信息,有需要的自行下载,博客附带百度云盘下载地址(手写数字.jpg 格式):http://blog.csdn.net/ ...

  2. caffe 利用VGG训练自己的数据

    写这个是因为有童鞋在跑VGG的时候遇到各种问题,供参考一下. 网络结构 以VGG16为例,自己跑的细胞数据 solver.prototxt: net: "/media/dl/source/E ...

  3. caffe 如何训练自己的数据图片

    申明:此教程加工于caffe 如何训练自己的数据图片 一.准备数据 有条件的同学,可以去imagenet的官网http://www.image-net.org/download-images,下载im ...

  4. rsync (windows 服务端,linux客户端)将windows上的数据同步到linux服务器,反之也可

    一:总体概述. 1.windows上面首先装CW_rsync_Server.4.1.0_installer,安装时要输入的用户名密码要记住哦!接下来就是找到rsyncd.conf进入配置细节 2.li ...

  5. 大数据高性能数据库Redis在Windows上的使用教程

    Redis学习笔记----Redis在windows上的安装配置和使用 Redis简介 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括s ...

  6. Windows上快速编译caffe CPU版本

    windows上快速安装配置Caffe的 cpu_only环境. 一:安装环境: 1.windows10: 2.Visual Studio2013: 3.Caffe版本:http://github.c ...

  7. caffe学习三:使用Faster RCNN训练自己的数据

    本文假设你已经完成了安装,并可以运行demo.py 不会安装且用PASCAL VOC数据集的请看另来两篇博客. caffe学习一:ubuntu16.04下跑Faster R-CNN demo (基于c ...

  8. 在GPU上训练数据

    在GPU上训练数据 模型搬到GPU上 数据搬到GPU上 损失函数计算搬到GPU上

  9. caffe 用faster rcnn 训练自己的数据 遇到的问题

    1 . 怎么处理那些pyx和.c .h文件 在lib下有一些文件为.pyx文件,遇到不能import可以cython 那个文件,然后把lib文件夹重新make一下. 遇到.c 和 .h一样的操作. 2 ...

随机推荐

  1. poj1125(Floyd最短路)

    //Accepted 164 KB 0 ms //floyd #include <cstdio> #include <cstring> #include <iostrea ...

  2. Image Generator (Image Builder)

    如果你想要下载一个预编译好的镜像文件,或者想要尝试整个编译过程,一个替代方案是使用镜像生成器(Image Generator)(以前被叫做Image Builder).这是一个预编译好的OpenWrt ...

  3. Math 对象的方法

    Math 对象的方法 方法 描述 abs(x) 返回数的绝对值 acos(x) 返回数的反余弦值 asin(x) 返回数的反正弦值 atan(x) 以介于 -PI/2 与 PI/2 弧度之间的数值来返 ...

  4. Python网络编程03----Python3.*中socketserver

    socketserver(在Python2.*中的是SocketServer模块)是标准库中一个高级别的模块.用于简化网络客户与服务器的实现(在前面使用socket的过程中,我们先设置了socket的 ...

  5. 关于刷Sylvain/burst_ind分支的一些问题解答

    Sylvain/burst_ind分支是网上说的比较多的带sniffer功能的分支,但是编译完无法刷固件 关于以上问题.相信很多朋友碰到过.但是国内没有人分享相关的经验.在这里我分享下我的经验. ht ...

  6. PHP_ArrayList

      <?php //遍历数组的2种方式 $arr=array( "1"=>"hello", "2"=>"my&q ...

  7. Mac抓包工具Charles

    一.下载 先到它的官网http://www.charlesproxy.com/可下载到最新版本,这个下载有点慢,我已经将它放到网盘中了:http://pan.baidu.com/s/1gdu0S4V ...

  8. JS手机定位地理位置

    /** * 以下为html5代码,获取地理位置 */ /** * 设置地址 */ function setAddress(json) { var position = document.getElem ...

  9. JLOI 提示问题

    按照题目意思模拟即可. Program XJOI2265; ..] of char=('a','e','i','o','u','A','E','I','O','U'); var s:ansistrin ...

  10. HDU 1811

    http://acm.hdu.edu.cn/showproblem.php?pid=1811 中文码题 对于等号的情况,用并查集合并(因为编号不同一定可以分出先后) 然后判断能否构成拓扑排序,以及拓扑 ...