segnet 编译与测试
参考:http://sunxg13.github.io/2015/09/10/caffe/
http://m.blog.csdn.net/lemianli/article/details/76687508
http://blog.h5min.cn/u010069760/article/details/75258539
(注意:nakefile而非makefile.config)
1、编译caffe-segnet:
1.1下载caffe-segnet(适用于segnet的caffe版本,下成scaffe)
git clone https://github.com/alexgkendall/caffe-segnet
1.2更改一些编译选项:
Makefile.config:
#USE_CUDNN := 1 (scaffe不支持高版本cudnn)
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
WITH_PYTHON_LAYER := 1(需要PYTHON_LAYER)

修改Makefile,在
LIBRARIES += glog gflags protobuf leveldb snappy \
lmdb boost_system hdf5_hl hdf5 m \
opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs
处加入后面的opencv_imgcodecs,因为opencv3.0.0把imread相关函数放到imgcodecs.lib中了(原来是imgproc.lib
make -j8
make pycaffe

1.3、下载segnet,建议放置在caffe-segnet文件中:
git clone https://github.com/alexgkendall/SegNet-Tutorial
文件很大,因为其中包含一些图片
下载模型文件:[http://mi.eng.cam.ac.uk/~agk34/resources/SegNet/segnet_weights_driving_webdemo.caffemodel
这是用于摄像头的模型文件,不过图片也能使用,不过需要改变测试文件
使用文件中自带的图片测试结果
Example——Moudel下有相应的模型描述文件prototxt
Scripts文件夹下有相应的测试文件:*p

更改相应路径即可显示结果,这里我更改了使用上面那个摄像头模型的测试文件,可以用于测试单张图片:

# -*- coding: utf-8 -*
import numpy as np
import matplotlib.pyplot as plt
import os.path
import scipy
import argparse
import math
import cv2
import sys
import time sys.path.append('/usr/local/lib/python2.7/site-packages')
# Make sure that caffe is on the python path:
caffe_root = '/media/lbk/娱乐/seg-env/caffe-segnet/'
sys.path.insert(0, caffe_root + 'python')
import caffe # Import arguments
#deploy='Example_Models/segnet_model_driving_webdemo.prototxt'
#weights='Example_Moudels/segnet_weights_driving_webdemo.caffemodel'
#colours='Scripts/camvid12.png'
#net = caffe.Net(deploy,weights,caffe.TEST) # Import arguments
parser = argparse.ArgumentParser()
parser.add_argument('--model', type=str, required=True)
parser.add_argument('--weights', type=str, required=True)
parser.add_argument('--colours', type=str, required=True)
args = parser.parse_args() net = caffe.Net(args.model,
args.weights,
caffe.TEST)
#caffe.set_mode_gpu() input_shape = net.blobs['data'].data.shape
output_shape = net.blobs['argmax'].data.shape label_colours = cv2.imread(args.colours).astype(np.uint8) #cv2.namedWindow("Input")
#cv2.namedWindow("SegNet") cap = cv2.VideoCapture(0) # Change this to your webcam ID, or file name for your video file rval = True frame = cv2.imread('/media/lbk/娱乐/seg-env/caffe-segnet/segnet/Example_Models/123.png')
frame = cv2.resize(frame, (input_shape[3],input_shape[2]))
input_image = frame.transpose((2,0,1))
# input_image = input_image[(2,1,0),:,:] # May be required, if you do not open your data with opencv
input_image = np.asarray([input_image])
out = net.forward_all(data=input_image) segmentation_ind = np.squeeze(net.blobs['argmax'].data)
segmentation_ind_3ch = np.resize(segmentation_ind,(3,input_shape[2],input_shape[3]))
segmentation_ind_3ch = segmentation_ind_3ch.transpose(1,2,0).astype(np.uint8)
segmentation_rgb = np.zeros(segmentation_ind_3ch.shape, dtype=np.uint8) cv2.LUT(segmentation_ind_3ch,label_colours,segmentation_rgb)
#这里应该变成小数存储了,看来opencv对于小数也是热图显示,但是保存还是黑白的图
segmentation_rgb = segmentation_rgb.astype(float)/255 #cv2.imwrite('output.jpg',segmentation_rgb)
#cv2.imshow("Input", frame)
#cv2.imshow("SegNet", segmentation_rgb)
#cv2.imwrite('output.jpg',segmentation_rgb)
#这里使用plt显示与保存,比cv2好点,并且不会出现进程卡住的情况
plt.imshow(segmentation_rgb)
plt.savefig('output.png')
plt.show()

运行:进入到SegNet-Tutorial-master文件夹
python Scripts/*.py --model Example_Models/segnet_model_driving_webdemo.prototxt --weights Example_Models/segnet_weights_driving_webdemo.caffemodel --colours Scripts/camvid12.png

即可得到结果

segnet 编译与测试的更多相关文章

  1. 在Windows用Rebar来构建,编译,测试,发布Erlang项目

    rebar是一个遵循 Erlang/OTP 原则的 Erlang 项目构建工具,使用它可以减少构建标准 Erlang/OTP 项目架构配置的工作量,并且可以很容易的编译.测试.发布 Erlang 应用 ...

  2. dubbox 编译 和 测试

    因为 dubbox 并没有发布到maven中央仓库仓库中,所以需要我们自己到官网下载,自己编译,install 到本地. 1. 首先安装git客户端工具 TortoiseGit, 然后使用它将 dub ...

  3. 用 rebar 来构建、编译、测试、发布 Erlang 应用程序

    转自:http://dhq.me/build-compile-eunit-release-erlang-application-with-rebar rebar 是一个遵循 Erlang/OTP 原则 ...

  4. Maven取消编译自动测试

    Maven取消编译自动测试 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins&l ...

  5. Qt 5.8 移植编译、测试

    /****************************************************************************** * Qt 5.8 移植编译.测试 * 说 ...

  6. 在Azure DevOps Server (TFS)的流水线中编译和测试Xcode移动应用(iPhone)

    概述 Xcode是开发基于苹果macOS系统的桌面应用和移动应用的主要IDE工具.使用Azure DevOps Server (原名TFS)系统中的pipelines流水线功能,可以方便的集成Xcod ...

  7. GEOS库在windows中的编译和测试(vs2012)

    版本:vs2012, geos3.5 一.下载和编译 这类的文章比较,不再具体细说,可以参考 http://blog.csdn.net/wangqinghao/article/details/8201 ...

  8. [原]在Fedora中编译Libevent测试实例

    在我的昨天的博文<[原]我在Windows环境下的首个Libevent测试实例>中介绍了在Windows环境下如何编译一个echo server例子.今天我又试了一下在Linux环境中编译 ...

  9. DataX的简单编译安装测试

    搭建环境:     Java > =1.6     Python>=2.6 <3     Ant     Rpmbuild     G++     编译DataX: 进入rpm文件夹 ...

随机推荐

  1. SSH做反向代理

    说实话,我对反向代理这个概念并不熟悉,只是感觉以下要做的事是一个代理的逆向过程,故借此名词一用. 问题场景是这样的:我有两套Linux集群的访问权限,分别为A和B,它们互相独立.其中A.B集群均能访问 ...

  2. 基于Java实现的选择排序算法

    选择排序和冒泡排序同样是基础排序算法,现在也做个学习积累. 简述 选择排序算法较为稳定,基本上都是O(n2)的时间复杂度,规模越小排序越快,不需要占用额外空间.其实选择排序原理很简单,就是在未排序序列 ...

  3. How To Use Git Source Control with Xcode in iOS 6

    This tutorial is by Malek Trabelsi, a passionate iOS developer from Tunisia focused primarily on mob ...

  4. 关闭火狐定期向“http://detectportal.firefox.com/”发包

    问题:最近发现火狐总是向http://detectportal.firefox.com/发包 办法:firefox地址栏输入 about:config,然后搜索找到 network.captive-p ...

  5. 转: JDK包含的基本组件

    JDK(Java Development Kit)是Sun Microsystems针对Java开发员的产品.自从Java推出以来,JDK已经成为使用最广泛的Java SDK.JDK 是整个Java的 ...

  6. 转: 为什么做java的web开发我们会使用struts2,springMVC和spring这样的框架?

    from: https://github.com/RubyLouvre/agate/issues/8 今年我一直在思考web开发里的前后端分离的问题,到了现在也颇有点心得了,随着这个问题的深入,再加以 ...

  7. [Django]中建立数据库视图

    Django中建立数据库视图 Django中没有建立视图的接口.假设要建立一个视图须要一些手动的改变. 这里使用的Django 版本号>1.5, 使用的数据库为mysql 第一步 建立视图,比如 ...

  8. nginx的优点

    Linux.MySQL.PHP这些框架的优点之前已经介绍过,LNMP和LAMP不同的一点就是Web服务器Nginx,那么Nginx相比Apache有什么优点呢? Nginx是一个小巧而高效的Linux ...

  9. vue-cli配置文件详解

    转自: https://blog.csdn.net/Mr_YanYan/article/details/79233188

  10. Codeforces Round #243 (Div. 2)——Sereja and Table

    看这个问题之前,能够先看看这个论文<一类算法复合的方法>,说白了就是分类讨论,可是这个思想非常重要 题目链接 题意: 首先给出联通块的定义:对于相邻(上下和左右)的同样的数字视为一个联通块 ...