Git Product home page Git Product logo

cupl's Introduction

Generating customized prompts for zero-shot image classification

This repository contains code to:

  1. Generate your own customized prompts using GPT-3
  2. Classify ImageNet using your own (or provided) generated customized prompts

Python version 3.8.9 -- Additional requirements can be found in requirements.txt

โš ๏ธ Currently this repository only supports the ImageNet dataset. Additional datasets coming soon.

alt text

Generating prompts with GPT-3

To generate prompts, run the below command:

python generate_image_prompts.py

Additionally, in that file you will need to specify your own openai beta API key (https://beta.openai.com/) and the name of the json file where you wish to write your generated prompts. You can adjust this in the following lines of the above file:

openai.api_key = "INSERT YOUR OPENAI BETA API KEY"
json_name = "json_name.json"

Finally, you can specify desires hyperparameters for generation including thee number of sentences you wish to generate (currently 10), temperature (currently .99), if you wish to stop after generating a given token ("."), and max tokens (currently 50). Additional documentation can be found here: https://beta.openai.com/docs/api-reference/completions/create.

openai.Completion.create(
	engine="text-davinci-002",
	prompt=curr_prompt,
	temperature=.99,
	max_tokens = 50,
	n=10,
	stop="."
	)

Zero-shot Image Classification with CLIP

Classify ImageNet using these prompts run the below command:

python classify_imagenet.py

Additionally, you will need to specify the path to ImageNet on your machine as well as the path to your (or provided) generated prompts. You can do that in the beginning of the above file in the following two lines of code:

PATH_TO_IMAGENET = "../val"
PATH_TO_PROMPTS = "./imagenet_prompts/CuPL_image_prompts.json"

cupl's People

Contributors

greaterchen avatar sarahpratt 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.