Python uses a newly trained model to classify

Source: Internet
Author: User

6. Use a well-trained model in Python.

Caffe only provides encapsulated imagenet model, given a pair of images, directly calculate the characteristics of the image and make predictions. You first need to download the model file.

The Python code is as follows:

From Caffe import imagenetfrom matplotlib import pyplot# Set the right path to your model file, pretrained model# and the Image would like to classify. Model_file = ' examples/imagenet_deploy.prototxt ' pretrained = '/home/jiayq/downloads/caffe_reference_imagenet_ Model ' image_file = '/home/jiayq/lena.png ' net = imagenet. Imagenetclassifier (Model_file, pretrained) #预测prediction = net.predict (image_file) #绘制预测图像print ' prediction shape: ', Prediction.shapepyplot.plot (prediction) Prediction shape: (+) [<matplotlib.lines.line2d at 0x8faf4d0>] #结果


The horizontal axis of the graph represents the label, and the vertical axes represent the probabilities on that category, and we see that the lena.jpg is divided into the "Sombrero" group, and the results are fairly accurate.

Python uses a newly trained model to classify

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.