galaxy.segmentation
Script to create segmentation maps for models.
To create segmentation maps for randomly chosen clusters, random objects and stars use function saveSegMaps(). To create a segmentation map with larger scale for a randomly chosen cluster use function saveBigSegMap().
Functions
|
Cleans up memory by deleting variables and freeing GPU memory. |
|
Loads a trained model with specific weights. |
|
Ensures the segmentation sample exists by downloading or generating it. |
|
Generates surrounding grid points for a given radius. |
|
|
|
Creates a dataloader for a segmentation map. |
|
Prepares dataloaders for segmentation map samples. |
|
Creates a segmentation map plot for a given sample. |
|
Creates segmentation maps for all samples. |
Module Contents
- galaxy.segmentation.cleanup_memory(*args) None
Cleans up memory by deleting variables and freeing GPU memory.
- Args:
*args: Variables to be deleted.
- galaxy.segmentation.load_model(model: torch.nn.Module, n_in_channels: int, optimizer_name: str, device: torch.device) torch.nn.Module
Loads a trained model with specific weights.
- Args:
model (torch.nn.Module): The model to be loaded. optimizer_name (str): Name of the optimizer used during training. device (torch.device): Device to load the model on.
- Returns:
torch.nn.Module: The loaded model.
- galaxy.segmentation.create_sample(sample_name: galaxy.util.SampleName2, dataset: str) tuple[pandas.DataFrame, galaxy.util.MapType]
Ensures the segmentation sample exists by downloading or generating it.
- Returns:
tuple: Sample dataframe and map type.
- galaxy.segmentation.grab_surrounding(points_on_radius: int) Generator[tuple[int, int], None, None]
Generates surrounding grid points for a given radius.
- Args:
points_on_radius (int): Radius in grid points.
- Yields:
tuple[int, int]: Coordinates of grid points.
- galaxy.segmentation.ddos_segmentation_map(map_type: galaxy.util.MapType, ra_start: float, dec_start: float, map_dir: pathlib.Path, description_path: pathlib.Path, already_ddosed=False)
- galaxy.segmentation.create_map_dataloader(map_dir: pathlib.Path, dataset: str) torch.utils.data.DataLoader
Creates a dataloader for a segmentation map.
- Args:
map_type (MapType): Type of the map. ra_start (float): Starting RA coordinate. dec_start (float): Starting Dec coordinate. map_dir (Path): Directory to save the map data. survey (str, optional): Survey name. Defaults to None. bands (list, optional): List of bands. Defaults to None. imgsize_pix (int, optional): Image size in pixels. Defaults to 224.
- Returns:
DataLoader: Dataloader object for the segmentation map.
- galaxy.segmentation.prepare_sample_dataloaders(data: pandas.DataFrame, sample_name: galaxy.util.SampleName2, dataset: str, map_type: galaxy.util.MapType) list[tuple[int, torch.utils.data.DataLoader]]
Prepares dataloaders for segmentation map samples.
- Args:
data (pd.DataFrame): Data describing the samples. sample_name (SampleName2): Name of the sample. map_type (MapType): Type of map to generate.
- Returns:
list[tuple[int, DataLoader]]: List of tuples containing index and dataloader.
- galaxy.segmentation.create_segmentation_plot(model_name: str, optimizer_name: str, num_epochs: int, predictor: galaxy.train.Predictor, dataset: str, sample_name: galaxy.util.SampleName2, n_cols: int = 5) None
Creates a segmentation map plot for a given sample.
- Args:
model_name (str): Name of the model. optimizer_name (str): Name of the optimizer used during training. predictor (train.Predictor): Predictor for making predictions. sample_name (SampleName2): Name of the sample. n_cols (int, optional): Number of columns in the plot. Defaults to 5.
- galaxy.segmentation.create_segmentation_plots(model: torch.nn.Module, model_name: str, dataset: str, n_in_channels: int, num_epochs: int, optimizer_name: str, map_type: galaxy.util.MapType = MapType.SMALL) None
Creates segmentation maps for all samples.
- Args:
model (torch.nn.Module): The model used for predictions. model_name (str): Name of the model. optimizer_name (str): Name of the optimizer used during training. map_type (MapType, optional): Type of map to generate. Defaults to MapType.SMALL.
- Returns:
None