added review sql database
This commit is contained in:
+30
-15
@@ -1,22 +1,37 @@
|
||||
from PIL import Image
|
||||
import os
|
||||
from matplotlib import pyplot as plt
|
||||
import torch
|
||||
|
||||
folder = "data/train"
|
||||
class TransformedSubset(torch.utils.data.Dataset):
|
||||
def __init__(self, subset, transform=None):
|
||||
self.subset = subset
|
||||
self.transform = transform
|
||||
|
||||
widths = []
|
||||
heights = []
|
||||
def __getitem__(self, idx):
|
||||
x, y = self.subset[idx]
|
||||
|
||||
for root, _, files in os.walk(folder):
|
||||
for file in files:
|
||||
if file.endswith((".jpg", ".png", ".jpeg")):
|
||||
path = os.path.join(root, file)
|
||||
img = Image.open(path)
|
||||
w, h = img.size
|
||||
widths.append(w)
|
||||
heights.append(h)
|
||||
if self.transform:
|
||||
x = self.transform(x)
|
||||
|
||||
avg_w = sum(widths) / len(widths)
|
||||
avg_h = sum(heights) / len(heights)
|
||||
return x, y
|
||||
|
||||
print("Average width:", avg_w)
|
||||
print("Average height:", avg_h)
|
||||
def __len__(self):
|
||||
return len(self.subset)
|
||||
|
||||
|
||||
def visualizeData(dataset):
|
||||
images, labels = next(iter(dataset))
|
||||
|
||||
for i in range(4):
|
||||
img = images[i]
|
||||
|
||||
# Convert tensor shape from [C,H,W] -> [H,W,C]
|
||||
img = img.permute(1, 2, 0)
|
||||
|
||||
plt.figure(figsize=(3,3))
|
||||
plt.imshow(img)
|
||||
plt.title(f"Label: {labels[i].item()}")
|
||||
plt.axis("off")
|
||||
|
||||
plt.show()
|
||||
Reference in New Issue
Block a user