Code Monkey home page Code Monkey logo

zero-shot-prediction-plugin's Introduction

Zero Shot Prediction Plugin

zero_shot_owlvit_example

This plugin allows you to perform zero-shot prediction on your dataset for the following tasks:

  • Image Classification
  • Object Detection
  • Instance Segmentation
  • Semantic Segmentation

Given a list of label classes, which you can input either manually, separated by commas, or by uploading a text file, the plugin will perform zero-shot prediction on your dataset for the specified task and add the results to the dataset under a new field, which you can specify.

Updates

  • 2023-10-27: Added support for MetaCLIP for image classification
  • 2023-10-20: Added support for AltCLIP and Align for image classification and GroupViT for semantic segmentation

Models

Built-in Models

As a starting point, this plugin comes with at least one zero-shot model per task. These are:

Most of the models used are from the HuggingFace Transformers library, and CLIP and SAM models are from the FiftyOne Model Zoo

Noteโ€” For SAM you will need to have Facebook's segment-anything library installed.

Adding Your Own Models

You can see the implementations for all of these models in the following files:

  • classification.py
  • detection.py
  • instance_segmentation.py
  • semantic_segmentation.py

These models are "registered" via dictionaries in each file. In classification.py, for example, the dictionary is:

CLASSIFICATION_MODELS = {
    "CLIP": {
        "activator": CLIP_activator,
        "model": CLIPZeroShotModel,
        "name": "CLIP",
    },
    "AltCLIP": {
        "activator": AltCLIP_activator,
        "model": AltCLIPZeroShotModel,
        "name": "AltCLIP",
    },
    "MetaCLIP-H14": {
        "activator": MetaCLIP_activator,
        "model": MetaCLIPZeroShotModel,
        "name": "MetaCLIP-H14",
    },
    "Align": {
        "activator": Align_activator,
        "model": AlignZeroShotModel,
        "name": "Align",
    },
}

The activator checks the environment to see if the model is available, and the model is a fiftyone.core.models.Model object that is instantiated with the model name and the task. The name is the name of the model that will be displayed in the dropdown menu in the plugin.

If you want to add your own model, you can add it to the dictionary in the corresponding file. For example, if you want to add a new image classification model, you can add it to the CLASSIFICATION_MODELS dictionary in classification.py:

CLASSIFICATION_MODELS = {
    "CLIP": {
        "activator": CLIP_activator,
        "model": CLIPZeroShotModel,
        "name": "CLIP",
    },
    ..., # other models
    "My Model": {
        "activator": my_model_activator,
        "model": my_model,
        "name": "My Model",
    }
}

๐Ÿ’ก You need to implement the activator and model functions for your model. The activator should check the environment to see if the model is available, and the model should be a fiftyone.core.models.Model object that is instantiated with the model name and the task.

Installation

fiftyone plugins download https://github.com/jacobmarks/zero-shot-prediction-plugin

If you want to use AltCLIP, Align, Owl-ViT, CLIPSeg, or GroupViT, you will also need to install the transformers library:

pip install transformers

If you want to use SAM, you will also need to install the segment-anything library:

pip install git+https://github.com/facebookresearch/segment-anything.git

Usage

All of the operators in this plugin can be run in delegated execution mode. This means that instead of waiting for the operator to finish, you schedule the operation to be performed separately. This is useful for long-running operations, such as performing inference on a large dataset.

Once you have pressed the Schedule button for the operator, you will be able to see the job from the command line using FiftyOne's command line interface:

fiftyone delegated list

will show you the status of all delegated operations.

To launch a service which runs the operation, as well as any other delegated operations that have been scheduled, run:

fiftyone delegated launch

Once the operation has completed, you can view the results in the App (upon refresh).

After the operation completes, you can also clean up your list of delegated operations by running:

fiftyone delegated cleanup -s COMPLETED

Operators

zero_shot_predict

  • Select the task you want to perform zero-shot prediction on (image classification, object detection, instance segmentation, or semantic segmentation), and the field you want to add the results to.

zero_shot_classify

  • Perform zero-shot image classification on your dataset

zero_shot_detect

  • Perform zero-shot object detection on your dataset

zero_shot_instance_segment

  • Perform zero-shot instance segmentation on your dataset

zero_shot_semantic_segment

  • Perform zero-shot semantic segmentation on your dataset

zero-shot-prediction-plugin's People

Contributors

jacobmarks 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.