예제 #1
0
 def cifar10_batches(self,
                     name,
                     downsample,
                     batch_size,
                     num,
                     total_num=12800):
     assert name in ['train', 'test']
     assert total_num % batch_size == 0 or batch_size == -1
     X0, y0 = (cf10.load_training_data()
               if name == 'train' else cf10.load_test_data())
     X = X0[:total_num]
     X_batch = X[num * batch_size:(num + 1) + batch_size]
     X_batch = X_batch[:, ::downsample, ::downsample, :]
     return X_batch
예제 #2
0
def cifar10_dataset_generator(dataset_name, batch_size, restrict_size=1000):
    assert dataset_name in ['train', 'test']
    assert batch_size > 0 or batch_size == -1  # -1 for entire dataset
    
    X_all_unrestricted, y_all = (cf10.load_training_data() if dataset_name == 'train'
                                 else cf10.load_test_data())
    
    actual_restrict_size = restrict_size if dataset_name == 'train' else int(1e10)
    X_all = X_all_unrestricted[:actual_restrict_size]
    data_len = X_all.shape[0]
    batch_size = batch_size if batch_size > 0 else data_len
    
    X_all_padded = np.concatenate([X_all, X_all[:batch_size]], axis=0)
    y_all_padded = np.concatenate([y_all, y_all[:batch_size]], axis=0)
    
    for slice_i in range(int(math.ceil(data_len / batch_size))):
        idx = slice_i * batch_size
        X_batch = X_all_padded[idx:idx + batch_size]
        y_batch = np.ravel(y_all_padded[idx:idx + batch_size])
        yield X_batch.astype(np.uint8), y_batch.astype(np.uint8)
예제 #3
0
 def cifar10_dataset(self, name, downsample, total_num):
     assert name in ['train', 'test']
     X, y = (cf10.load_training_data()
             if name == 'train' else cf10.load_test_data())
     data = X[:total_num]
     return data[:, ::downsample, ::downsample, :]