File size: 780 Bytes
42d27cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pickle
import numpy as np
import os
import matplotlib.pyplot as plt

def load_pkls(path):
    assert os.path.isfile(path), path
    images = []
    with open(path, "rb") as f:
        images += pickle.load(f)
    assert len(images) > 0, path
    images = [np.transpose(image, [2, 0, 1]) for image in images]
    return images

path = 'datasets/DIV2K-va.pklv4'
loaded_images = load_pkls(path)
print(len(loaded_images))
# Display the first image
if loaded_images:
    first_image = loaded_images[11]
    plt.imshow(np.transpose(first_image, [1, 2, 0]))  # Transpose image to original shape [height, width, channels]
    plt.title('First Image')
    plt.axis('off')  # Hide axis
    plt.show()
else:
    print("No images loaded from the pickle file.")
print(loaded_images[11])