This is my script to load the pretrained model and make prediction. However, it is not able to recognize the apparently pretty or ugly image, so I am thinking maybe my input is not right.
There are several places that I am not quite sure:
import numpy as np
from PIL import Image
def preprocess_image(fp, ava1mean):
im = Image.open(fp).convert("RGB")
im = im.resize([227, 227])
im = np.asarray(im).astype(np.float32) # 227, 227, 3
if len(im.shape) != 3:
raise Exception
# im = im[:, :, ::-1] shall we convert RGB -> BGR?
im -= ava1mean
return im # 227, 227, 3
ava1mean = np.load("../ILGnet/mean/AVA1_mean.npy") # 3, 256, 256
ava1mean = ava1mean.transpose(1, 2, 0)[14:241,14:241,:] # 227, 227, 3
inputs = [preprocess_image("../ugly.jpg", ava1mean)]
classifier = caffe.Classifier("deploy2.prototxt", "ILGnet-AVA1.caffemodel",
image_dims=[227, 227])
print(classifier.predict(inputs, True))```
This is my script to load the pretrained model and make prediction. However, it is not able to recognize the apparently pretty or ugly image, so I am thinking maybe my input is not right.
There are several places that I am not quite sure:
If possible, can anyone post a script about how to correctly read image, load model and make prediction? It is much appreciated.