Skip to content

Define python level abstraction for a Bundle #5821

Open

Description

@Nic-Ma

Is your feature request related to a problem? Please describe.
Currently, we developed many bundles in the model-zoo repo and developed the ConfigParser to load configs.
But actually we don't have a clear definition about what a Bundle is in the python level.
It would be nice to define the Bundle class to represent a bundle and enable users to follow & define their customized bundle structure, and provide the APIs for other applications to easily load and handle a bundle, like MONAI Label, MONAI FL, etc.
Several draft steps to do:

  • Develop BundleWorkflow interface and implement config-based subclass, so bundle can be implemented with JSON/YAML config or python code, just need to follow the interface.
  • How to expose the CLI entry and args for customized BYOCBundleWorkflow in bundle/scripts/.
  • Update FL monai algo to use new workflow.
  • Update MONAI Label to use new bundle workflow. #6720
  • Add tutorial to show how to develop a new pure python-based bundle.
  • Develop Bundle interface for the whole bundle, mainly about folder structure, files, download, etc.

Activity

  1. self-assigned this
    on Jan 6, 2023
  2. Nic-Ma commented on Jan 6, 2023

    @Nic-Ma
    ContributorAuthor

    CC @wyli @SachidanandAlle for more discussion.

    Thanks.

  3. added this to the Bundle class [P1 v1.2] milestone on Feb 6, 2023
  4. reopened this on Mar 16, 2023
  5. added this to MONAI v1.3 and removed this from MONAI v1.2on Jun 24, 2023
  6. moved this to Bundle TODO in MONAI v1.3on Jun 30, 2023
  7. vikashg commented on Jul 7, 2023

    @vikashg
    Collaborator

    Hi @Nic-Ma
    Thanks for starting this post. As I mentioned that we need to think of usability of bundles from 2 different angles

    1. Ease of use from an end-user perspective
    2. Ease of building a MONAI Bundle

    From an end-user perspective, if the monai model weights should be available from the python script (as they are for pytorch and keras) without explicitly downloading the model. For example

    import torchvision
    from torchvision.models.detection.faster_rcnn import FastRCNNPredictor
    from torchvision.models.detection.mask_rcnn import MaskRCNNPredictor
    

    or for keras

    base_model = keras.applications.Xception(
        weights="imagenet",  # Load weights pre-trained on ImageNet.
        input_shape=(150, 150, 3),
        include_top=False,
    )  # Do not include the ImageNet classifier at the top.
    
    # Freeze the base_model
    base_model.trainable = False
    

    It will be nice to have similar interface for MONAI models. As far as I understand and used, we can create a model architecture in the similar way in MONAI, but they are not populated with model weights. We looked at loading torchvision models and fine-tuning their model weights in this pull request last year with @wyli.

    So maybe if we can reach a place where we can load the model weights as follows

    from monai.model_zoo import brats_tumor_segmentation_model
    model = brats_tumor_segmentation_model.load_weights(dataset="Brats_challenge_2020")
    

    At this point, the user might want to query the model I/O for the purposes of fine-tuning. A user should be able to call something like

    print("Model Info")
    print(model.info)
    print("Model I/O Config")
    print(model.config.io)
    

    which should produce an output

    Model Info
    Model Name: Brats Tumor Segmentation Model
    Dataset model is trained on: Brats Challenge 20
    Last updated date: 3 July 2021
    Author: xxxx xxxx
    
    Model I/O Config
    Input Shape: [3, 256, 256, 256]
    Intensity Range for input: [0, 1]
    
    Output Labels: [4, 256, 256, 256] 
    Produces Binary label for each class.
    

    The user should be able to peel the last layer and attach a different layer for fine-tuning purposes.

  8. 1 remaining item

  9. surajpaib commented on Aug 7, 2023

    @surajpaib
    Contributor

    Hi @wyli, do you think something like the above would be of interest?

  10. wyli commented on Aug 8, 2023

    @wyli
    Contributor

    yes, that's a good point, thanks for the comments @surajpaib, @KumoLiu is designing a new pythonic user experience https://docs.google.com/presentation/d/1z3rVJWX7LMcyTrCH-K9dFehBuEksFj0f8bobmJ-DJPA will let you know when a prototype is ready

  11. surajpaib commented on Aug 8, 2023

    @surajpaib
    Contributor

    Thank you very much for sharing this @wyli

    This looks very promising @KumoLiu. Let me know if you would like any help with testing

  12. self-assigned this
    on Aug 11, 2023
  13. added this to MONAI v1.4 and removed this from MONAI v1.3on Oct 13, 2023
  14. moved this to Todo in MONAI v1.4on Oct 13, 2023
  15. KumoLiu commented on Oct 20, 2023

    @KumoLiu
    Contributor

    E.g:
    from monai.networks.nets import densenet121
    model = densenet121(pretrained="pathology_nuclei_classification") # pretrained / weights
    Where the model now loads pre-trained weights from the pathology_nuclei_classification bundle.

    Hi @surajpaib, given your comment above, we were able to support getting instantiated nets directly from a bundle in the 1.3 release, which can be used directly in the existing pipeline.

    from monai.bundle import load
    
    model = load("pathology_nuclei_classification", bundle_dir="/workspace/", return_state_dict=False)
    

    Feel free to share the feedback.

  16. moved this from Todo to No status in MONAI v1.4on Nov 3, 2023
  17. added a commit that references this issue on Apr 15, 2024
    c696773
  18. added this to MONAI v1.5 and removed this from MONAI v1.4on Sep 20, 2024
  19. moved this to In progress in MONAI v1.5on Sep 20, 2024
  20. ericspod commented on Jun 27, 2025

    @ericspod
    Member

    Hi all, is this still being worked on? It currently is marked as such in our project but we should keep track of anything falling behind.

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

Metadata

Metadata

Type

No type

Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions