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