Code Monkey home page Code Monkey logo

flash-fiftyone_component's Introduction

A Lightning component to serve a Flash Task using FiftyOne


Install

Use these instructions to install:

git clone https://github.com/Lightning-AI/LAI-flash-fiftyone-Component.git
cd LAI-flash-fiftyone-Component
pip install -r requirements.txt
pip install -e .

Use the component

Note:

  1. We have a cache_calls argument to the component, this allows you to only run it only once as long as same arguments are passed to the run method of FlashFiftyOne class.
  2. This component currently only supports task as image_classification. Please make sure to pass "task": "image_classification" in the run_dict as shown below.

To run the code below, copy the code and save it in a file app.py. Run the component using lightning run app app.py. If you want to run the app on cloud, do: lightning run app app.py --cloud.

import lightning as L

from flash_fiftyone import FlashFiftyOne


class FiftyOneComponent(L.LightningFlow):
    def __init__(self):
        super().__init__()
        self.flash_fiftyone = FlashFiftyOne(cache_calls=True)
        self.layout = []

    def run(self):
        # Pass your data here:
        # `task` can be either image_classification or text_classification
        # `url` needs to be a downloadable link for your dataset
        # Depending on the task you've chosen, pass the arguments to the task class
        #   from Lightning Flash in the `data_config` dict
        # `checkpoint_path` can either be a local path to the checkpoint or any hosted link
        run_dict = {
            "task": "image_classification",
            "url": "https://pl-flash-data.s3.amazonaws.com/hymenoptera_data.zip",
            "data_config": {
                "target": "from_folders",
                "train_folder": "hymenoptera_data/train/",
                "val_folder": "hymenoptera_data/val/",
            },
            "checkpoint_path": "https://flash-weights.s3.amazonaws.com/0.7.0/image_classification_model.pt",
        }

        self.flash_fiftyone.run(
            task=run_dict["task"],
            url=run_dict["url"],
            data_config=run_dict["data_config"],
            checkpoint_path=run_dict["checkpoint_path"],
        )

    def configure_layout(self):
        # Use flash_fiftyone.ready flag - which will be `True` when fiftyone server is ready and the task is served!
        if self.flash_fiftyone.ready and not self.layout:
            self.layout.append(
                {
                    "name": "Predictions Explorer (FiftyOne)",
                    "content": self.flash_fiftyone,
                },
            )
        return self.layout


app = L.LightningApp(FiftyOneComponent(), debug=True)

flash-fiftyone_component's People

Contributors

borda avatar krshrimali avatar pre-commit-ci[bot] avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.