Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • arouxel/simulation-oxydation-vcsel
1 result
Show changes
Commits on Source (2)
import pytorch_lightning as pl
from torch.utils.data import Dataset, DataLoader
import os
import numpy as np
### DATASET STRUCTURE
### --- IMAGES ONLY ---
# -- labels folder
# * example file : mask_0.png with 0,1,2,...
# -- data folder
# * example file :
class VCSELDataset(Dataset):
def __init__(self, image_paths, label_paths, transform=None):
"""
Args:
image_paths (list): List of paths to hyperspectral images.
label_paths (list): List of paths to corresponding segmentation labels.
transform (callable, optional): Optional transform to be applied on a sample.
"""
self.image_paths = image_paths
self.label_paths = label_paths
self.transform = transform
def __len__(self):
pass
def __getitem__(self, idx):
hyperspectral_cube = self.load_hyperspectral_cube(idx)
if self.transform:
hyperspectral_cube = self.transform(hyperspectral_cube)
return hyperspectral_cube
def load_hyperspectral_cube(self, idx):
spectra = np.load(os.path.join(self.image_paths[idx], "spectra.npy"))
map = np.load(os.path.join(self.image_paths[idx], "map.npy"))
hyperspectral_cube = self.generate_hyperspectral_cube(spectra, map)
return hyperspectral_cube
def generate_hyperspectral_cube(self, spectra, map):
nb_of_spectra = spectra.shape[0]
# Ensure map values are within valid range
map = np.clip(map, 0, nb_of_spectra - 1)
# Index spectra with the map to generate the hyperspectral cube
hyperspectral_cube = spectra[map]
return hyperspectral_cube
class VCSELDataModule(pl.LightningDataModule):
def __init__(self,data_dir,batch_size,num_workers):
self.data_dir = data_dir
self.batch_size = batch_size
self.num_workers = num_workers
def prepare_data(self):
pass
def setup(stage):
pass
def train_dataloader(self):
pass
def val_dataloader(self):
pass
def test_dataloader(self):
pass
#--- LOADING DATA
# Load spectra
# Load ground truth png
#--- PREPROCESSING DATA
# Add smooth noise to the spectra (impurities in the materials) : ie add a std depending on lambda for each spectrum
# --> TO BE CONSIDERED CAREFULLY
# * should we generate various spectra for each material to take into account non regular surface ?
# Generate spectral filters using one of the following methods : PCA+LDA or neural network
#