Views
No views yet

1git clone https://github.com/MeriDK/AstroM3.git
2cd AstroM31uv venv venv --python 3.10.14
2source venv/bin/activate
3uv pip install -r requirements.txt1from datasets import load_dataset
2from src.data import process_photometry
3
4# Load the test dataset
5test_dataset = load_dataset('AstroMLCore/AstroM3Processed', name='full_42', split='test')
6
7# Process photometry to have a fixed sequence length of 200 (center-cropped)
8test_dataset = test_dataset.map(process_photometry, batched=True, fn_kwargs={'seq_len': 200, 'how': 'center'})
9test_dataset = test_dataset.with_format('torch')1import torch
2from src.model import AstroM3
3
4# Load the base AstroM3-CLIP model
5model = AstroM3.from_pretrained('AstroMLCore/AstroM3-CLIP')
6
7# Retrieve the first sample (batch size = 1)
8sample = test_dataset[0:1]
9photometry = sample['photometry']
10photometry_mask = sample['photometry_mask']
11spectra = sample['spectra']
12metadata = sample['metadata']
13
14# Example 1: Generate embeddings when all modalities are present
15p_emb, s_emb, m_emb = model.get_embeddings(photometry, photometry_mask, spectra, metadata)
16multimodal_emb = (p_emb + s_emb + m_emb) / 3
17print('Multimodal Embedding (All Modalities):', multimodal_emb)
18
19# Example 2: Generate embeddings when the spectra modality is missing
20dummy_spectra = torch.zeros_like(spectra) # Dummy tensor for missing spectra
21p_emb, s_emb, m_emb = model.get_embeddings(photometry, photometry_mask, dummy_spectra, metadata)
22multimodal_emb_missing = (p_emb + m_emb) / 2
23print('Multimodal Embedding (Spectra Missing):', multimodal_emb_missing)1from src.model import AstroM3, Informer, GalSpecNet, MetaModel
2
3# Photometry classification
4photo_model = Informer.from_pretrained('AstroMLCore/AstroM3-CLIP-photo')
5prediction = photo_model(photometry, photometry_mask).argmax(dim=1).item()
6print('Photometry Classification:', test_dataset.features['label'].int2str(prediction))
7
8# Spectra classification
9spectra_model = GalSpecNet.from_pretrained('AstroMLCore/AstroM3-CLIP-spectra')
10prediction = spectra_model(spectra).argmax(dim=1).item()
11print('Spectra Classification:', test_dataset.features['label'].int2str(prediction))
12
13# Metadata classification
14meta_model = MetaModel.from_pretrained('AstroMLCore/AstroM3-CLIP-meta')
15prediction = meta_model(metadata).argmax(dim=1).item()
16print('Metadata Classification:', test_dataset.features['label'].int2str(prediction))
17
18# Multimodal classification
19all_model = AstroM3.from_pretrained('AstroMLCore/AstroM3-CLIP-all')
20prediction = all_model(photometry, photometry_mask, spectra, metadata).argmax(dim=1).item()
21print('Multimodal Classification:', test_dataset.features['label'].int2str(prediction))| # Model | # Description |
|---|---|
| AstroM3-CLIP | The base model pre-trained using the trimodal CLIP approach. |
| AstroM3-CLIP-meta | Fine-tuned for metadata-only classification. |
| AstroM3-CLIP-spectra | Fine-tuned for spectra-only classification. |
| AstroM3-CLIP-photo | Fine-tuned for photometry-only classification. |
| AstroM3-CLIP-all | Fine-tuned for multimodal classification. |
| # Model | # Description |
|---|---|
| AstroM3-CLIP-42 | The base model pre-trained with random seed 42 (identical to AstroM3-CLIP). |
| AstroM3-CLIP-0 | AstroM3-CLIP pre-trained with random seed 0 (use dataset with seed 0). |
| AstroM3-CLIP-66 | AstroM3-CLIP pre-trained with random seed 66 (use dataset with seed 66). |
| AstroM3-CLIP-12 | AstroM3-CLIP pre-trained with random seed 12 (use dataset with seed 12). |
| AstroM3-CLIP-123 | AstroM3-CLIP pre-trained with random seed 123 (use dataset with seed 123). |
preprocess.py in the AstroM3Dataset repo.1@article{rizhko2024astrom,
2 title={AstroM $\^{} 3$: A self-supervised multimodal model for astronomy},
3 author={Rizhko, Mariia and Bloom, Joshua S},
4 journal={arXiv preprint arXiv:2411.08842},
5 year={2024}
6}