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. SEAndroid安全机制框架分析

    我们知道,Android系统基于Linux实现. 针对传统Linux系统,NSA开发了一套安全机制SELinux,用来加强安全性. 然而.因为Android系统有着独特的用户空间执行时.因此SELin ...

  2. luogu3376 【模板】 网络最大流

    题目大意 给出一个网络图,以及其源点和汇点,求出其网络最大流. 概念 可以把网络图看作管道,节点看作管道的交界处.流就像是管道里的流水.管道有个容量(相当于横截面积),还会有个流量(相当于水流占了管道 ...

  3. base64对文件进行加密

    将原文件读取为字节数组,然后用base64加密,得到加密的字符串 https://stackoverflow.com/questions/475421/base64-encode-a-pdf-in-c ...

  4. nginx FastCGI模块(FastCGI)配置

    http://www.howtocn.org/nginx:nginx%E6%A8%A1%E5%9D%97%E5%8F%82%E8%80%83%E6%89%8B%E5%86%8C%E4%B8%AD%E6 ...

  5. java语言的运行机制

    计算机高级编程语言按其程序的执行方式可分为编译型语言和解释型语言. 编译型语言是指使用专门的编译器,针对特定的操作系统将源程序代码一次性翻译成计算机能识别的机器指令.例如C.C++等都属于编译型语言. ...

  6. 给统计人讲Python(1)_科学计算库-Numpy

    本地代码是.ipynb格式的转换到博客上很麻烦,这里展示部分代码,了解更多可以查看我的git-hub:https://github.com/Yangami/Python-for-Statisticia ...

  7. NOIP2013 D2T1 积木大赛

    [NOIP2013T4]积木大赛 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 noip2013day2 描述 春春幼儿园举办了一年一度的"积木大 ...

  8. vue开发的项目中遇到的警告,报错,配置项目文件等合集(长期更新)

    1. Vue组件里面data()里面没有return时触发错误:Vue components Cannot read property '__ob__' of undefined 这个警告不解决会触发 ...

  9. 8、List接口的特点及其相关功能

    /* * Collection * |--List * 元素有序(指的是存储顺序和取出顺序是否一致),可重复. * |--Set * 元素无序,唯一. */ /* * List的特有功能: * A:添 ...

  10. Jquery 重置表单

    1.重置表单回初始状态 $('#fromid')[0].reset(); 此方法一步到位,不需要一个个的去赋值为空