Giter Club home page Giter Club logo

clip-image-classification's Introduction

CLIP-Image-Classification

Use

!git clone https://github.com/kingchloexx/CLIP-Image-Classification # if not in a notebook, run in console (w/o the "!")
import os
os.chdir("Image-Classification")

from classify import load, classify, encode

filename = "../input.jpg"

load_categories = "imagenet"

print("loading categories")
load(load_categories)

print("classifying")
print(classify(filename))

load

load("imagenet") #imagenet categories
load("pokemon") #loads a list of 721 pokemon names as categories
load("dog vs cat") #dog and cat as categories
load("emojis") #emojis :)
load(["banana", "elephant", "monkey"]) #any custom words in a list will do as well

classify

classify(filename) #returns the highest scoring class
classify(filename, return_raw=True) #returns the scores for all the classes (cosine_similarity)

encode

this will return CLIP's raw encoding of an image or text if you need it.

encode("input.jpg") #encode based on filename, it'll be detected if it ends w/ png, jpg, or jpeg
encode("an image of a flower") #encode based on text

Examples

Classify an image: Open In Colab

Search within an image: Open In Colab

Dependencies

I made it as simple as I could lmao, first you've gotta install the dependencies which can be done with this block of text if you're using Google Colab:

import subprocess

CUDA_version = [s for s in subprocess.check_output(["nvcc", "--version"]).decode("UTF-8").split(", ") if s.startswith("release")][0].split(" ")[-1]
print("CUDA version:", CUDA_version)

if CUDA_version == "10.0":
    torch_version_suffix = "+cu100"
elif CUDA_version == "10.1":
    torch_version_suffix = "+cu101"
elif CUDA_version == "10.2":
    torch_version_suffix = ""
else:
    torch_version_suffix = "+cu110"
!git clone https://github.com/kingchloexx/CLIP-Image-Classification
! pip install torch==1.7.1{torch_version_suffix} torchvision==0.8.2{torch_version_suffix} -f https://download.pytorch.org/whl/torch_stable.html ftfy regex
!pip install ftfy

If you're using a conda environment (outside of google colab), make sure you have an nvidea graphics card, once you've conda activateed your environment, use conda install cudatoolkit and at the time of writing this, the command for installing the correct torch version would be

pip install torch==1.7.1 torchvision==0.8.2 -f https://download.pytorch.org/whl/torch_stable.html ftfy regex

if you try the script and it says there are dependencies missing, usually a pip install [dependency name] will fix it

๐Ÿ‘ - Chloe

clip-image-classification's People

Contributors

aicrumb avatar goocharea avatar

Stargazers

 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.