def giveMeNewTraining(self): x_tmp = [] y_tmp = [] print("Starting to create new training data ") for c, files in self.trainingsets.iteritems(): y = self.testsets.keys().index( c) #We use the testset as a reference for file in files: image = cv2.imread( self.path + c + '/' + file, cv2.CV_LOAD_IMAGE_GRAYSCALE) #unit8 from e.g. 34 to 255 image2 = expandTraining.distorb(image / 255.) # cv2.imshow('org', cv2.resize(image, (280, 280))) # cv2.imshow('mani', cv2.resize(image2, (280, 280))) # cv2.waitKey(2000) x_tmp.append(np.reshape( image2, len(image2)**2)) #To floats from 0 to 1 y_tmp.append(y) print("Finished, creating new training data") perm = np.random.permutation(len(y_tmp)) return theano.shared(np.asarray(x_tmp, theano.config.floatX)[perm], borrow=True), T.cast( theano.shared(np.asarray( y_tmp, theano.config.floatX)[perm], borrow=True), 'int32')
def giveMeNewTraining(): y_table = np.zeros(10) y_tmp = [] x_tmp = [] if (show): cv2.namedWindow('Original', cv2.WINDOW_NORMAL) cv2.namedWindow('Preprocessed', cv2.WINDOW_NORMAL) minV = 1e100 maxV = -1e100 c = 0 with gzip.open(filenameValidation) as f: reader = csv.reader(f) for row in reader: y = int(row[0]) y_tmp.append(y) y_table[y] += 1 vals = np.asarray(row[1:], np.uint8) n = int(np.sqrt(vals.shape[0])) img_org = np.reshape(vals/255., (n, n)) import expandTraining img_dist = expandTraining.distorb(img_org) img_dist = mask_on_rect2(img_dist) x_tmp.append(img_dist.reshape(-1)) if show: cv2.imshow('Original', img_org) cv2.imshow('Preprocessed', img_dist) cv2.waitKey(1) c += 1 print(" Data Range" + str(minV) + " " + str(maxV) + " number of training examples " + str(c)) print(" Balance " + str(y_table)) train_set = np.asarray(x_tmp, theano.config.floatX), np.asarray(y_tmp, theano.config.floatX) return shared_dataset(train_set, np.random.permutation(train_set[1].shape[0]), testnum=2)
def giveMeNewTraining(self): x_tmp = [] y_tmp = [] print("Starting to create new training data ") for c,files in self.trainingsets.iteritems(): y = self.testsets.keys().index(c) #We use the testset as a reference for file in files: image = cv2.imread(self.path + c + '/' + file, cv2.CV_LOAD_IMAGE_GRAYSCALE) #unit8 from e.g. 34 to 255 image2 = expandTraining.distorb(image / 255.) # cv2.imshow('org', cv2.resize(image, (280, 280))) # cv2.imshow('mani', cv2.resize(image2, (280, 280))) # cv2.waitKey(2000) x_tmp.append(np.reshape(image2, len(image2)**2)) #To floats from 0 to 1 y_tmp.append(y) print("Finished, creating new training data") perm = np.random.permutation(len(y_tmp)) return theano.shared(np.asarray(x_tmp, theano.config.floatX)[perm],borrow=True), T.cast(theano.shared(np.asarray(y_tmp, theano.config.floatX)[perm],borrow=True), 'int32')