From 49087cb0b9f10f32fad4233d69b9abbd73bc0a4a Mon Sep 17 00:00:00 2001
From: Milan <milan.cart@ecl20.ec-lyon.fr>
Date: Thu, 9 Nov 2023 14:32:34 +0100
Subject: [PATCH] Update read_cifar.py

---
 read_cifar.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/read_cifar.py b/read_cifar.py
index da73e4b..c8cedb0 100644
--- a/read_cifar.py
+++ b/read_cifar.py
@@ -1,3 +1,15 @@
 import numpy as np
 
-print("Test")
\ No newline at end of file
+import pickle
+
+def read_cifar_batch(batch_path):
+
+  with open(batch_path, "rb") as f:
+    batch = pickle.load(f, encoding="bytes") 
+
+  data = np.array(batch[b'data'], dtype=np.float32)
+  labels = np.array(batch[b'labels'], dtype=np.int64)
+  
+  return data, labels
+
+print(read_cifar_batch('Data/cifar-10-batches-py/data_batch_2'))
\ No newline at end of file
-- 
GitLab