alexgkendall / SegNet-Tutorial

Files for a tutorial to train SegNet for road scenes using the CamVid dataset
http://mi.eng.cam.ac.uk/projects/segnet/tutorial.html
851 stars 518 forks source link

Filter Visualization #18

Closed mtrth closed 8 years ago

mtrth commented 8 years ago

Is there a way to visualize the layer filters? similar to http://nbviewer.jupyter.org/github/BVLC/caffe/blob/master/examples/00-classification.ipynb

alexgkendall commented 8 years ago

You should be able to use that exact example - just change caffe to caffe-segnet and the model and layer details to the segnet model as required

mtrth commented 8 years ago

I tried modifying the first few step: (the file is in ./caffe-segnet/examples/)

import numpy as np import matplotlib.pyplot as plt

caffe_root = '../' # this file is expected to be in {caffe_root}/examples import sys sys.path.insert(0, caffe_root + 'python')

import caffe

plt.rcParams['figure.figsize'] = (10, 10) plt.rcParams['image.interpolation'] = 'nearest' plt.rcParams['image.cmap'] = 'gray'

caffe.set_mode_cpu() net = caffe.Net(caffe_root + 'models/segnet_basic/segnet_basic_solver.prototxt', caffe_root + 'models/segnet_basic/segnet_basic_iter_10000.caffemodel', caffe.TEST)

transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape}) transformer.set_transpose('data', (2,0,1)) transformer.set_mean('data', np.load(caffe_root + 'python/caffe/mean.npy').mean(1).mean(1)) # mean pixel transformer.set_raw_scale('data', 255) # the reference model operates on images in [0,255] range instead of [0,1] transformer.set_channel_swap('data', (2,1,0)) # the reference model has channels in BGR order instead of RGB

net.blobs['data'].reshape(50,3,227,227)

net.blobs['data'].data[...] = transformer.preprocess('data', caffe.io.load_image(caffe_root + 'examples/images/PC10_20100606_053000_0020.bmp')) out = net.forward() print("Predicted class is #{}.".format(out['prob'][0].argmax()))

but I get the error

[libprotobuf ERROR google/protobuf/text_format.cc:245] Error parsing text-format caffe.NetParameter: 1:4: Message type "caffe.NetParameter" has no field named "net". WARNING: Logging before InitGoogleLogging() is written to STDERR F0127 22:15:32.835021 30435 upgrade_proto.cpp:928] Check failed: ReadProtoFromTextFile(param_file, param) Failed to parse NetParameter file: ../models/segnet_basic/segnet_basic_solver.prototxt * Check failure stack trace: * Aborted (core dumped)

tsingjinyun commented 8 years ago

[libprotobuf ERROR && Failed to parse NetParameter file:../models/segnet_basic/segnet_basic_solver.prototxt so, may the protobuf is doesn't match well with caffe or caffe-segnet