贴上具体的编译过程吧:

step1:clone下caffe,按照caffe官方教程编译caffe(要编译python接口)

step2:进入到PSPNet里面进行编译,编译过程和caffe的编译差不多,在这里我使用了python接口,所以进行以下语句的编译即可:

make pycaffe -j4
make all -j4
make test -j4

在编译pycaffe是可能会出现以下错误:

如果不适用GPU的话在interp.hpp直接注释掉这条语句即可;

还可能出现下面这个错误:

sudo apt-get install libmatio-dev安装一下就好。

step3:在PSPNet下面建立demo文件夹

下载相应的caffemodel和prototxt文件,然后修改demo.py就可以用训练好的模型进行测试:

import sys
import time
import getopt
import os
import numpy as np
from PIL import Image as PILImage# Path of the Caffe installation.
_CAFFE_ROOT = "/home/chen/PSPNet/"# Model definition and model file paths
_MODEL_DEF_FILE = "pspnet50_ADE20K_473.prototxt"  # Contains the network definition
_MODEL_FILE = "pspnet50_ADE20K.caffemodel"  # Contains the trained weights.sys.path.insert(0, _CAFFE_ROOT + "python")
import caffe_MAX_DIM = 473def get_palette(num_cls):""" Returns the color map for visualizing the segmentation mask.Args:num_cls: Number of classesReturns:The color map"""n = num_clspalette = [0] * (n * 3)for j in xrange(0, n):lab = jpalette[j * 3 + 0] = 0palette[j * 3 + 1] = 0palette[j * 3 + 2] = 0i = 0while lab:palette[j * 3 + 0] |= (((lab >> 0) & 1) << (7 - i))palette[j * 3 + 1] |= (((lab >> 1) & 1) << (7 - i))palette[j * 3 + 2] |= (((lab >> 2) & 1) << (7 - i))i += 1lab >>= 3return palettedef crfrnn_segmenter(model_def_file, model_file, gpu_device, inputs):""" Returns the segmentation of the given image.Args:model_def_file: File path of the Caffe model definition prototxt filemodel_file: File path of the trained model file (contains trained weights)gpu_device: ID of the GPU device. If using the CPU, set this to -1inputs: List of images to be segmented Returns:The segmented image"""assert os.path.isfile(model_def_file), "File {} is missing".format(model_def_file)assert os.path.isfile(model_file), ("File {} is missing. Please download it using ""./download_trained_model.sh").format(model_file)if gpu_device >= 0:caffe.set_device(gpu_device)caffe.set_mode_gpu()else:caffe.set_mode_cpu()net = caffe.Net(model_def_file, model_file, caffe.TEST)num_images = len(inputs)num_channels = inputs[0].shape[2]assert num_channels == 3, "Unexpected channel count. A 3-channel RGB image is exptected."caffe_in = np.zeros((num_images, num_channels, _MAX_DIM, _MAX_DIM), dtype=np.float32)for ix, in_ in enumerate(inputs):caffe_in[ix] = in_.transpose((2, 0, 1))start_time = time.time()out = net.forward_all(**{net.inputs[0]: caffe_in})end_time = time.time()print("Time taken to run the network: {:.4f} seconds".format(end_time - start_time))predictions = out[net.outputs[0]]return predictions[0].argmax(axis=0).astype(np.uint8)def run_crfrnn(input_file, output_file, gpu_device):""" Runs the CRF-RNN segmentation on the given RGB image and saves the segmentation mask.Args:input_file: Input RGB image file (e.g. in JPEG format)output_file: Path to save the resulting segmentation in PNG formatgpu_device: ID of the GPU device. If using the CPU, set this to -1"""input_image = 255 * caffe.io.load_image(input_file)input_image = resize_image(input_image)image = PILImage.fromarray(np.uint8(input_image))image = np.array(image)palette = get_palette(256)#PIL reads image in the form of RGB, while cv2 reads image in the form of BGR, mean_vec = [R,G,B] mean_vec = np.array([123.68, 116.779, 103.939], dtype=np.float32)mean_vec = mean_vec.reshape(1, 1, 3)# Rearrange channels to form BGRim = image[:, :, ::-1]# Subtract meanim = im - mean_vec# Pad as necessarycur_h, cur_w, cur_c = im.shapepad_h = _MAX_DIM - cur_hpad_w = _MAX_DIM - cur_wim = np.pad(im, pad_width=((0, pad_h), (0, pad_w), (0, 0)), mode='constant', constant_values=0)# Get predictionssegmentation = crfrnn_segmenter(_MODEL_DEF_FILE, _MODEL_FILE, gpu_device, [im])segmentation = segmentation[0:cur_h, 0:cur_w]output_im = PILImage.fromarray(segmentation)output_im.putpalette(palette)output_im.save(output_file)def resize_image(image):""" Resizes the image so that the largest dimension is not larger than 500 pixels.If the image's largest dimension is already less than 500, no changes are made.Args:Input imageReturns:Resized image where the largest dimension is less than 500 pixels"""width, height = image.shape[0], image.shape[1]max_dim = max(width, height)if max_dim > _MAX_DIM:if height > width:ratio = float(_MAX_DIM) / heightelse:ratio = float(_MAX_DIM) / widthimage = PILImage.fromarray(np.uint8(image))image = image.resize((int(height * ratio), int(width * ratio)), resample=PILImage.BILINEAR)image = np.array(image)return imagedef main(argv):""" Main entry point to the program. """input_file = "/home/chen/PSPNet/demo/test2.jpg"output_file = "/home/chen/PSPNet/demo/test_rs.png"gpu_device = -1  # Use -1 to run only on the CPU, use 0-3[7] to run on the GPUtry:opts, args = getopt.getopt(argv, 'hi:o:g:', ["ifile=", "ofile=", "gpu="])except getopt.GetoptError:print("crfasrnn_demo.py -i <input_file> -o <output_file> -g <gpu_device>")sys.exit(2)for opt, arg in opts:if opt == '-h':print("crfasrnn_demo.py -i <inputfile> -o <outputfile> -g <gpu_device>")sys.exit()elif opt in ("-i", "ifile"):input_file = argelif opt in ("-o", "ofile"):output_file = argelif opt in ("-g", "gpudevice"):gpu_device = int(arg)print("Input file: {}".format(input_file))print("Output file: {}".format(output_file))if gpu_device >= 0:print("GPU device ID: {}".format(gpu_device))else:print("Using the CPU (set parameters appropriately to use the GPU)")run_crfrnn(input_file, output_file, gpu_device)if __name__ == "__main__":main(sys.argv[1:])

------------------------------------------------------------------------------------------------

复现PSPNet真的好曲折...这里贴一些复现过程的心得吧。

这是PSPNet整个工程的文件结构,在src文件里包含了修改过的caffe的源码,include包含了新增的一些layer的头文件什么的,具体看一下,然后和caffe-master做个对比,这样以后自己要利用caffe搭一个炼丹炉也知道这么弄。

在caffe/src/caffe/layers里面有127个.cpp文件,而在pspnet/src/caffe/layers里面有131个.cpp文件,所以多出来的4个应该是实现PSPNet自己定义的四个layer的实现。

然后proto文件夹,solvers文件夹都一样,util文件夹里PSPNet的刚好也比caffe的多7个文件。

最后是PSPNet/include/caffe/layers里面包含了一些实现caffe中layers的头文件,PSPNet的肯定也是更多的。

/----------------------------------------------------------------------------------------------------------------------------

PSPNet编译心得相关推荐

  1. Razer Phone TWRP 适配编译心得

    Razer Phone TWRP 适配编译心得 暑假的时候搞到一台雷蛇手机,因为官方的 TWRP 功能基本上都是残废的,就想自己适配个 不过这也是第一次适配,故把第一次的适配步骤写在博客里 语文不是很 ...

  2. 嵌入式linux alsa,嵌入式Linux下ALSA音频架构ALSA-lib移植与编译心得

    **************************************************************************************************** ...

  3. binutils-2.22编译心得

    最近想自己编译出arm的gcc,其中必须的一步是必须编译binutils,所以尝试了一下,步骤如下: 1.安装cygwin,选择gcc及libiconv库,安装,不要用mingw的编译器编译,我查了下 ...

  4. cygwin下的gcc-4.7.1编译心得

    步骤: 1.先编译gmp mpfr mpc这几个库,注意configure时--prefix=/usr/local/ 2.中间碰到过can not compute suffix的错误,在命令 expo ...

  5. VisualBoy Advance编译心得

    今天闲着没事在SourceForge逛,无意中找到了VisualBoy Advance(VBA)项目的svn地址.哈哈,那就编了它吧. 编译工具:vs2010 VBA主页:http://vba-m.c ...

  6. nite simpleHandTracker编译心得

    使用kinect2+nite2+openni2.2编译时,总是在这里返回错误 这让我很郁闷.前后查找资料,再加上还有其他工作,这个问题卡住了3天左右.很是难过. 后来我发现,可以使用 libfreen ...

  7. ICnet pspnet编译过程

    下载ICnet,想评估一下,编译的过程相当伤神.总结一下: 这个caffe不是原装的,而且不支持cuda8,于是百度无数,才得以编译成功,以资纪念.感谢这个哥们: http://blog.csdn.n ...

  8. linux音频时钟bclk,linux alsa音频中采样率fs、比特率BCLK 、主时钟MCLK关系

    转:https://blog.csdn.net/lugandong/article/details/72468831 一. 拿512fs说话: 看图知道采样的位深是32bit(位),左右声道各占了8* ...

  9. 安卓逆向-入门笔记、相关知识点总结及思路

    文章目录 安卓逆向思路: 1.查壳 2.未加固 2.1 工具 2.2方法 3 .第一代加固 3.1 工具 3.2 方法 3.3 材料准备 3.4 实例 补充知识: 一.Android 1.加密原则: ...

  10. 基于ARM64银河麒麟V10系统(PK体系)适配安装Ambari2.7.3+HDP3.1

    引言 目前市场上主流的大数据平台以CDH和HDP两种为主,而两种大数据平台都是基于Apache原生态版本改进的,HDP版本的更贴近于原生态版本,开源率100%,基本上支持所有的开源大数据组件.CDH版 ...

最新文章

  1. c语言一个偶数用两个素数表示,用java怎样编写一个偶数总能表示为两个素数之和的程序...
  2. 【Android 异步操作】Handler 机制 ( MessageQueue 消息队列的阻塞机制 | Java 层机制 | native 层阻塞机制 | native 层解除阻塞机制 )
  3. 关于python的保留字_Python中的保留字
  4. 【问底】徐汉彬:PHP7和HHVM的性能之争
  5. 肝毒净-道格拉斯实验室
  6. Android平台开发职位招聘要求总结
  7. 关于 exynos 4412 按键中断 异步通知
  8. Hi3519A 接入 BT1120或BT656视频
  9. dll文件保存到服务器,dll是什么文件?dll文件怎么打开?
  10. 。。。。看毛片算法_(:з」∠)_ /FZU - 2275
  11. 基于时间窗的AGV调度算法优化
  12. linux基础学习思维导图及文档(17万字)
  13. Vista 陪我过周末
  14. 微分几何笔记(2) —— 曲线的参数化
  15. KGB知识图谱成功落地金融行业
  16. 计算机链接局域网,window7连接局域网的方法
  17. 我的世界服务器自定义怪物怎么用,我的世界自定义怪物插件
  18. 使用canvas绘制笑脸
  19. python、前端vue——全栈——vscode插件
  20. web 原型设计工具_适用于Web设计人员的7种原型设计工具

热门文章

  1. idea运行lua脚本
  2. 360+linux浏览器下载官网下载,360极速浏览器下载
  3. MOSFET知识小结
  4. ad域 禁用账号_AD域撤销域用户管理员权限方案
  5. 物业为什么要用微小区SaaS系统进行管理
  6. 迅雷精简版 for Mac!附精简教程!
  7. QT应用编程: windows下QT调用COM组件
  8. 面向对象程序设计——基于JML的地铁系统
  9. offer来了(原理篇)学习笔记-第9章设计模式
  10. 面向对象第三单元(地铁)总结