Views
No views yet
pip install torch timm huggingface-hub1from huggingface_hub import hf_hub_download
2import torch
3import numpy as np
4from model import load_condensatepose_model
5
6# Download and load model
7model_path = hf_hub_download(
8 repo_id="rajlab/condensatepose-model",
9 filename="model_weights.pth"
10)
11
12model = load_condensatepose_model(model_path, device='cuda')
13model.eval()
14
15# Prepare your image (H, W) grayscale
16image = ... # Your microscopy image as numpy array
17
18# Normalize
19image = image.astype(np.float32)
20if image.max() > 1:
21 image = image / 255.0
22
23# Convert to tensor
24img_tensor = torch.from_numpy(image).unsqueeze(0).unsqueeze(0) # (1, 1, H, W)
25img_tensor = img_tensor.to('cuda')
26
27# Run inference
28with torch.no_grad():
29 outputs = model(img_tensor)
30
31# Get outputs
32mask_logits = outputs['mask'][0, 0].cpu().numpy() # (H, W)
33flow_vectors = outputs['flows'][0].cpu().numpy() # (2, H, W)
34
35# Apply sigmoid to get probabilities
36mask_prob = 1 / (1 + np.exp(-mask_logits))
37
38# Threshold to get binary mask
39binary_mask = (mask_prob > 0.5).astype(np.uint8)
40
41# Generate instance segmentation
42from scipy.ndimage import label
43instance_mask, num_objects = label(binary_mask)
44
45print(f"Detected {num_objects} condensates")1{
2 "model_type": "condensatepose",
3 "architecture": "efficientnetv2-fpn-style-modulation",
4 "task": "instance-segmentation",
5 "application": "biomolecular-condensate-detection",
6 "framework": "pytorch",
7 "encoder_variant": "rw_s",
8 "encoder_backbone": "efficientnetv2",
9 "pyramid_channels": [
10 24,
11 48,
12 64,
13 160
14 ],
15 "pyramid_dim": 32,
16 "use_spatial_attention": true,
17 "spatial_kernel_size": 11,
18 "dropout_rate": 0.15,
19 "input_channels": 1,
20 "output_channels": 3,
21 "patch_size": 256,
22 "trained_on": "nimbus_image_data",
23 "microscopy_type": "fluorescence",
24 "target": "biomolecular_condensates",
25 "style_modulation": true,
26 "dual_residual_blocks": true,
27 "multi_scale_upsampling": true
28}