From e8b65f8dfe36e420132c7f38d4e8be857bc9ea28 Mon Sep 17 00:00:00 2001
From: lucile <lucile.audard@ecl20.ec-lyon.fr>
Date: Fri, 20 Oct 2023 18:53:57 +0200
Subject: [PATCH] Create read_cifar.py

---
 read_cifar.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 read_cifar.py

diff --git a/read_cifar.py b/read_cifar.py
new file mode 100644
index 0000000..5d0736d
--- /dev/null
+++ b/read_cifar.py
@@ -0,0 +1,19 @@
+import pickle
+import numpy as np
+
+def unpickle(file):
+    with open(file, 'rb') as fo:
+        batch = pickle.load(fo, encoding='bytes')
+    return batch
+
+def read_cifar_batch(path):
+    batch = unpickle(path)
+    data = batch[b'data']
+    labels = batch[b'labels']
+    return np.float32(data), np.int64(labels)
+        
+        
+if __name__ == "__main__":
+    v1, v2 = read_cifar_batch("./data/cifar-10-batches-py/cifar-10-batches-py~/cifar-10-batches-py/data_batch_1")
+    print(v1)
+    print(v2)
-- 
GitLab