Oct-15-2019, 09:31 PM
So I'm trying to:
a) invert the pixel values of the mnist training data set and
b) run it in 5 epochs
I have zero experience or idea of how to do this. Have been googling for hours but now just want a straight up answer. :(
a) invert the pixel values of the mnist training data set and
b) run it in 5 epochs
I have zero experience or idea of how to do this. Have been googling for hours but now just want a straight up answer. :(
import numpy as np from PIL import Image epochs = 5 for e in range(epochs): for record in training_data_list: all_values = record.split(',') inputs = (numpy.asfarray(all_values[1:]) / 255.0 * 0.99) + 0.01 training_data_file = open("mnist_train.csv", 'r') training_data_list = training_data_file.readlines() training_data_file.close() test_data_file = open("mnist_test.csv", 'r') test_data_list = test_data_file.readlines() test_data_file.close() #def inverseImageBW_array(originalImage): # temp = 1 - originalImage # temp = -1.* originalImage # return temp targets = numpy.zeros(output_nodes) + 0.01 targets[int(all_values[0])] = 0.99 n.train(inputs, targets) pass passThis is my next cell
test_data_file = open("mnist_test.csv", 'r') test_data_list = test_data_file.readlines() test_data_file.close() scorecard = [] for record in test_data_list: all_values = record.split(',') correct_label = int(all_values[0]) inputs = (numpy.asfarray(all_values[1:]) / 255.0 * 0.99) + 0.01 outputs = n.query(inputs) label = numpy.argmax(outputs) if (label == correct_label): scorecard.append(1) else: scorecard.append(0) pass pass scorecard_array = numpy.asarray(scorecard) print ("performance = ", scorecard_array.sum() * 100 / scorecard_array.size)