linux 终端无法显示图片

由于是使用的终端,plt.plot函数不能用,采用的思路是不显示图像,直接保存要显示的图像。(红色字体为实现代码)

import numpy as np
import matplotlib  
matplotlib.use('Agg')

import matplotlib.pyplot as plt




# Make sure that caffe is on the python path:
caffe_root = '/public/home/zhkfu/zhkfu/caffe-master/'  # this file is expected to be in {caffe_root}/examples
import sys
sys.path.insert(0, caffe_root + 'python')


import caffe


# Set the right path to your model definition file, pretrained model weights,
# and the image you would like to classify.
MODEL_FILE = caffe_root +  'models/bvlc_reference_caffenet/deploy.prototxt'
PRETRAINED = caffe_root + 'models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel'
IMAGE_FILE = caffe_root + 'examples/images/cat.jpg'  


import os
if not os.path.isfile(PRETRAINED):
    print("Downloading pre-trained CaffeNet model...")
   
caffe.set_mode_cpu()
net = caffe.Classifier(MODEL_FILE, PRETRAINED,
                       mean=np.load(caffe_root + 'python/caffe/imagenet/ilsvrc_2012_mean.npy').mean(1).mean(1),
                       channel_swap=(2,1,0),
                       raw_scale=255,
                       image_dims=(256, 256))
                       
input_image = caffe.io.load_image(IMAGE_FILE)
#plt.imshow(input_image)
prediction = net.predict([input_image])  # predict takes any number of images, and formats them for the Caffe net automatically
plt.plot(prediction[0])
plt.savefig("prediction.png")

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值