Giter Site home page Giter Site logo

cav_mae_model's Introduction

cav_mae_model

please refer to the original cav_mae repository

How to use it:

Install

pip install git+https://github.com/audio-visual/cav_mae_model.git

Get features

import torch
import cav_mae
from PIL import Image

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

model = cav_mae.load('ckpt_path').to(device) 

img_size = 224
audio_length = 512 # 5 seconds, should match with the audio_length in model checkpoint
n_mels = 128

# audio_preprocess only used for eval mode,for train mode, you should manually mask it
visual_preprocess, audio_preprocess = cav_mae.visual_preprocess(img_size), cav_mae.audio_preprocess(audio_length,n_mels)

image = visual_preprocess(Image.open('test.png')).unsqueeze(0).to(device) # 1,3,img_size,img_size
audio = audio_preprocess('test.wav').unsqueeze(0).to(device) # 1,audio_length,n_mels

# you should manually change the model mode
model.eval()

# audio_emb: [1,256,768]
# img_emb: [1,196,768]
audio_emb, img_emb = model.module.forward_feat(audio, image)

Compute similarity

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

model = cav_mae.load('ckpt_path').to(device) 

img_size = 224


visual_preprocess, audio_preprocess = cav_mae.visual_preprocess(img_size), cav_mae.audio_preprocess()

image = visual_preprocess(Image.open('test.png')).unsqueeze(0).to(device) # 1,3,img_size,img_size
audio = audio_preprocess('test.wav').unsqueeze(0).to(device) # 1,audio_length,n_mels

cav_mae.compute_audio_image_similarity(model, audio, image)

cav_mae_model's People

Contributors

audio-visual avatar

Watchers

Kostas Georgiou 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.