I have this MNIST data set of 10,000 rows and I'm trying to apply a convolution kernel to every single row, but what my code does only produces the last line after it's done. It's been reshaped to 28,28. This is a snippet the raw original data set. 10000 rows of 784 numbers that corresponds to MNIST data.
test_data_file = open("mnist_test.csv", 'r')
test_data_list = test_data_file.readlines()
test_data_file.close()
for record in test_data_list: # test_data_list is all the values in the test file
all_values = record.split(',') # split each record (image) into values seperated by commas
correct_label = int(all_values[0]) # the first value is the lab
inputs = (numpy.asfarray(all_values[1:]))
original = numpy.asfarray(inputs.reshape((28,28))) # the list is made into an array
sharpen_kernel = np.array([
[0, -1, 0],
[-1, 5, -1],
[0, -1, 0]])
matplotlib.rcParams['figure.figsize'] = 20,20 # convolve your image with the kernel
conv_image = numpy.ones((28,28))
# make a subarray and convolve it with the kernel
step = 3
i=0
while i < 25:
i+=1
j = 0
while j < 25 :
sub_image = original[i:(i+step),j:(j+step):]
sub_image = numpy.reshape(sub_image,(1,(step ** 2)))
kernel = numpy.reshape(sharpen_kernel, ((step ** 2),1))
conv_scalar = numpy.dot(sub_image,kernel)
sharpened[i,j] = conv_scalar
j+=1
pass
This is what I get when I np.savetxt it into a new file. You see that it's only one single line. I want to produce a new csv file with ALL 10,000 rows after applying the kernel.
And when I matplot my 'sharpened' image, I only get a singular image. Do I have to use count+= function or add a new loop somewhere after the 'for record in ...' line? A very confused newbie.