Python Forum
How to invert pixel numbers of MNIST data set
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to invert pixel numbers of MNIST data set
#1
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. :(


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
pass 
This 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) 
Reply


Messages In This Thread
How to invert pixel numbers of MNIST data set - by squillam - Oct-15-2019, 09:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Voxel to pixel graphics voicemail 3 649 Nov-19-2023, 09:45 AM
Last Post: paul18fr
  Pixel color and action Sartre 4 2,222 Apr-13-2023, 03:26 AM
Last Post: Sartre
  Dynamic pixel display jerryf 2 773 Mar-17-2023, 07:26 PM
Last Post: jerryf
  How to invert scatter plot axis Mark17 3 2,645 Sep-22-2021, 04:45 PM
Last Post: jefsummers
  Plotting Pixel Intensity Doev 0 1,780 Oct-21-2020, 10:56 PM
Last Post: Doev
  5 variants to invert dictionaries with non-unique values Drakax1 2 2,674 Aug-31-2020, 11:40 AM
Last Post: snippsat
  Invert Pillow image colours chesschaser 5 4,001 Jul-11-2020, 02:59 PM
Last Post: chesschaser
  Return draw.rectangle pixel coordinate data to .csv file CephloRhod 0 2,426 May-20-2020, 10:37 AM
Last Post: CephloRhod
  What is the best way to search for a pixel in a screenshot? TheZadok42 1 2,696 May-15-2020, 12:37 PM
Last Post: scidam
  Issue with creating an array of pixel data for PNG files in Google Colab The_Sarco 1 1,976 Apr-29-2020, 12:03 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020