Views
No views yet
1from perturblab.model.cellfm import CellFMModel
2
3# Load pretrained model
4model = CellFMModel.from_pretrained('cellfm-80m')
5
6# Or from local path
7model = CellFMModel.from_pretrained('./weights/cellfm-80m')1import scanpy as sc
2from perturblab.data import PerturbationData
3
4# Load your data
5adata = sc.read_h5ad('your_data.h5ad')
6
7# Preprocess
8adata = CellFMModel.prepare_data(adata)
9
10# Get embeddings
11embeddings = model.predict_embeddings(
12 adata,
13 batch_size=32,
14 return_cls_token=True,
15)
16
17# Access cell embeddings
18cell_embeddings = embeddings['cell_embeddings'] # Shape: (n_cells, enc_dims)1from perturblab.model.cellfm import CellFMModel, CellFMConfig
2
3# Initialize model with classification head
4config = CellFMConfig(
5 model_name='80M',
6 num_cls=10, # Number of cell types
7)
8model = CellFMModel(config, for_finetuning=True)
9
10# Load pretrained weights
11model.load_weights('./weights/cellfm-80m/model.pt')
12
13# Fine-tune on your labeled data
14# ... (training code)1from perturblab.model.cellfm import CellFMPerturbationModel
2from perturblab.data import PerturbationData
3
4# Load perturbation data
5data = PerturbationData.from_anndata(adata)
6data.split_data(train=0.7, val=0.15, test=0.15)
7
8# Initialize model
9model = CellFMPerturbationModel.from_pretrained('cellfm-80m')
10
11# Initialize perturbation head
12model.init_perturbation_head_from_dataset(data)
13
14# Train
15model.train_model(data, epochs=20)
16
17# Predict
18predictions = model.predict_perturbation(data, split='test')config.json: Model configurationmodel.pt: Model weights (PyTorch state dict)README.md: This file1@article{cellfm2024,
2 title={CellFM: A Large-Scale Foundation Model for Single-Cell Transcriptomics},
3 author={...},
4 journal={...},
5 year={2024}
6}