目录

  • Tags: ComputerVision
  • 编译
  • 数据处理
  • 训练结果
  • Reference

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));

  1. .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

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

  3. 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 resizecamvid_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_valassert (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 tooverwrite original RGB labels""")return parserif __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 valuesresized_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

转载于:https://www.cnblogs.com/vincentcheng/p/9179606.html

【Computer Vision】 复现分割网络(1)——SegNet相关推荐

  1. SegNet 语义分割网络以及其变体 基于贝叶斯后验推断的 SegNet

    HomePage: http://mi.eng.cam.ac.uk/projects/segnet/ SegNet Paper: https://www.computer.org/csdl/trans ...

  2. 一文概览主要语义分割网络:FCN,SegNet,U-Net...

    本文来自 CSDN 网站,译者蓝三金 图像的语义分割是将输入图像中的每个像素分配一个语义类别,以得到像素化的密集分类.虽然自 2007 年以来,语义分割/场景解析一直是计算机视觉社区的一部分,但与计算 ...

  3. 【Deep Learning笔记】语义分割网络-Segnet的探索

    文章目录 1 简介 2 网络框架 3 Encoder 4 Pooling&Upsampling(decoder): 5 Batch Normlization 6 Loss Function 7 ...

  4. 干货 | 一文概览主要语义分割网络,FCN、UNet、SegNet、DeepLab 等等等等应有尽有

    翻译不易,麻烦 Ctrl-C Ctrl-V 之后标注转载并加上原译者!! 部分内容翻译,部分内容原创. 内容较多,可以传送门直达.新网络待更- 文章目录 介绍 网络架构 Fully Convoluti ...

  5. 复杂背景下计算机视觉模型害虫识别的比较研究(像素语义分割网络SegNet)

    Abstract 农业被认为是世界各国的经济基础,新技术的发展有助于提高收获效率.自动驾驶汽车在农场用于播种.收获和施用农药等任务.然而,任何一个种植园的主要问题之一是害虫和疾病的鉴定,这对害虫控制和 ...

  6. Pytorch:图像语义分割-FCN, U-Net, SegNet, 预训练网络

    Pytorch: 图像语义分割-FCN, U-Net, SegNet, 预训练网络 Copyright: Jingmin Wei, Pattern Recognition and Intelligen ...

  7. 【语义分割】一文概览主要语义分割网络,FCN、UNet、SegNet、DeepLab

    目录 前言知识 一.语义分割与实例分割的区别 1. Semantic Segmentation(语义分割): 2. Instance Segmentation(实例分割): 二.语义分割一般网络架构 ...

  8. Real_time实时语义分割网络 SegNet, ENet, ICNet, BiSeNet,ShelfNet

    1. SegNet 论文地址:A Deep Convolutional Encoder-Decoder Architecture for Image Segmentation 本不应该将segnet作 ...

  9. 基于飞桨复现语义分割网络HRNet,实现瓷砖缺陷检测

    点击左上方蓝字关注我们 [飞桨开发者说]路星奎,沈阳化工大学信息工程学院研究生在读,PPDE飞桨开发者技术专家,研究方向为图像分类.目标检测.图像分割等 内容简介 本项目讲述了HRNet网络结构,并尝 ...

最新文章

  1. 巴黎新式婴儿饼干,你敢吃吗?
  2. POJ1269 直线相交
  3. (七)JS基础知识四(搞定异步)【三座大山之三,必考!!!】
  4. POJ 1850 Code(组合数学)
  5. [css] 怎样去除图片自带的边距?
  6. break后面的语句还执行吗_12.python之配合循环的四种语句
  7. 调整心态,java复习要点总结。
  8. hdu 2295 Radar DLX 重复覆盖问题
  9. 【OpenCV应用】python处理行李图像匹配项目——图像特征点
  10. ETCD for java_etcd-java使用
  11. 5 添加数据获得id_D3库实践笔记之元素定位与数据绑定 |可视化系列33
  12. 中国股市十大风云人物
  13. python :tushare 唐奇安通道
  14. 阿里云虚拟主机和服务器的区别
  15. 查询水果价格(15 分)
  16. 新浪股东批准私有化合并协议;中集车辆创业板成功过会;中国红牛2020年销售额超228亿元​ | 美通企业周刊...
  17. 让51单片机进行上网
  18. 【java毕业设计】基于java+SSH+jsp的酒水销售系统设计与实现(毕业论文+程序源码)——酒水销售系统
  19. 怎么查看php-fpm的错误日志,php fpm如何开启错误日志
  20. 远程进服务器怎么全屏显示,远程服务器如何全屏显示

热门文章

  1. 基于Picture Library创建的图片文档库中的上传多个文件功能(upload multiple files)报错怎么解决?...
  2. AJAX范例大搜罗(转载)
  3. Ansible05-部署文件
  4. 初创公司面试要问什么_聘请初创公司的产品设计师时要问的问题
  5. 散列基础知识总结(思维导图)
  6. PAT(甲级)2020年春季考试 7-4 Replacement Selection
  7. Python组合数据类型之集合类型
  8. C++ 枚举类型基本知识
  9. python函数图像绘制、函数不固定_无法在函数中绘制tkinter图像
  10. pwa+webpack,初探与踩坑