Dies ist eine alte Version des Dokuments!
—————————————————————————-
from scipy import misc import numpy as np import matplotlib.pyplot as plt class Bild(object): def __init__(self,daten=None, info=None): self.daten = daten if info: self.info=info else: self.info= '' def read_from_file(self,name): self.daten = misc.imread(name, 'F') self.info = "From file: " + name def show(self): plt.imshow(self.daten,cmap=plt.get_cmap('gray')) plt.show() def bildlesen(): bild=Bild() nameBild=raw_input("Gib den Namen des Bildes ein: ") bild.read_from_file(nameBild) print "Bild shape: ", bild.daten.shape if bild.daten.shape== (28,28): bild.daten= np.reshape(bild.daten, (784,1)) print "Bild erfolgreich in Vektor geschrieben: ", bild.daten.shape elif bild.daten.shape== [784,1]: print "Bild bereits im richtigem Format, Vorgang wird fortgesetzt. " elif bild.daten.shape[0]%2!=0 or bild.daten.shape[1]%2!=0: print "Es wird ein Bild mit einer geraden Anzahl an Pixlen benoetigt!" else: bild.daten=bild.daten[bild.daten.shape[0]/2-14:bild.daten.shape[0]/2+14, bild.daten.shape[1]/2-14:bild.daten.shape[1]/2+14] bild.daten= np.reshape(bild.daten,(784,1)) print "Bild erfolgreich auf 28x28 editiert und in einen Vektor", bild.daten.shape, "umgewandelt." return bild
from pickle import Unpickler with open('clean_symbols.p','r') as f: u=Unpickler(f) data=u.load() print "Datentupel, 0. Komponente: " print "Shape: ",data[0].shape print "Datentupel, 1. Komponente: " print data[1][:10] print "Shape: ", data[1].shape print "Datentupel, 2. Komponente: " print data[2][:10] print "Shape: ", data[2].shape
Porgramm knNTest.py ist extrem langsam. Aus diesem Grund untersuchen wir mit cProfile, wo die Zeit in dem Programm verloren geht.
import cprofile cProfile.run('bestimmung(10)',sort='time') bestimmung(10)