Tags: ComputerVision

编译

  1. src/caffe/layers/contrastive_loss_layer.cpp:56:30: error: no matching function for call to ‘max(double, float)’

    Dtype dist = std::max(margin - sqrt(dist_sq_.cpu_data()[i]), Dtype(0.0));

Replace line 56 by this one :

Dtype dist = std::max(margin - (float)sqrt(dist_sq_.cpu_data()[i]), Dtype(0.0));

2. .build_release/lib/libcaffe.so: undefined reference to `cv::imread(cv::String const&, int)'

Change Makefile:

LIBRARIES += glog gflags protobuf leveldb snappy

lmdb boost_system hdf5_hl hdf5 m

opencv_core opencv_highgui opencv_imgproc

add :opencv_imgcodecs

数据处理

  1. median frequency balancing的计算

    图片分割经常会遇到class unbalance的情况,如果你的target是要求每个类别的accuracy 都很高那么在训练的时候做class balancing 很重要,如果你的target要求只要求图片总体的pixel accuracy好,那么class balancing 此时就不是很重要,因为占比小的class, accuray 虽然小,但是对总体的Pixel accuracy影响也较小。

    那么看下本文中的meidan frequency balancing是如何计算的:

    对于一个多类别图片数据库,每个类别都会有一个class frequency, 该类别像素数目除以数据库总像素数目, 求出所有class frequency 的median 值,除以该类别对应的frequency 得到weight:

\[weight_i = median(weights)/weight_i
\]

这样可以保证占比小的class, 权重大于1, 占比大的class, 权重小于1, 达到balancing的效果.

如对我自己的数据有两类分别为0,1, 一共55张500500训练图片,统计55张图片中0,1像素的个数:

count1 227611

count0 13522389

freq1 = 227611/(500
50055) = 0.0166

freq0 = 13522389/(500
500*55) = 0.9834

median = 0.5

weight1 = 30.12

weight0 = 0.508

  1. webdemo权重

    作者训练的webdemo和他给出的模型文件的类别数目和label 是对不上号的,因此可以使用webdemo跑测试,但是最好不要在上面finetune, 直接在VGG-16上面finetune 就行

  2. rgb label 转换为 gray label

一些数据集给出的label是rgb的,如下图,但是训练过程中输入网络的label一般是0 - class_num-1标记的label map, 因此需要一个转换过程,下面给出一个python2转换脚本:

#!/usr/bin/env python
import os
import numpy as np
from itertools import izip
from argparse import ArgumentParser
from collections import OrderedDict
from skimage.io import ImageCollection, imsave
from skimage.transform import resize camvid_colors = OrderedDict([
("Animal", np.array([64, 128, 64], dtype=np.uint8)),
("Archway", np.array([192, 0, 128], dtype=np.uint8)),
("Bicyclist", np.array([0, 128, 192], dtype=np.uint8)),
("Bridge", np.array([0, 128, 64], dtype=np.uint8)),
("Building", np.array([128, 0, 0], dtype=np.uint8)),
("Car", np.array([64, 0, 128], dtype=np.uint8)),
("CartLuggagePram", np.array([64, 0, 192], dtype=np.uint8)),
("Child", np.array([192, 128, 64], dtype=np.uint8)),
("Column_Pole", np.array([192, 192, 128], dtype=np.uint8)),
("Fence", np.array([64, 64, 128], dtype=np.uint8)),
("LaneMkgsDriv", np.array([128, 0, 192], dtype=np.uint8)),
("LaneMkgsNonDriv", np.array([192, 0, 64], dtype=np.uint8)),
("Misc_Text", np.array([128, 128, 64], dtype=np.uint8)),
("MotorcycleScooter", np.array([192, 0, 192], dtype=np.uint8)),
("OtherMoving", np.array([128, 64, 64], dtype=np.uint8)),
("ParkingBlock", np.array([64, 192, 128], dtype=np.uint8)),
("Pedestrian", np.array([64, 64, 0], dtype=np.uint8)),
("Road", np.array([128, 64, 128], dtype=np.uint8)),
("RoadShoulder", np.array([128, 128, 192], dtype=np.uint8)),
("Sidewalk", np.array([0, 0, 192], dtype=np.uint8)),
("SignSymbol", np.array([192, 128, 128], dtype=np.uint8)),
("Sky", np.array([128, 128, 128], dtype=np.uint8)),
("SUVPickupTruck", np.array([64, 128, 192], dtype=np.uint8)),
("TrafficCone", np.array([0, 0, 64], dtype=np.uint8)),
("TrafficLight", np.array([0, 64, 64], dtype=np.uint8)),
("Train", np.array([192, 64, 128], dtype=np.uint8)),
("Tree", np.array([128, 128, 0], dtype=np.uint8)),
("Truck_Bus", np.array([192, 128, 192], dtype=np.uint8)),
("Tunnel", np.array([64, 0, 64], dtype=np.uint8)),
("VegetationMisc", np.array([192, 192, 0], dtype=np.uint8)),
("Wall", np.array([64, 192, 0], dtype=np.uint8)),
("Void", np.array([0, 0, 0], dtype=np.uint8))
]) def convert_label_to_grayscale(im):
out = (np.ones(im.shape[:2]) * 255).astype(np.uint8)
for gray_val, (label, rgb) in enumerate(camvid_colors.items()):
match_pxls = np.where((im == np.asarray(rgb)).sum(-1) == 3)
out[match_pxls] = gray_val
assert (out != 255).all(), "rounding errors or missing classes in camvid_colors"
return out.astype(np.uint8) def make_parser():
parser = ArgumentParser()
parser.add_argument(
'label_dir',
help="Directory containing all RGB camvid label images as PNGs"
)
parser.add_argument(
'out_dir',
help="""Directory to save grayscale label images.
Output images have same basename as inputs so be careful not to
overwrite original RGB labels""")
return parser if __name__ == '__main__':
parser = make_parser()
args = parser.parse_args()
labs = ImageCollection(os.path.join(args.label_dir, "*"))
os.makedirs(args.out_dir)
for i, (inpath, im) in enumerate(izip(labs.files, labs)):
print(i + 1, "of", len(labs))
# resize to caffe-segnet input size and preserve label values
resized_im = (resize(im, (360, 480), order=0) * 255).astype(np.uint8)
out = convert_label_to_grayscale(resized_im)
outpath = os.path.join(args.out_dir, os.path.basename(inpath))
imsave(outpath, out)

训练结果

基于VGG-16finetune训练的一个模型迭代20000次的测试结果:



label:



基于VGG-16自己数据训练的结果:



label:

测试结果:

Reference

  1. Demystifying Segnet:http://5argon.info/portfolio/d/SegnetTrainingGuide.pdf

【Computer Vision】 复现分割网络(1)——SegNet的更多相关文章

  1. Graph Cut and Its Application in Computer Vision

    Graph Cut and Its Application in Computer Vision 原文出处: http://lincccc.blogspot.tw/2011/04/graph-cut- ...

  2. paper 156:专家主页汇总-计算机视觉-computer vision

    持续更新ing~ all *.files come from the author:http://www.cnblogs.com/findumars/p/5009003.html 1 牛人Homepa ...

  3. 获取Avrix上Computer Vision and Pattern Recognition的论文,进一步进行统计分析。

    此文主要记录我在18年寒假期间,收集Avrix论文的总结 寒假生活题外   在寒假期间,爸妈每天让我每天跟着他们6点起床,一起吃早点收拾,每天7点也就都收拾差不多.   早晨的时光是人最清醒的时刻,而 ...

  4. inception_v2版本《Rethinking the Inception Architecture for Computer Vision》(转载)

    转载链接:https://www.jianshu.com/p/4e5b3e652639 Szegedy在2015年发表了论文Rethinking the Inception Architecture ...

  5. Rethinking the inception architecture for computer vision的 paper 相关知识

    这一篇论文很不错,也很有价值;它重新思考了googLeNet的网络结构--Inception architecture,在此基础上提出了新的改进方法; 文章的一个主导目的就是:充分有效地利用compu ...

  6. 【Semantic segmentation Overview】一文概览主要语义分割网络(转)

    文章来源:https://www.tinymind.cn/articles/410 本文来自 CSDN 网站,译者蓝三金 图像的语义分割是将输入图像中的每个像素分配一个语义类别,以得到像素化的密集分类 ...

  7. 如何创建Azure Face API和计算机视觉Computer Vision API

    在人工智能技术飞速发展的当前,利用技术手段实现人脸识别.图片识别已经不是什么难事.目前,百度.微软等云计算厂商均推出了人脸识别和计算机视觉的API,其优势在于不需要搭建本地环境,只需要通过网络交互,就 ...

  8. 【E2EL5】A Year in Computer Vision中关于图像增强系列部分

    http://www.themtank.org/a-year-in-computer-vision 部分中文翻译汇总:https://blog.csdn.net/chengyq116/article/ ...

  9. Computer vision labs

    积累记录一些视觉实验室,方便查找 1.  多伦多大学计算机科学系 2.  普林斯顿大学计算机视觉和机器人实验室 3.  牛津大学Torr Vision Group 4.  伯克利视觉和学习中心 Pro ...

随机推荐

  1. C# ArcgisEngine开发中,对一个图层进行过滤,只显示符合条件的要素

    转自原文 C# ArcgisEngine开发中,对一个图层进行过滤,只显示符合条件的要素 有时候,我们要对图层上的地物进行有选择性的显示,以此来满足实际的功能要求. 按下面介绍的方法可轻松实现图层属性 ...

  2. AutoReplace in pl/sql developer

    AutoReplace in pl/sql developer SL=SELECT S*=SELECT * FROM 2D=TO_DATE('2017-01-01 01:01:00','YYYY-MM ...

  3. Memcache 和 Radis 比较

    Memcache 和 Radis 比较 2014-03-28 11:00 2447人阅读 评论(0) 收藏 举报  分类: memcache(6)  Redis(7)  版权声明:本文为博主原创文章, ...

  4. POJ3570 Fund Management 动态规划

    题目大意 Frank从个人投资者获得了c美元的资金,可用于m天的投资.Frank可以对n(n<=8)支股票进行投资.对于每一支股票:都有一个交易上限si,表示一天最多能交易的股数:还有一个上限k ...

  5. Linux - 环境变量与位置变量

    环境变量 [root@local ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin 注:只有自己执行 ...

  6. Spark MLlib介绍

    Spark MLlib介绍 Spark之所以在机器学习方面具有得天独厚的优势,有以下几点原因: (1)机器学习算法一般都有很多个步骤迭代计算的过程,机器学习的计算需要在多次迭代后获得足够小的误差或者足 ...

  7. 【SCOI 2005】 骑士精神

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1085 [算法] IDA* [代码] #include<bits/stdc++. ...

  8. CI中的文件上传

    //首先在控制器中装载url类和view视图: //在view视图中创建一个表单,注:在做文件上传一定要写encype=“multipart/form-data”: //form表单的提交页面应该使用 ...

  9. 如何使用fetch

    Fetch API  提供了一个 JavaScript接口,用于访问和操纵HTTP管道的部分,例如请求和响应.它还提供了一个全局fetch()方法,该方法提供了一种简单,合乎逻辑的方式来跨网络异步获取 ...

  10. vue1.0.js的初步学习

    vue.js是一个mvvm框架 {{.....}}   常用模板渲染方式 v-model  :将对应变量的值的变化反映到input的vaule中 vue.js 的一个组件 .vue文件包含<te ...