Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ def __getitem__(self, idx):
img = np.load(img_path, allow_pickle = True)
if class_name == 'axion':
img = img[0]
img = (img - np.min(img))/(np.max(img) - np.min(img))
eps = 1e-8
img_min = np.min(img)
img_max = np.max(img)
img = (img - img_min) / (img_max - img_min + eps)

if self.transform:
aug = self.transform(image=img)
img = aug['image']

img = img.to(torch.float)
img = img.to(torch.float32)
class_id = self.class_map[class_name]
class_id = torch.tensor(class_id)

Expand All @@ -80,4 +83,10 @@ def create_full_test_dataloader(full_test_data_path, test_transforms, batch_size
)

full_test_loader, class_map = create_full_test_dataloader(FULL_TEST_DATA_PATH, test_transforms, BATCH_SIZE)

# ---- normalization sanity check ----
const_img = np.ones((64, 64))

eps = 1e-8
out = (const_img - const_img.min()) / (const_img.max() - const_img.min() + eps)

print("Normalization NaN check:", np.isnan(out).any())
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,20 @@ def __len__(self):
def __getitem__(self, idx):
path = self.data[idx]
img = np.load(path, allow_pickle = True)
img = (img - np.min(img))/(np.max(img) - np.min(img))
eps = 1e-8
img_min = np.min(img)
img_max = np.max(img)
img = (img - img_min) / (img_max - img_min + eps)


if self.transform:
aug = self.transform(image = img)
img = aug['image']

img = img.to(torch.float)
if isinstance(img, torch.Tensor):
img = img.to(torch.float32)
else:
img = torch.tensor(img, dtype=torch.float32)

return img

Expand Down Expand Up @@ -96,7 +102,7 @@ def create_dataloaders(train_data_path, test_data_path, train_transforms, test_t
BATCH_SIZE
)
single_batch = next(iter(test_loader))
print(f"Shape of a single batch of data: {single_batch[0].shape}")
print(f"Shape of a single batch of data: {single_batch.shape}")

single_batch_grid = utils.make_grid(single_batch[:16], nrow=8)
plt.figure(figsize = (20,70))
Expand Down