forked from Wilson-TKU/PyTorchIPFS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
39 lines (32 loc) · 992 Bytes
/
test.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
35
36
37
38
39
# import ipfshttpclient
# import pytorchipfs
from src.pytorchipfs import __init__
import torch
import torchvision.transforms as transforms
hashes = [
'bafkreic3aeripksj7a7pnvkiybq3i43hme6pxlmpx7jaokubpz2lfdrvti'
]
client = ipfshttpclient.connect()
# Standard dataset
dataset = pytorchipfs.datasets.IPFSImageTensorDataset(
client,
'data', # Where the files will be downloaded
None, # Don't make assumptions about the image shape
hashes
)
# Dataset with cropping (to be fed to the model)
cropped_dataset = pytorchipfs.datasets.IPFSImageTensorDataset(
client,
'data', # Where the files will be downloaded
None, # Don't make assumptions about the image shape
hashes,
transform=transforms.CenterCrop(32) # Crop the images
)
import matplotlib.pyplot as plt
import numpy as np
for image in dataset:
# Convert to channel-last Numpy
image = image.cpu().numpy() / 255
image = np.transpose(image, (2, 1, 0))
plt.imshow(image)
plt.show()