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 ...
随机推荐
- .net 找回密码的第一步 第二步 第三步的进程条
先写一个div作为存放这个进程条的容器 开始写js 根据jQuery选择器找到需要加载ystep1的容器 loadstep方法可以初始化 steps参数表示步骤名称,content则是鼠标移动到当前位 ...
- 使用sslsplit嗅探tls/ssl连接
首先发一个从youtube弄到的sslsplit的使用教程 http://v.qq.com/page/x/k/s/x019634j4ks.html 我最近演示了如何使用mitmproxty执行中间人攻 ...
- Note_Master-Detail Application(iOS template)_01_YJYAppDelegate.h
//YJYAppDelegate.h #import <UIKit/UIKit.h> @interface YJYAppDelegate : UIResponder <UIAppli ...
- apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName的解决
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ...
- 破解 Rith's CrackMe #1(对比IDA查看动态分析中的MFC函数名)
系统 : Windows xp 程序 : Rith's CrackMe #1 程序下载地址 :http://pan.baidu.com/s/1gecW9Qr 要求 : 注册机编写 使用工具 : IDA ...
- Unity3D ShaderLab压缩混合纹理贴图
Unity3D ShaderLab压缩混合纹理贴图 纹理可以用于存储大量的数据,我们可以把多个图像打包存储在单一的RGBA纹理上,然后通过着色器代码提取这些元素, 我们就可以使用每个图片的RGBA通道 ...
- json-c-0.9 的简单用法
1.下载安装包路径: wget http://oss.metaparadigm.com/json-c/json-c-0.9.tar.gz 2.解压安装包 tar zxvf json-c-0.9.tar ...
- Qt的quit(),exit()以及close()事件捕获
使用QT编辑界面,其中带来很大方便的一点就是Qt中自带丰富的.种类齐全的类及其功能函数,程序员可以在编辑程序的过程中简单地直接调用.关于窗口关闭的操作,在这里指出常用的三个槽,即quit() ...
- Hadoop no.1
解决的问题: 1. 磁盘读取速度慢:磁盘容量大了,将一个大的文件存在磁盘上,但读取速度慢. 解决方法:hdfs将文件拆开存在不同的节点(datanode)上,namenode记载文件存储的位置( ...
- 【题解】【BT】【Leetcode】Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...