Search code examples
pythonmachine-learningcntk

Manually Reading a Minibacth contents in CNTK


I am modifying the CNTK 103B MNIST Tutorial to read PNG files directly instead of the original text file. I am having problems in having the model converge when I make the change, and would like to inspect the contents of the minibatches that are being read from PNG files to make sure this is not the reason the model stops working after changing the source of training data.

After this code:

mb = reader_test.next_minibatch(test_minibatch_size, input_map=input_map)

Is there a way to inspect the contents of the minibatch in python?


Solution

  • mb is just a dictionary from variables to minibatch_data. Minibatch data has a .value attribute you can use to see the minibatch as a numpy array. So something like for var in mb: print('minibatch data for variable "%s" with shape %s'%(var.name, var.shape)) print(mb[var].value) will work. However, printing a 784 dense vector will likely not be very helpful. Fortunately, it is easy to reshape each element of the minibatch to a 28 x 28 square and display it as an image inside the notebook.