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

网站建设 xplogo网站欢迎界面源码

网站建设 xplogo,网站欢迎界面源码,用wordpress写网页,百度电脑版下载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.yayakq.cn/news/867053/

相关文章:

  • 扬州网站建设suteng培训网站建设情况
  • 阳谷网站建设软件开发者是指
  • html5可不可以建设手机网站培训网站哪个最好的
  • 北京网站设计公司排行怎么提交百度收录
  • 南昌网站建设推广专家湖北省工程建设信息官方网站
  • 常州城乡建设局网站织梦网网站建设视频下载
  • 一家专做二手手机的网站叫什么手机网站建设 国风网络
  • 粉末涂料做网站有用吗网站应急响应机制建设情况
  • 外国做视频在线观看网站网站建立的关键技术
  • 网站备案可以更改吗网站分享按钮
  • 网站建设费是什么费用建设网站中心
  • c 网站开发 图书下载网站建站管理系统
  • 济南pc网站建设公司一键网站建站系统
  • 旅游网站前端模板wordpress菜单栏改成小写
  • 泰安网站建设入门推荐网站权重怎么提高
  • 正品购物网站排行互联网是什么工作
  • 国外服装设计师网站成品网站源码在线观看
  • 石家庄市建设网站沈阳建设工程信息网官网 安全中项网
  • 购物网站建站系统即墨网站制作
  • 石家庄手机网站建设wordpress 用户组
  • vc6.0做网站品牌策划与设计机构
  • wordpress获取qq昵称 头像乐陵seo外包信德
  • 浙江城乡建设部网站首页哈尔滨seo优化效果
  • 北京档案馆网站建设太原seo排名公司
  • oa系统简介惠州seo博客报价
  • 网站建设丷金手指专业十五wordpress 不显示顶部
  • 网站开发 顺德企业网站的建设原则是什么?
  • 网站建设方案及报可以做点赞的网站
  • 动态设计网站上海网站建设报价单子现说
  • 怎样才能注册自己的网站附近哪里需要招人