当前位置: 首页 > news >正文

网站建设最新教程视频网站推广教程

网站建设最新教程视频,网站推广教程,互联网网站模块,企业微信登录网页版OpenAI——CLIPs(打通NLP与CV) Open AI在2021年1月份发布Contrastive Language-Image Pre-training(CLIP),基于对比文本-图像对对比学习的多模态模型,通过图像和它对应的文本描述对比学习,模型能够学习到文本-图像对的匹配关系。它开源、多模态、zero-s…

OpenAI——CLIPs(打通NLP与CV)

Open AI在2021年1月份发布Contrastive Language-Image Pre-training(CLIP),基于对比文本-图像对对比学习的多模态模型,通过图像和它对应的文本描述对比学习,模型能够学习到文本-图像对的匹配关系。它开源、多模态、zero-shot、few-shot、监督训练均可。
原文原理图:
在这里插入图片描述
原文算法思想伪代码:
在这里插入图片描述

OpenAI CLIP 原项目:

https://github.com/openai/CLIP

使用

(一)原版
安装:

$ conda install --yes -c pytorch pytorch=1.7.1 torchvision cudatoolkit=11.0
$ pip install ftfy regex tqdm
$ pip install git+https://github.com/openai/CLIP.git

当然没有GPU和cuda,直接CPU也可以
源码:

import torch
import clip
from PIL import Imagedevice = "cuda" if torch.cuda.is_available() else "cpu"
model, preprocess = clip.load("ViT-B/32", device=device)image = preprocess(Image.open("cat.png")).unsqueeze(0).to(device)  # CLIP.png为本文中图一,即CLIP的流程图
text = clip.tokenize( ["cat in basket", "python", "a cute cat","pytorch","code of CLIP","code of pytorch ","code"]).to(device)  # 将这三句话向量化with torch.no_grad():image_features = model.encode_image(image) # 将图片进行编码text_features = model.encode_text(text)    # 将文本进行编码# print("image_features shape:",image_features.shape,image_features.size(),image_features.ndim)# print("text_features shape:", text_features.shape)logits_per_image, logits_per_text = model(image, text)# print("logits_per_image shape:",logits_per_image.shape)# print("logits_per_text shape:", logits_per_text.shape)probs = logits_per_image.softmax(dim=-1).cpu().numpy()print("Label probs:", probs)  # prints: [[0.9927937  0.00421068 0.00299572]] # 图片"CLIP.png",text["a diagram", "a dog", "a cat"] 对应"a diagram"的概率为0.9927937####(2)接前:矩阵相乘分类
import pandas as pd
with torch.no_grad():score = []image_features = model.encode_image(image) # 将图片进行编码image_features /= image_features.norm(dim=-1, keepdim=True)text_features = model.encode_text(text)    # 将文本进行编码text_features /= text_features.norm(dim=-1, keepdim=True)# texts = ["cat in basket", "python", "a cute cat","pytorch","code of CLIP","code of pytorch ","code"]texts = ["cat in basket", "python", "a cat","pytorch","code","pytorch code"]for text in texts:textp = clip.tokenize(text)# 问题文本编码textp_embeddings = model.encode_text(textp)textp_embeddings /= textp_embeddings.norm(dim=-1, keepdim=True)# 计算图片和问题之间的匹配分数(矩阵相乘)sc = float((image_features  @ textp_embeddings.T).cpu().numpy())score.append(sc)print(pd.DataFrame({'texts': texts, 'score': score}).sort_values('score', ascending=False))print('')print('-------------------------')print('')

(二)transformer库版本
Transformers 库的基本使用:
https://blog.csdn.net/benzhujie1245com/article/details/125279229
安装:

pip install transformers

CLIP源码:

####基本用法二:利用transformer库
from PIL import Image
from transformers import CLIPProcessor,CLIPModelmodel = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
#这里加入自己图片的地址就行
image = Image.open('cat.png')
#这里加入类别的标签类别
text = ["cat in basket", "python", "a cute cat","pytorch","code of CLIP","code of pytorch ","code"]
inputs = processor(text=text,images = image,return_tensors="pt",padding=True)
outputs = model(**inputs)
logits_per_image = outputs.logits_per_image
probs = logits_per_image.softmax(dim=1)for i in range(len(text)):print(text[i],":",probs[0][i])

输入图片:
在这里插入图片描述
结果:
在这里插入图片描述

但是CLIP对于有些比较抽象的图片或任务效果并不一定好,例如:
图片code.png:
在这里插入图片描述

PLUS:

但是CLIP仍是一项AI重要突破,尤其是当它应用到CV相关任务时,例如风格换装,CLIPBERT,CLIP4Clip,CLIP2Video,CLIPTV、image caption等等。

http://www.dt0577.cn/news/18553.html

相关文章:

  • durable创建网站营销100个引流方案
  • 开发一款app大概多少钱seo关键词排名技术
  • 专业营销软件网站建设广告投放是什么工作
  • p2p网站开发思路方案互联网推广广告
  • 如何用ps做网站网页最火的网络推广平台
  • 上海网站建设多少钱宁波seo外包推广渠道
  • 上海营销平台网站建设微商如何引流与推广
  • 佛山购物网站建设百度云盘网官网
  • 常州疫情最新消息今天封城了seo推广培训
  • 网站费用标准游戏推广员好做吗
  • 敲代码做网站多少钱爱站权重
  • 建设一个网站主要受哪些因素的影响因素百度资源提交
  • 南通做网站优化谷歌排名推广公司
  • 有域名如何自己制作网站百度云服务器官网
  • 做php网站需要什么软件2345网址大全浏览器
  • 郴州网站建设培训代运营网店公司
  • 凡科网做网站收费吗运营培训
  • 做盗版网站 国外服务器百度应用商店官网
  • 微信分享接口网站开发关键词三年级
  • 平面设计如何接单seo是什么意思seo是什么职位
  • WordPress怎么修改网站登陆地址seo教程自学网
  • 效果图外包seo是什么专业
  • 专用车网站建设哪家好seo做什么网站赚钱
  • 建设银行手机银行网站用户名seo站长工具
  • 企业如何建官方网站如何线上推广引流
  • 昆明app制作湖州网站seo
  • wordpress编辑作者投稿者英文seo怎么做排名
  • 微网站的链接怎么做的站长工具忘忧草社区
  • 南山模板网站建设公司网络营销的用户创造价值
  • 做网站大概多少进入百度一下官网