Browse Source

Fix execution of user script

Path is related to the root python script.
DricomDragon 5 years ago
parent
commit
032de4ba78
1 changed files with 14 additions and 3 deletions
  1. 14 3
      python/lab/io_mnist.py

+ 14 - 3
python/lab/io_mnist.py

@@ -1,19 +1,24 @@
 from mnist import MNIST
 import numpy as np
 
-def load_training_samples():
+def load_samples(training):
 	"""
+	training : load training data if true, load testing data otherwise
+
 	Return np_images, np_expected
 	where
 	np_impages is a np.array of 784 x 60 000
 	np_expected is a np.array of 10 x 60 000
 	"""
-	mndata = MNIST('../../resources/download')
+	mndata = MNIST('../resources/download')
 
 	images = [[]] # Contains vectors of 784 pixels image
 	labels = [] # Contains expected response for each image
 
-	images, labels = mndata.load_training()
+	if (training):
+		images, labels = mndata.load_training()
+	else:
+		images, labels = mndata.load_testing()
 
 	np_images = np.array(images, dtype=np.float64)
 
@@ -26,3 +31,9 @@ def load_training_samples():
 		np_expected[k][label] = 1.0
 
 	return np.transpose(np_images), np.transpose(np_expected)
+
+def load_training_samples():
+	return load_samples(training = True)
+
+def load_testing_samples():
+	return load_samples(training = False)