Read data from CNTK model file

assumes that the data has already been dumped to a file in the current directory, called AlexNetDump.txt, representing an AlexNet model from the CNTK AlexNet example in CNTK/Tests/EndToEndTest/Image/AlexNet


In [ ]:
import numpy as np
from matplotlib import pyplot as plt

In [ ]:
infile = open("./AlexNetDump.txt")

In [ ]:
# discard first 3 lines, containing '\n', 
# 'ce=CrossEntropyWithSoftmax ( labels , OutputNodes.z ) \n'
# 'conv1.b=LearnableParameter [1,64]   learningRateMultiplier=1.000000  NeedsGradient=true \n'
# first entry is conv1 layer bias values
for i in range(3):
    infile.readline()

In [ ]:
txtline = infile.readline()
a = txtline.split()
conv1_bias = []
for i in range(64):
    conv1_bias.append(float(a[i]))
conv1_bias_matrix = np.matrix(conv1_bias).reshape(8,8)

In [ ]:
conv1_bias_matrix
next 5 lines describe the conv1 weights, followed by 64 lines of 363 weights each #################################################################### conv1.c=Convolution ( conv1.W , features ) Geometry: Input: 224 x 224 x 3, Output: 56 x 56 x 64, Kernel: 11 x 11 x 3, Map: 1 x 1 x 64, Stride: 4 x 4 x 3, Sharing: (1), AutoPad: (1), LowerPad: 0, UpperPad: 0 PoolKind: 0 conv1.W=LearnableParameter [64,363] learningRateMultiplier=1.000000 NeedsGradient=true

In [ ]:
txtline = infile.readline()
a = txtline.split()
conv1_w = []
for i in range(363):
    conv1_bias.append(float(a[i])
conv1_w_matrix = np.array(conv1_bias).reshape(3, 11, 11)

In [ ]:
txtline

In [ ]:
plt.imshow(c)
plt.show()

In [ ]:
txtline1 = infile.readline()
txtline1

In [ ]: