Views
No views yet
trust_remote_code=True.1import numpy as np
2
3from transformers import AutoModel, AutoProcessor
4
5
6model = AutoModel.from_pretrained("giovannicozzolongo/astroclip", trust_remote_code=True)
7processor = AutoProcessor.from_pretrained("giovannicozzolongo/astroclip", trust_remote_code=True)
8
9image = np.load("galaxy_grz_cutout.npy") # shape: (3, height, width), bands: g, r, z
10spectrum = np.load("galaxy_spectrum.npy")
11
12inputs = processor(images=image, spectra=spectrum, return_tensors="pt")
13outputs = model(**inputs)
14
15image_embeddings = outputs.image_embeds
16spectrum_embeddings = outputs.spectrum_embeds
17similarity = outputs.logits_per_imageAstroClipImageProcessor with
band_indices so the selected channels correspond to the g,r,z bands used by
the upstream checkpoint.g,r,z(length,), (batch, length) or (batch, length, 1)spectrum_values with shape (batch, 778, 22).AutoModel.from_pretrained(..., trust_remote_code=True)AutoProcessor.from_pretrained(..., trust_remote_code=True)(batch, 1024) image and
spectrum embeddingsrtol=1e-4, atol=1e-5 for image embeddings, spectrum embeddings, logits and
contrastive loss.g,r,z cutouts and the spectrum
side uses DESI spectra. See the paper and upstream repository for dataset
details.trust_remote_code=True because the model code is included
in this Hub repository rather than in the main Transformers library.1@misc{parker2024astroclipcrossmodalfoundationmodel,
2 title={AstroCLIP: A Cross-Modal Foundation Model for Galaxies},
3 author={Liam Parker and Francois Lanusse and Siavash Golkar and
4 Leopoldo Sarra and Miles Cranmer and Alberto Bietti and
5 Michael Eickenberg and Geraud Krawezik and Michael McCabe and
6 Ruben Ohana and Mariel Pettee and Bruno Regaldo-Saint Blancard and
7 Tiberiu Tesileanu and Kyunghyun Cho and Shirley Ho},
8 year={2024},
9 eprint={2310.03024},
10 archivePrefix={arXiv},
11 primaryClass={astro-ph.IM},
12 doi={10.1093/mnras/stae1450},
13 url={https://arxiv.org/abs/2310.03024},
14}