BestiVictory / ILGnet

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to do the prediction via pretrained model?

pcgreat opened this issue · comments

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:

  1. Is the input RGB or BGR?
  2. The input scale should be 0~255 rather than 0-1, right?
  3. The AVA1_mean file is (3, 256, 256), should I crop it to (227, 277, 3) and subtract that from each image?
    If possible, can anyone post a script about how to correctly read image, load model and make prediction? It is much appreciated.
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))```

I think your suggestion is necessary for our project.The script of prediction will be upload soon.

That will be awesome! Thanks in advance and looking forward to that!

I'd like that script, too!

Is test.py the script of prediction sample?