Search code examples
pythoncntk

Trying to make a extremely simple function in microsoft CNTK but obtain wrong results


I did not get the correct answer i expect from CNTK from the code below. Did i do something wrong?

import cntk as C
import numpy as np

def custom(a, b, c):
    return a * 0 + c * 0 + b


np.set_printoptions(edgeitems=1000, linewidth=1000)

a = C.input_variable(3)
b = C.input_variable(3)
c = C.input_variable(3)

f = custom(a, b, c)

q = np.zeros((1, 3)).astype(np.float32) + 0.5
w = np.zeros((1, 3)).astype(np.float32) + 1.0
e = np.zeros((1, 3)).astype(np.float32) + 1.5

print()
print("a:", q)
print("b:", w)
print("c:", e)
print(">>>>>>>>>>>>>>>>>>>>>")
results = f(q, w, e)
print(results)

I demand that the results return

[[1.0, 1.0, 1.0]]

but i got,

[[1.5, 1.5, 1.5]]

instead. Can anyone replicate this? Copying and paste should run without error.

EDIT: i realised that shifting the position of variable b in the function around changes it's value too.


Solution

  • You need to use eval() in order to obtain the calculated result of a variable.

    So, replacing the line results = f(q, w, e) with results = f.eval({a: q, b: w, c: e}) would get the expected result.