CNTK model evaluation


In [ ]:
from cntk.ops.functions import load_model
from PIL import Image 
import numpy as np

In [ ]:
z = load_model("mycnn.dnn")

In [ ]:
# JPG image is stored and read in as RGB data, CNTK model is trained in BGR format, so need to permute input
rgb_image = np.asarray(Image.open("foo.jpg"), dtype=np.float32) - 128
bgr_image = rgb_image[..., [2, 1, 0]]
pic = np.ascontiguousarray(np.rollaxis(bgr_image, 2))

In [ ]:
predictions = np.squeeze(z.eval({z.arguments[0]:[pic]}))
top_class = np.argmax(predictions)