Closed nhatuan84 closed 6 years ago
I solved it: img = cv2.resize(cv2.imread(img_path, cv2.IMREAD_COLOR),(320,180)) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) img = np.transpose(img[:, :, ::-1], [2, 0, 1]).astype(np.float32) net.blobs['data'].data[...] = img out = net.forward()
Hi,
I have problem when predicting based on pretrained model. This is my code: `import numpy as np import caffe import glob import cv2
caffe.set_device(0) caffe.set_mode_gpu()
load the model
net = caffe.Net('TrailNet_SResNet-18.prototxt', 'TrailNet_SResNet-18.caffemodel', caffe.TEST)
Define image transformers
transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape}) transformer.set_transpose('data', (2,0,1))
Reading image paths
test_img_paths = [img_path for img_path in glob.glob("./*jpg")]
Making predictions
test_ids = [] preds = [] for img_path in test_img_paths: print (img_path) img = cv2.imread(img_path, cv2.IMREAD_COLOR) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) net.blobs['data'].data[...] = transformer.preprocess('data', img) out = net.forward() print(out)`
I used the images that you used when testing cpp program: rot_c.jpg rot_l.jpg rot_r.jpg tran_l.jpg tran_r.jpg
Here is the output:
Thank you.