forked from corenel/pytorch-adda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_check.py
34 lines (30 loc) · 1.14 KB
/
data_check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import numpy as np
import matplotlib.pyplot as plt
import struct
# Function to load ubyte dataset
def load_mnist_images(filename):
with open(filename, 'rb') as f:
# First 16 bytes are the header
f.read(16)
# Remaining bytes are the image pixels
data = np.frombuffer(f.read(), dtype=np.uint8)
data = data.reshape(-1, 28, 28) # MNIST images are 28x28 pixels
return data
def load_mnist_labels(filename):
with open(filename, 'rb') as f:
# First 8 bytes are the header
f.read(8)
# Remaining bytes are the labels
labels = np.frombuffer(f.read(), dtype=np.uint8)
return labels
# Load the dataset
images = load_mnist_images(r'B:\_GITHUB\domain_adaptive_thorax_disease_classification\pytorch-adda\data\MNIST\raw\train-images-idx3-ubyte')
labels = load_mnist_labels(r'B:\_GITHUB\domain_adaptive_thorax_disease_classification\pytorch-adda\data\MNIST\raw\t10k-images-idx3-ubyte')
# Visualize some images
plt.figure(figsize=(10, 10))
for i in range(25):
plt.subplot(5, 5, i+1)
plt.imshow(images[i], cmap='gray')
plt.title(f"Label: {labels[i]}")
plt.axis('off')
plt.show()