3. caffe中 python Notebook

caffe官网上的example中的例子,如果环境配对都能跑出来,接下来跑Notobook Example中的程序,都是python写的,这些程序会让你对如何使用caffe解决问题有个初步的了解(http://www.cnblogs.com/dupuleng/articles/4242983.html)

即然用到python,那么就要确定安装了python,并且pycaffe编译通过,还要安装一些依赖项:

sudo apt-get install python-numpy python-scipy python-matplotlib python-sklearn python-skimage python-h5py python-protobuf python-leveldb python-networkx python-nose python-pandas python-gflags Cython ipython

其中matplotlib是用来进行绘图的,非常方便。在深度学习中,我们经常会通过将中间结果显示来观察学习到的特征,因此掌握matplotlib相当重要。

在使用matplotlib时需要注意一个问题,先看示例

import matplotlib.pyplot as plt

input_image = caffe.io.load_image(IMAGE_FILE)
plt.imshow(input_image)
#显示
plt.show() 

最后一唏的plt.show()必须有,要不然不会显示绘图,在caffe的例子中并没有注明这一点。

如果你有多幅图像要显示,可以像matlab一样使用subplot

复制代码
import matplotlib.pyplot as plt

plt.figure()
plt.subplot(1,2,1)
plt.bar(left = (0,1),height = (1,0.5),width = 0.35)

plt.subplot(1,2,2)
plt.bar(left = (0,1),height = (1,0.5),width = 0.35)

plt.show()
复制代码

如果想每幅图单独显示,可以在每次绘图前新建一个绘图区

复制代码
import matplotlib.pyplot as plt

plt.figure()
plt.bar(left = (0,1),height = (1,0.5),width = 0.35)

plt.figure()
plt.bar(left = (0,1),height = (1,0.5),width = 0.35)  
plt.show()
复制代码
【. . . . . .本博客仅作个人生活、工作、学习等的日常记录。说明: (1) 内容有参考其他博主、网页等,有因“懒”直接粘贴来,会备注出处。若遇雷同,或忘备注,并无故意抄袭之意,请诸“原主”谅解,很感谢您的辛勤"笔记"可供本人参考学习。 (2) 如遇同行,有参考学习者,因个人学识有限,不保证所写内容完全正确。您对本博文有任何的意见或建议,欢迎留言,感谢指正。 (3) 若您认为本主的全博客还不错,可以点击关注,便于互相学习。 (4) 感谢您的阅读,希望对您有一定的帮助。欢迎转载或分享,但请注明出处,谢谢。. . . . . .】 【作者: Carole0904 ; 出处: https://www.cnblogs.com/carle-09/ 】
原文地址:https://www.cnblogs.com/carle-09/p/5712666.html