The whole process of caffe target detection model training (2) python loads caffemodel classification

Following the whole process of caffe target detection model training (1) script, data preparation and production
in the previous article , we trained its model, as shown in the figure:
write picture description here
models2_iter_70000.caffemodel is the model that needs to be called, 70000 means that the model has been trained 70,000 times The saved model, the others are the same.

Write it down, use python to load the model, and then identify it. First, identify the processed image with a size of 227*227.
code show as below:

# 加载图片
im = caffe.io.load_image('scale_img.jpg')
print(im.shape)

transformer = caffe.io.Transformer({'data': net_full_conv.blobs['data'].data.shape})
#transformer.set_mean('data', np.load(caffe_root + 'python/caffe/imagenet/ilsvrc_2012_mean.npy').mean(1).mean(1))
transformer.set_transpose('data', (2,0,1))
transformer.set_channel_swap('data', (2,1,0))
transformer.set_raw_scale('data', 255.0)

transformed_image = transformer.preprocess('data', im)
net_full_conv.blobs['data'].data[...] = transformed_image
net_full_conv.blobs['data'].reshape(1,3,227,227)

### perform classification
out = net_full_conv.forward()
# make classification map by forward and print prediction indices at each location
# out = net_full_conv.forward_all(data=np.asarray([transformer.preprocess('data', im)]))
#打印出类别
print (out['prob'],(x,y))

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324666081&siteId=291194637