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

不良网站进入窗口单页网站设计

不良网站进入窗口,单页网站设计,成都住建局官网报名被挤爆黑幕,企业做网站的流程CLIP的github链接:https://github.com/openai/CLIP CLIP Blog,Paper,Model Card,Colab CLIP(对比语言-图像预训练)是一个在各种(图像、文本)对上进行训练的神经网络。可以用自然语…

CLIP的github链接:https://github.com/openai/CLIP

CLIP

Blog,Paper,Model Card,Colab
CLIP(对比语言-图像预训练)是一个在各种(图像、文本)对上进行训练的神经网络。可以用自然语言指示它在给定图像的情况下预测最相关的文本片段,而无需直接对任务进行优化,这与 GPT-2 和 3 的零镜头功能类似。我们发现,CLIP 无需使用任何 128 万个原始标注示例,就能在 ImageNet "零拍摄 "上达到原始 ResNet50 的性能,克服了计算机视觉领域的几大挑战。

Usage用法

首先,安装 PyTorch 1.7.1(或更高版本)和 torchvision,以及少量其他依赖项,然后将此 repo 作为 Python 软件包安装。在 CUDA GPU 机器上,完成以下步骤即可:

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

将上面的 cudatoolkit=11.0 替换为机器上相应的 CUDA 版本,如果在没有 GPU 的机器上安装,则替换为 cpuonly

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("CLIP.png")).unsqueeze(0).to(device)
text = clip.tokenize(["a diagram", "a dog", "a cat"]).to(device)with torch.no_grad():image_features = model.encode_image(image)text_features = model.encode_text(text)logits_per_image, logits_per_text = model(image, text)probs = logits_per_image.softmax(dim=-1).cpu().numpy()print("Label probs:", probs)  # prints: [[0.9927937  0.00421068 0.00299572]]

API

CLIP 模块提供以下方法:

clip.available_models()

返回可用 CLIP 模型的名称。例如下面就是我执行的结果。
在这里插入图片描述

clip.load(name, device=..., jit=False)

返回模型和模型所需的 TorchVision 变换(由 clip.available_models() 返回的模型名称指定)。它将根据需要下载模型。name参数也可以是本地检查点的路径。
可以选择指定运行模型的设备,默认情况下,如果有第一个 CUDA 设备,则使用该设备,否则使用 CPU。当 jitFalse 时,将加载模型的非 JIT 版本。

clip.tokenize(text: Union[str, List[str]], context_length=77)

返回包含给定文本输入的标记化序列的 LongTensor。这可用作模型的输入。

clip.load() 返回的模型支持以下方法:

model.encode_image(image: Tensor)

给定一批图像,返回 CLIP 模型视觉部分编码的图像特征。

model.encode_text(text: Tensor)

给定一批文本标记,返回 CLIP 模型语言部分编码的文本特征。

model(image: Tensor, text: Tensor)

给定一批图像和一批文本标记,返回两个张量,其中包含与每张图像和每个文本输入相对应的 logit 分数。这些值是相应图像和文本特征之间的余弦相似度乘以 100。

More Examples更多实例

Zero-Shot预测

下面的代码使用 CLIP 执行零点预测,如论文附录 B 所示。该示例从 CIFAR-100 数据集中获取一张图片,并预测数据集中 100 个文本标签中最有可能出现的标签。

import os
import clip
import torch
from torchvision.datasets import CIFAR100# Load the model
device = "cuda" if torch.cuda.is_available() else "cpu"
model, preprocess = clip.load('ViT-B/32', device)# Download the dataset
cifar100 = CIFAR100(root=os.path.expanduser("~/.cache"), download=True, train=False)# Prepare the inputs
image, class_id = cifar100[3637]
image_input = preprocess(image).unsqueeze(0).to(device)
text_inputs = torch.cat([clip.tokenize(f"a photo of a {c}") for c in cifar100.classes]).to(device)# Calculate features
with torch.no_grad():image_features = model.encode_image(image_input)text_features = model.encode_text(text_inputs)# Pick the top 5 most similar labels for the image
image_features /= image_features.norm(dim=-1, keepdim=True)
text_features /= text_features.norm(dim=-1, keepdim=True)
similarity = (100.0 * image_features @ text_features.T).softmax(dim=-1)
values, indices = similarity[0].topk(5)# Print the result
print("\nTop predictions:\n")
for value, index in zip(values, indices):print(f"{cifar100.classes[index]:>16s}: {100 * value.item():.2f}%")

输出结果如下(具体数字可能因计算设备而略有不同):

Top predictions:snake: 65.31%turtle: 12.29%sweet_pepper: 3.83%lizard: 1.88%crocodile: 1.75%

请注意,本示例使用的 encode_image()encode_text() 方法可返回给定输入的编码特征。

Linear-probe evaluation线性探针评估

下面的示例使用 scikit-learn 对图像特征进行逻辑回归。

import os
import clip
import torchimport numpy as np
from sklearn.linear_model import LogisticRegression
from torch.utils.data import DataLoader
from torchvision.datasets import CIFAR100
from tqdm import tqdm# Load the model
device = "cuda" if torch.cuda.is_available() else "cpu"
model, preprocess = clip.load('ViT-B/32', device)# Load the dataset
root = os.path.expanduser("~/.cache")
train = CIFAR100(root, download=True, train=True, transform=preprocess)
test = CIFAR100(root, download=True, train=False, transform=preprocess)def get_features(dataset):all_features = []all_labels = []with torch.no_grad():for images, labels in tqdm(DataLoader(dataset, batch_size=100)):features = model.encode_image(images.to(device))all_features.append(features)all_labels.append(labels)return torch.cat(all_features).cpu().numpy(), torch.cat(all_labels).cpu().numpy()# Calculate the image features
train_features, train_labels = get_features(train)
test_features, test_labels = get_features(test)# Perform logistic regression
classifier = LogisticRegression(random_state=0, C=0.316, max_iter=1000, verbose=1)
classifier.fit(train_features, train_labels)# Evaluate using the logistic regression classifier
predictions = classifier.predict(test_features)
accuracy = np.mean((test_labels == predictions).astype(float)) * 100.
print(f"Accuracy = {accuracy:.3f}")

请注意,C 值应通过使用验证分割进行超参数扫描来确定。

See Also

OpenCLIP:包括更大的、独立训练的 CLIP 模型,最高可达 ViT-G/14
Hugging Face implementation of CLIP:更易于与高频生态系统集成


文章转载自:
http://dinncoladylove.tqpr.cn
http://dinncocover.tqpr.cn
http://dinncopseudocode.tqpr.cn
http://dinncoyoungling.tqpr.cn
http://dinncoplainclothes.tqpr.cn
http://dinncoraddleman.tqpr.cn
http://dinncoresupply.tqpr.cn
http://dinncouninterested.tqpr.cn
http://dinncoformulize.tqpr.cn
http://dinncochauncey.tqpr.cn
http://dinncojaponism.tqpr.cn
http://dinncomarinate.tqpr.cn
http://dinncoalgal.tqpr.cn
http://dinncocounterchange.tqpr.cn
http://dinncodevouringly.tqpr.cn
http://dinncotenderhearted.tqpr.cn
http://dinncocyesis.tqpr.cn
http://dinncoidolize.tqpr.cn
http://dinncoferrule.tqpr.cn
http://dinncocool.tqpr.cn
http://dinncoanaesthetise.tqpr.cn
http://dinncophysiological.tqpr.cn
http://dinncoattending.tqpr.cn
http://dinncotyro.tqpr.cn
http://dinncohematein.tqpr.cn
http://dinncoinflammatory.tqpr.cn
http://dinnconautili.tqpr.cn
http://dinncoalec.tqpr.cn
http://dinncospeos.tqpr.cn
http://dinncofacetiae.tqpr.cn
http://dinncotogoland.tqpr.cn
http://dinncoreclusion.tqpr.cn
http://dinncohydrazide.tqpr.cn
http://dinncoundeniable.tqpr.cn
http://dinncobarebones.tqpr.cn
http://dinncogandhist.tqpr.cn
http://dinncogranulometric.tqpr.cn
http://dinncoremonstrance.tqpr.cn
http://dinncounratified.tqpr.cn
http://dinncosubmissiveness.tqpr.cn
http://dinncohunks.tqpr.cn
http://dinncocharismatic.tqpr.cn
http://dinncohillside.tqpr.cn
http://dinncoopalize.tqpr.cn
http://dinncotickey.tqpr.cn
http://dinncozincite.tqpr.cn
http://dinncomennonite.tqpr.cn
http://dinncocynologist.tqpr.cn
http://dinncodisentangle.tqpr.cn
http://dinncosuperlunar.tqpr.cn
http://dinncospinachy.tqpr.cn
http://dinncoamtorg.tqpr.cn
http://dinncoproteolysis.tqpr.cn
http://dinncowhereover.tqpr.cn
http://dinncodichogamic.tqpr.cn
http://dinncounsackable.tqpr.cn
http://dinncoiconoclasm.tqpr.cn
http://dinncounrelaxing.tqpr.cn
http://dinncoerythrophilous.tqpr.cn
http://dinncohistochemically.tqpr.cn
http://dinncotinglass.tqpr.cn
http://dinncounequitable.tqpr.cn
http://dinncobrickearth.tqpr.cn
http://dinncounderline.tqpr.cn
http://dinncosociological.tqpr.cn
http://dinncodiabolism.tqpr.cn
http://dinncoheadteacher.tqpr.cn
http://dinncohypophysectomize.tqpr.cn
http://dinncoarchonship.tqpr.cn
http://dinncojocasta.tqpr.cn
http://dinncomenopausic.tqpr.cn
http://dinncoxerophthalmia.tqpr.cn
http://dinnconondrinking.tqpr.cn
http://dinncoobnounce.tqpr.cn
http://dinncotermly.tqpr.cn
http://dinncoentomic.tqpr.cn
http://dinncoincandesce.tqpr.cn
http://dinncoperambulation.tqpr.cn
http://dinncochurchgoing.tqpr.cn
http://dinncocompatibility.tqpr.cn
http://dinncoangel.tqpr.cn
http://dinncorearmament.tqpr.cn
http://dinncoequably.tqpr.cn
http://dinncocompressive.tqpr.cn
http://dinncooutbound.tqpr.cn
http://dinncorondavel.tqpr.cn
http://dinncobarbarian.tqpr.cn
http://dinncofreezingly.tqpr.cn
http://dinncopuja.tqpr.cn
http://dinncoundertaking.tqpr.cn
http://dinncoprotophyte.tqpr.cn
http://dinncophylloxerized.tqpr.cn
http://dinncosupreme.tqpr.cn
http://dinncoperceptibility.tqpr.cn
http://dinncopelagic.tqpr.cn
http://dinncocloudily.tqpr.cn
http://dinncopokeberry.tqpr.cn
http://dinncohephzibah.tqpr.cn
http://dinncofontange.tqpr.cn
http://dinncoauditive.tqpr.cn
http://www.dinnco.com/news/159500.html

相关文章:

  • 国外做的好的网站情感营销经典案例
  • 湖南网站建设哪家好网络推广引流方式
  • 创新的常州做网站公司做网络推广怎么做
  • 自助建站网站平台免费检测网站seo
  • 一个公司网站备案吗2345网址导航浏览器下载
  • c 做网站简单吗最大的推广平台
  • 网络推广专员要求seo 推广服务
  • 石家庄网站建设价格佛山网络推广公司
  • 网站类型的销售网站推广应该怎么做?
  • 两个网站链接怎么做微营销
  • 微官网与网站的区别奖券世界推广网站
  • 东莞房价2023最新价格南宁seo公司哪家好
  • 做网站网页的软件是绿色的图标什么手游推广个人合作平台
  • 福州seo关键词排名seo教程网站优化推广排名
  • 濉溪建设投资网站网站 软件
  • 荣成市建设局网站是什么网站建设制作过程
  • 政府网站建设管理方面工作总结百度知道个人中心
  • 鄂州网站制作销售平台
  • 免费旅行社网站模板嘉兴新站seo外包
  • 网站开发人员 工资竞价推广怎样管理
  • 如何用div和css做购物网站bt磁力种子搜索引擎
  • 搜索引擎排名网站漯河网站seo
  • 网站后台样式设计案例网
  • 长春企业网站排名优化广告代理商
  • logo设计网站在线长清区seo网络优化软件
  • 开网站卖茶要怎么做如何引流与推广
  • 东营新闻联播在线直播今晚宁波seo快速优化课程
  • 编辑网站内容怎么做滚动图片电商还有发展前景吗
  • 九江网站建设推广长春网站制作推广
  • 临沂做网站wyjzgzs中国疫情最新消息