参考博客:

http://blog.csdn.net/haoji007/article/details/77148374

http://blog.csdn.net/jacke121/article/details/78160398

voc数据集下载地址:

https://pjreddie.com/projects/pascal-voc-dataset-mirror/

我习惯于将所有训练、预测有关的.py .prototxt .caffemodel文件放在一起

将score.py surgery.py voc_layers.py拷贝到voc-fcn32s这个文件夹中。

修改solve.py:

import caffe

import surgery, score

import numpy as np

import os

import sys

try:

import setproctitle

setproctitle.setproctitle(os.path.basename(os.getcwd()))

except:

pass

weights = 'train_iter_100000.caffemodel'  #caffe的预训练模型

deploy_proto = 'deploy_voc_32s.prototxt'  #deploy文件

# init

caffe.set_device(int(0))

caffe.set_mode_gpu()

solver = caffe.SGDSolver('solver.prototxt')

#solver.net.copy_from(weights)

vgg_net=caffe.Net(deploy_proto,weights,caffe.TRAIN)

surgery.transplant(solver.net,vgg_net)

del vgg_net

# surgeries

interp_layers = [k for k in solver.net.params.keys() if 'up' in k]

surgery.interp(solver.net, interp_layers)

# scoring

#加载训练过程中的测试文件

val = np.loadtxt('../data/voc2012/VOCtrainval_11-May-2012/ImageSets/Segmentation/val.txt', dtype=str)

for _ in range(50):

solver.step(2000)

score.seg_tests(solver, False, val, layer='score')

# N.B. metrics on the semantic labels are off b.c. of missing classes;

# score manually from the histogram instead for proper evaluation

#score.seg_tests(solver, False, test, layer='score_sem', gt='sem')

#score.seg_tests(solver, False, test, layer='score_geo', gt='geo')

在../data/voc2012/VOCtrainval_11-May-2012/ImageSets/Segmentation有train.txt val.txt trainval.txt三个文件,num(trainval)=num(train)+num(val)。

预训练的模型可以去官网下载。

编辑solver.prototxt文件:

train_net: "train.prototxt"

test_net: "val.prototxt"

test_iter: 736

# make test net, but don't invoke it from the solver itself

test_interval: 999999999

display: 20

average_loss: 20

lr_policy: "fixed"

# lr for unnormalized softmax

base_lr: 1e-10

# high momentum

momentum: 0.99

# no gradient accumulation

iter_size: 1

max_iter: 100000

weight_decay: 0.0005

snapshot: 20000

snapshot_prefix: "./train"

test_initialization: false

生成deploy.prototxt文件

data层不变,保留

网络层照常理不变

去掉loss层

修改train.prototxt和val.prototxt文件

layer {

name: "data"

type: "Python"

top: "data"

top: "label"

python_param {

module: "voc_layers"

layer: "VOCSegDataLayer"

param_str: "{\'voc_dir\': \'../data/voc2012/VOCtrainval_11-May-2012\', \'seed\': 1337, \'split\': \'val\', \'mean\': (104.00699, 116.66877, 122.67892)}"

}

}

module指的是该文件夹下名为voc_layers.py的python文件,layer是该python文件名称为VOCSegDataLayer的类,该python文件中有两个类,另一个类不管。设置voc_dir为对应的路径。Train.prototxt和val.prototxt文件中作相同的修改。

其中的seed=1337,我也不知道是什么意思。这个mean的参数和siftflow中的值倒是一样的。

修改voc_layers.py:

该文件中主要是修改VOCSegDataLayer类中的一些路径和名称,下面的那个SBDDSegDataLayer不管。

设置voc2012数据集的路径

self.voc_dir = params['voc_dir']

加载txt文件

split_f  = '{}/ImageSets/Segmentation/{}.txt'.format(self.voc_dir,self.split)

加载图片

im = Image.open('{}/JPEGImages/{}.jpg'.format(self.voc_dir, idx))

加载标签图片

im = Image.open('{}/SegmentationClass/{}.png'.format(self.voc_dir, idx))

voc数据集中的图片尺寸不固定,图片的长宽也不相等。

如上图的网络结构可以看到,经过上采样之后,得到一个比原图大的图像,然后做crop操作,生成和原图像一样的尺寸,这就实现了不管输入的图片尺寸是多少,经过全卷积神经网络的结果图片和原图的尺寸都是相同的。

fcn+caffe+voc2012实验记录的更多相关文章

  1. fcn+caffe+siftflow实验记录

    环境搭建: vs2013,编译caffe工程,cuda8.0,cudnn5.1,python2.7. 还需要安装python的一些包.Numpy+mkl  scipy  matplotlib  sci ...

  2. case7 淋巴瘤子类分类实验记录

    case7 淋巴瘤子类分类实验记录 简介 分类问题:3分类 (identifying three sub-types of lymphoma: Chronic Lymphocytic Leukemia ...

  3. 实验记录:Oracle redo logfile的resize过程

    实验记录:Oracle redo logfile的resize过程. 实验环境:RHEL 6.4 + Oracle 11.2.0.3 单实例 文件系统 实验目的:本实验是修改redo logfile的 ...

  4. 使用Scapy向Mininet交换机注入流量 实验记录

    使用Scapy向Mininet交换机注入流量 实验记录 用Python脚本及Scapy库写了一个简单的流量生成脚本,并打算使用该脚本往Mininet中的OpenvSwitch交换机注入流量.拓扑图如下 ...

  5. 树莓派4B智能小车机器套件——入手组装实验记录

    树莓派4B智能小车机器套件--入手组装实验记录 4WD智能小车(4WD SMART ROBOT KIT),支持Arduino.51.STM32.Raspberry Pi等4个版本.本套件采用的是树莓派 ...

  6. CSAPP:datalab实验记录

    CSAPP:datalab实验记录 bitXor /* * bitXor - x^y using only ~ and & * Example: bitXor(4, 5) = 1 * Lega ...

  7. 实验记录三 通用输入输出(GPIO)

    之前把全部程序都跑了一次后,得到了导师下一步的安排. 例如以下: 1.编写一个程序.实如今LCD上显示一个万年历,包含年月日 星期 还有室内的温度.2.编写一个程序,将原来的交通灯改为跑马灯. 期限是 ...

  8. RHCE实验记录总结-2-RHCE

    RHCSA实验总结-点击跳转 RHCE实验 RHCE这边我简单分了下类: ## 网络与安全 1. IPv6 设置(推荐使用GUI程序 nm-connection-editor来完成) 2. team ...

  9. RHCE实验记录总结-1-RHCSA

    不管是运维还是开发系统的了解下Linux或者系统的温习整理一下Linux知识点无疑是较好的,这篇文章是对RHCSA&RHCE实验进行一个汇总,是我为了做实验方便(并分享给朋友)的一篇文章. 前 ...

随机推荐

  1. Luogu 1177 - 【模板】快速排序 - [快速排序][归并排序][无旋Treap]

    题目链接:https://www.luogu.org/problemnew/show/P1177 题意:输入 $n$ 以及后续 $n$ 个整数,让你将这 $n$ 个整数从小到大排序输出. 归并排序(用 ...

  2. SQL Server 索引自动组织维护

    公司的一个产品中的数据库,几个热点表因为主键和索引设计不合理,造成索引碎片过大,影响性能. 我尝试新建了一个索引碎片整理的定时任务,用于维护索引锁片和统计信息. 具体的过程如下: 本文原创,转发请表明 ...

  3. JS中的三种弹出式消息提醒(警告窗口、确认窗口、信息输入窗口)的命令是什么?

    一种: <a href="javascript:if(confirm('确实要删除该内容吗?')){location='http://www.google.com'}"> ...

  4. LeetCode 696 Count Binary Substrings 解题报告

    题目要求 Give a string s, count the number of non-empty (contiguous) substrings that have the same numbe ...

  5. linux下yum安装及配置

    1 2 3 4 分步阅读 公司使用的是linux搭建服务器,linux安装软件能够使用yum安装依赖包是一件非常简单而幸福的事情,所以这里简单介绍一下linux安装yum源流程和操作. 工具/原料 电 ...

  6. 11.0-uC/OS-III就绪列表(优先级)

    准备运行的任务被放置于就绪列表中.就绪列表包括2个部分:位映像组包含了优先级信息,一个表包含了所有指向就绪任务的指针. 1.优先级 图6-1到6-3显示了优先级的位映像组.它的宽度取决于CPU_DAT ...

  7. Django中CBV源码解析

    使用 关于FBV和CBV的使用在之前有提到,点击穿越. 准备 首先在视图中创建一个类并继承 django.views.View 类,在类中可定义各种请求方式对应执行的函数(函数名为请求方式名称小写). ...

  8. 《linux就该这么学》第二节课,安装红帽7,基础命令至2.3小节的笔记

    笔记 实验环境: 1.安装注意事项:使用VM12版本   安装需要稍后安装系统.   自定义硬件DVD选择镜像位置.   自定义网卡仅主机.   自定义内存:大于等于4G,给予虚拟机2G,大于2G小于 ...

  9. Centos 忘记root密码怎么办?

    1 - 在启动grub菜单,选择编辑选项启动 2 - 按键盘e键,来进入编辑界面 3 - 找到Linux 16的那一行,将ro改为rw init=/sysroot/bin/sh 4 - 现在按下 Co ...

  10. python扩展包的升级

    检查更新:pip list --outdated 更新: pip install --upgrade xxxx