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

网站建设最新教程视频seo是干啥的

网站建设最新教程视频,seo是干啥的,国内设计师个人网页,网站托管团队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.yidumall.com/news/38149.html

相关文章:

  • 承德做网站的公司百度登录
  • 温州网站建设公司排名搜索引擎排名优化程序
  • 孝感门户网优化公司结构
  • 酷黑网站网络营销推广方式案例
  • 百度wap网站建设国外引擎搜索
  • 中国十大知名网站建设最好的搜索引擎排名
  • 淄川政府网站建设公司石家庄最新疫情最新消息
  • 北京住建委网站开发适配问题seo网站优化软件价格
  • 最新免费下载ppt模板网站江苏网页定制
  • 用软件做模板下载网站360安全网址
  • 蚌埠市做网站自己建网站要花多少钱
  • 网站开发的广告seo推广有哪些公司
  • 网站制作是怎么做的游戏推广可以做吗
  • 网站模板后台怎么做国内最开放的浏览器
  • 文员做任务赚钱的网站中国疫情今天最新消息
  • 设计师装修网seo技术培训教程视频
  • 郴州在哪里百度搜索排名优化哪家好
  • wordpress网站被黑百度关键词工具入口
  • 台州做网站电话网站推广的常用途径有哪些
  • 美食网站建设规划书需求分析临沂seo建站
  • 怎么找到仿牌外贸出口公司的网站网页设计怎么做
  • bilibili推广网站新网站如何快速收录
  • 做网站的企划书长尾关键词挖掘爱站网
  • 品牌网站设计步骤个人能接广告联盟吗
  • 网站认证免费成都seo的方法
  • wordpress相册插件nextgen gallery网站优化排名易下拉稳定
  • wordpress 评论 评分成都网站改版优化
  • 山东滨州网站建设公司高级seo是什么职位
  • 石家庄网站制作方案上海aso苹果关键词优化
  • 施工企业管理制度完整版外贸网站推广seo