1

With CNTK I have created a network with 2 input neurons and 1 output neuron. A line in the training file looks like

|features 1.567518 2.609619 |labels 1.000000 

Then the network was trained with brain script. Now I want to use the network for predicting values. For example: Input data is [1.82, 3.57]. What ist the output from the net?

I have tried Python with the following code, but here I am new. Code does not work. So my question is: How to pass the input data [1.82, 3.57] to the eval function?

On stackoverflow there are some hints, here and here, but this is too abstract for me.

Thank you.

import cntk as ct
import numpy as np

z = ct.load_model("LR_reg.dnn", ct.device.cpu())

input_data= np.array([1.82, 3.57], dtype=np.float32)

pred = z.eval({ z.arguments[0] : input_data })

print(pred)
Guest_2015
  • 123
  • 4

1 Answers1

1

Here's the most defensive way of doing it. CNTK can be forgiving if you omit some of this when the network is specified with V2 constructs. Not sure about a network that was created with V1 code.

Basically you need a pair of braces for each axis. Which axes exist in Brainscript? There's a batch axis, a sequence axis and then the static axes of your network. You have one dimensional data so that means the following should work: input_data= np.array([[[1.82, 3.57]]], dtype=np.float32) This specifies a batch of one sequence, of length one, containing one 1d vector of two elements. You can also try omitting the outermost braces and see if you are getting the same result.

Update based on more information from the comment below, we should not forget that the V1 code also saved the part of the network that computes things like loss and accuracy. If we provide only the features, CNTK will complain that the labels have not been provided. There are two ways to deal with this issue. One possibility is to provide some fake labels, so that the network can evaluate these auxiliary operations. Another possibility is to identify the prediction and use that. If the prediction was called 'p' in V1, this python code

p = z.find_by_name('p')

should create a CNTK function that only needs the features in order to compute the prediction.

  • Thank you for anwering, but it did not work. I get the error message: ValueError: Values for 1 required arguments 'Input('features', [#, ], [2])', that the requested output(s) 'Output('err', [], []), Output('lr', [], []), Output('p', [#, ], [1])' depend on, have not been provided. – Guest_2015 Jun 13 '17 at 03:58
  • This error is because the V1 model saves also things that depend on the labels such as the 'err' and 'lr' outputs mentioned in the error message. I will update my answer on how to avoid this error. – Nikos Karampatziakis Jun 14 '17 at 01:56