예제 #1
0
 def __init__(self, batch_size=1000, train=True):
     self.batch_size = batch_size
     self.classes = 10
     if train:
         self.images, self.labels, _, _ = mnist_web.mnist(path='.')
     else:
         _, _, self.images, self.labels = mnist_web.mnist(path='.')
     self.n = self.images.shape[0]
     self.images *= 255
     self.images = self.images.astype(int)
     self.images[self.images <= 128] = -1
     self.images[self.images > 128] = 1
예제 #2
0
 def __init__(self, train=True, cuda=False):
     if train:
         self.images, self.labels, _, _ = mnist_web.mnist(path='.')
     else:
         _, _, self.images, self.labels = mnist_web.mnist(path='.')
     self.images *= 255
     self.images = self.images.astype('int32')
     #self.labels = np.sum(self.labels * np.arange(0,10),1).reshape(-1,1)
     self.labels = self.labels.astype('int32')
     self.images[self.images <= 128] = -1
     self.images[self.images > 128] = 1
     self.images = torch.from_numpy(self.images)
     self.labels = torch.from_numpy(self.labels)
     if cuda:
         self.images = self.images.float().cuda()
         self.labels = self.labels.float().cuda()
예제 #3
0
 def __init__(self, train = True, margin = 0, noise_rate = 0):
     if train:
         self.train = True
         self.images, self.labels, _, _= mnist_web.mnist(path='.')
         self.MARGIN = margin
         self.noise_rate = noise_rate
     else:
         self.train = False
         self.MARGIN = 0
         self.noise_rate = 0
         _, _, self.images, self.labels = mnist_web.mnist(path='.')
     #self.labels = np.sum(self.labels * np.arange(0,10),1).reshape(-1,1)
     self.len = self.labels.shape[0]
     self.images *= 255
     self.images[self.images<=128] = -1
     self.images[self.images>128] = 1
     self.images = torch.from_numpy(self.images).type(DTYPE)
     self.images_raw= self.images.clone()
     self.labels = torch.from_numpy(self.labels).type(DTYPE)
     self.images = self.images.reshape(-1, IMAGE_R, IMAGE_R)
     self.images = torch.nn.functional.pad(self.images, \
             (self.MARGIN,self.MARGIN,self.MARGIN,self.MARGIN), "constant", -1)
예제 #4
0
def load_data_wrapper2(path):
    train_images, train_labels, test_images, test_labels = mnist_web.mnist(
        path)

    training_inputs = [np.reshape(x, (784, 1)) for x in train_images]
    training_results = [vectorized_result2(y) for y in train_labels]
    training_data = list(zip(training_inputs, training_results))
    # validation_inputs = [np.reshape(x, (784, 1)) for x in test_images]
    # validation_data = zip(validation_inputs, va_d[1])
    test_inputs = [
        np.reshape(x, (784, 1)) for x in test_images
    ]  # np.concatenate([np.reshape(x, (784, 1)) for x in test_images], axis=1)
    test_results = [vectorized_result3(y) for y in test_labels]
    test_data = list(zip(test_inputs, test_results))

    return training_data, test_data