Skip to content

319 add bioclip training - #320

Open
Raindrop182 wants to merge 10 commits into
devfrom
319-add-bioclip-training
Open

319 add bioclip training#320
Raindrop182 wants to merge 10 commits into
devfrom
319-add-bioclip-training

Conversation

@Raindrop182

Copy link
Copy Markdown
Collaborator

Integrates BioClip2 into the model training pipeline

Relies on features from #316 and #318 for proper functionality

  • Adds bioclip2 architecture to model_architecture.py
  • Changes logic of applying transforms in TrainGenerator so bioclip-specific transforms can be applied
    • Adds function get_model_transforms that returns either default transforms or bioclip specific transforms
    • Adds architecture argument to TrainGenerator and train_dataloader
  • Updates load_classifier, save_classifier, load_classifier_checkpoint, and frozen epoch unfreezing logic for bioclip (especially since we only train the LoRA weights in bioclip)

Does not integrate BioClip2 into classification pipeline

Closes #319

@Raindrop182
Raindrop182 marked this pull request as draft June 30, 2026 18:14
@Raindrop182
Raindrop182 force-pushed the 319-add-bioclip-training branch from 0d63e56 to c21cb91 Compare July 6, 2026 15:53
@Raindrop182
Raindrop182 force-pushed the 319-add-bioclip-training branch from c21cb91 to 025982e Compare July 6, 2026 16:00
@Raindrop182
Raindrop182 marked this pull request as ready for review July 6, 2026 16:07
@Raindrop182
Raindrop182 requested a review from tkswanson July 6, 2026 16:07
Comment thread src/animl/generator.py Outdated
torchvision.transforms.v2.Compose: Complete preprocessing pipeline.
"""
if architecture == "bioclip_2":
assert resize_width == 224 and resize_height == 224, "BioClip only accepts image dimensions of 224x224"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's the case, maybe we force the resize width and height to be 224 instead of depending on the user to get it right

"""
import open_clip
from peft import LoraConfig, get_peft_model
import torch

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should add these to the package dependencies

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like you also need huggingface_hub and a specific version of transformers to be compatible

@Raindrop182

Copy link
Copy Markdown
Collaborator Author
  • Changed get_model_transforms so it forces the resize width and height for bioclip to be 224x224 (with a printed warning if it differs from what the user inputted)
  • Added huggingface_hub, open_clip_torch, peft, safetensors, and transformers to pyproject.toml dependencies.

@Raindrop182
Raindrop182 requested a review from tkswanson July 6, 2026 23:17
Comment thread src/animl/train.py
checkpoint = {'model': model.state_dict(),
'stats': stats}
# save optimizer and scheduler state dicts if they are provided
if model.__class__.__name__=="BioClip":

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do all models we use have this attribute so that this check will not error out?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! all of them have this attribute and it returns the name of the class in model_architecture (so 'EfficientNet', 'ConvNeXtBase', or 'BioClip')

Comment thread src/animl/generator.py Outdated
return img_tensor, [file_path], [frame], torch.tensor([(height, width)])


def get_model_transforms(resize_height, resize_width, architecture=None):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be a helper function, add an underscore at the front and remove from the init please

@Raindrop182
Raindrop182 requested a review from tkswanson July 7, 2026 18:06
@tkswanson

Copy link
Copy Markdown
Member

If we only need the architecture param for bioclip, maybe we want a separate function that creates a dataloader specficially for bioclip that includes the transforms instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants