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

创建网站无法播放视频企业网站建设排名口碑

创建网站无法播放视频,企业网站建设排名口碑,建筑工程有限责任公司,网站建设十大公司文章目录 前言一、使用 TVMC二、获得模型三、将 ONNX 模型编译到 TVM 运行时中四、TVMC 从编译的模块中运行模型4.1、输入预处理4.2 运行已编译的模块4.3 输出后处理 前言 在本节中#xff0c;将使用 TVMC#xff0c;即 TVM 命令行驱动程序。TVMC 工具#xff0c;它暴露了 T… 文章目录 前言一、使用 TVMC二、获得模型三、将 ONNX 模型编译到 TVM 运行时中四、TVMC 从编译的模块中运行模型4.1、输入预处理4.2 运行已编译的模块4.3 输出后处理 前言 在本节中将使用 TVMC即 TVM 命令行驱动程序。TVMC 工具它暴露了 TVM 的功能如 auto-tuning、编译、profiling 和通过命令行界面执行模型。 在完成本节内容后将使用 TVMC 来完成以下任务 为 TVM 运行时编译预训练 ResNet-50 v2 模型。通过编译后的模型运行真实图像并解释输出和模型的性能。使用 TVM 在 CPU 上调优模型。使用 TVM 收集的调优数据重新编译优化模型。通过优化后的模型运行图像并比较输出和模型的性能。 一、使用 TVMC TVMC 是 Python 应用程序是 TVM Python 软件包的一部分。当你使用 Python 包安装 TVM 时你将得到 TVMC 作为命令行应用程序名为 tvmc。这个命令的位置将取决于你的平台和安装方法。   另外如果你在 $PYTHONPATH 上将 TVM 作为 Python 模块你可以通过可执行的 python 模块 python -m tvm.driver.tvmc 访问命令行驱动功能。   为简单起见将提到 TVMC 命令行使用 tvmc options但同样的结果可以用 python -m tvm.driver.tvmc options。 可以使用帮助页面查看: !python -m tvm.driver.tvmc --helpusage: tvmc [--config CONFIG] [-v] [--version] [-h]{micro,run,tune,compile} ...TVM compiler driveroptions:--config CONFIG configuration json file-v, --verbose increase verbosity--version print the version and exit-h, --help show this help message and exit.commands:{micro,run,tune,compile}micro select micro context.run run a compiled moduletune auto-tune a modelcompile compile a model.TVMC - TVM driver command-line interfacetvmc 可用的 TVM 的主要功能来自子命令 compile 和 run以及 tune。要了解某个子命令下的具体选项使用 tvmc subcommand --help。将在本教程中逐一介绍这些命令但首先需要下载预训练模型来使用。 二、获得模型 使用 ResNet-50 v2。ResNet-50 是卷积神经网络有 50 层深度设计用于图像分类。将使用的模型已经在超过一百万张图片上进行了预训练有 1000 种不同的分类。该网络输入图像大小为 224x224。如果你有兴趣探究更多关于 ResNet-50 模型的结构建议下载 Netron它免费提供的 ML 模型查看器。 在本文中将使用 ONNX 格式的模型。 !wget https://github.com/onnx/models/raw/main/vision/classification/resnet/model/resnet50-v2-7.onnx--2022-04-26 13:07:52-- https://github.com/onnx/models/raw/main/vision/classification/resnet/model/resnet50-v2-7.onnx Resolving github.com (github.com)... 20.205.243.166 Connecting to github.com (github.com)|20.205.243.166|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://media.githubusercontent.com/media/onnx/models/main/vision/classification/resnet/model/resnet50-v2-7.onnx [following] --2022-04-26 13:07:53-- https://media.githubusercontent.com/media/onnx/models/main/vision/classification/resnet/model/resnet50-v2-7.onnx Resolving media.githubusercontent.com (media.githubusercontent.com)... 185.199.111.133, 185.199.108.133, 185.199.110.133, ... Connecting to media.githubusercontent.com (media.githubusercontent.com)|185.199.111.133|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 102442450 (98M) [application/octet-stream] Saving to: ‘resnet50-v2-7.onnx’resnet50-v2-7.onnx 100%[] 97.70M 4.51MB/s in 25s 2022-04-26 13:08:27 (3.89 MB/s) - ‘resnet50-v2-7.onnx’ saved [102442450/102442450]支持的模型格式 TVMC 支持用 Keras、ONNX、TensorFlow、TFLite 和 Torch创建的模型。如果你需要明确地提供你所使用的模型格式请使用选项 --model-format。 为 TVM 添加 ONNX 支持 TVM 依赖于你系统中的 ONNX python 库。你可以使用 pip3 install --user onnx onnxoptimizer 命令来安装ONNX。如果你有 root 权限并且想全局安装 ONNX你可以去掉 --user 选项。对onnxoptimizer 的依赖是可选的仅用于 onnx1.9 三、将 ONNX 模型编译到 TVM 运行时中 一旦下载了 ResNet-50 模型下一步就是对其进行编译。为了达到这个目的将使用 tvmc compile。从编译过程中得到的输出是模型的 TAR 包它被编译成目标平台的动态库。可以使用 TVM 运行时在目标设备上运行该模型。 # 这可能需要几分钟的时间取决于你的机器 !python -m tvm.driver.tvmc compile --target llvm \--output resnet50-v2-7-tvm.tar \../../_models/resnet50-v2-7.onnxOne or more operators have not been tuned. Please tune your model for better performance. Use DEBUG logging level to see more details.查看 tvmc compile 在 module 中创建的文件 %%bash mkdir model tar -xvf resnet50-v2-7-tvm.tar -C modelmod.so mod.json mod.paramsmod.so 是模型表示为 C 库可以被 TVM 运行时加载。mod.json 是 TVM Relay 计算图的文本表示。mod.params 是包含预训练模型参数的文件。 指定正确的目标选项 --target可以对编译后的模块的性能产生巨大的影响因为它可以利用目标上可用的硬件特性。 四、TVMC 从编译的模块中运行模型 TVMC 内置了 TVM 运行时允许你运行编译的 TVM 模型。为了使用 TVMC 来运行模型并进行预测需要两样东西 编译后的模块刚刚生成出来。对模型的有效输入以进行预测。 当涉及到预期的张量形状、格式和数据类型时每个模型都很特别。出于这个原因大多数模型需要一些预处理和后处理以确保输入是有效的并解释输出结果。TVMC 对输入和输出数据都采用了 NumPy 的 .npz 格式。这是得到良好支持的 NumPy 格式可以将多个数组序列化为文件。 4.1、输入预处理 对于 ResNet-50 v2 模型预期输入是 ImageNet 格式的。下面是为 ResNet-50 v2 预处理图像的脚本例子。你将需要安装支持的 Python 图像库的版本。你可以使用 pip3 install --user pillow 来满足脚本的这个要求 #!python ./preprocess.py from tvm.contrib.download import download_testdata from PIL import Image import numpy as npimg_url https://s3.amazonaws.com/model-server/inputs/kitten.jpg img_path download_testdata(img_url, imagenet_cat.png, moduledata)# Resize it to 224x224 resized_image Image.open(img_path).resize((224, 224)) img_data np.asarray(resized_image).astype(float32)# ONNX expects NCHW input, so convert the array img_data np.transpose(img_data, (2, 0, 1))# Normalize according to ImageNet imagenet_mean np.array([0.485, 0.456, 0.406]) imagenet_stddev np.array([0.229, 0.224, 0.225]) norm_img_data np.zeros(img_data.shape).astype(float32) for i in range(img_data.shape[0]):norm_img_data[i, :, :] (img_data[i, :, :] / 255 - imagenet_mean[i]) / imagenet_stddev[i]# Add batch dimension img_data np.expand_dims(norm_img_data, axis0)# Save to .npz (outputs imagenet_cat.npz) np.savez(imagenet_cat, dataimg_data)4.2 运行已编译的模块 有了模型和输入数据现在可以运行 TVMC 来做预测 !python -m tvm.driver.tvmc run \--inputs imagenet_cat.npz \--output predictions.npz \resnet50-v2-7-tvm.tar回顾一下 .tar 模型文件包括 C 库对 Relay 模型的描述以及模型的参数。TVMC 包括 TVM 运行时它可以加载模型并根据输入进行预测。当运行上述命令时TVMC 会输出新文件predictions.npz其中包含 NumPy 格式的模型输出张量。 4.3 输出后处理 如前所述每个模型都会有自己的特定方式来提供输出张量。需要运行一些后处理利用为模型提供的查找表将 ResNet-50 v2 的输出渲染成人类可读的形式。下面的脚本显示了后处理的例子从编译的模块的输出中提取标签。运行这个脚本应该产生以下输出 #!python ./postprocess.py import os.path import numpy as npfrom scipy.special import softmaxfrom tvm.contrib.download import download_testdata# Download a list of labels labels_url https://s3.amazonaws.com/onnx-model-zoo/synset.txt labels_path download_testdata(labels_url, synset.txt, moduledata)with open(labels_path, r) as f:labels [l.rstrip() for l in f]output_file predictions.npz# Open the output and read the output tensor if os.path.exists(output_file):with np.load(output_file) as data:scores softmax(data[output_0])scores np.squeeze(scores)ranks np.argsort(scores)[::-1]for rank in ranks[0:5]:print(class%s with probability%f % (labels[rank], scores[rank]))classn02123045 tabby, tabby cat with probability0.621104 classn02123159 tiger cat with probability0.356378 classn02124075 Egyptian cat with probability0.019712 classn02129604 tiger, Panthera tigris with probability0.001215 classn04040759 radiator with probability0.000262
http://www.yingshimen.cn/news/93944/

相关文章:

  • 建站公司的工作流程贵阳自助建站软件
  • 电子商务网站推广实训心得贵州做网站找谁
  • 要怎么判断网站是什么cms做的商务网站的推广方法有哪些
  • 吉林省网络推广公司云南网络营销seo
  • 青海公路建设信用信息服务网站淮安集团网站建设
  • 免费做公司网站能在百度上搜索的到企业网络管理方案
  • 免费行情软件网站下载市场调研公司存在的意义
  • 网站建设协议附件小程序ui设计报价
  • 网站建设价表模板仿小米 wordpress
  • 北京建设信源网站 怎么打不开wordpress无法评论
  • 网站如何推广运营小米官方网站开发版在哪里
  • 网站seo推广怎么做重庆建设工程信息网怎么打不开
  • 网站建设的发展历程自己建网站怎么弄
  • 淄博周村网站建设方案盲盒app开发
  • wordpress 网站加速石龙网站设计
  • 怎么在58同城上做网站两学一做山西答题网站
  • 网站开发框架的工具月夜影视在线观看免费完整版韩剧
  • 制作网站设计的公司房产网排名
  • 网站建设要求30天网站建设全程实录 pdf
  • 建立网站链接结构的基本方式是推广赚钱app
  • 七冶建设集团网站第一装修网
  • 360网站名片怎么做的蒲县网站建设
  • 远近互联网站建设网站建设完整版
  • 常州辉煌网络网站制作网站备案查询到什么资料
  • 织梦电影网站免费模板各家建站平台
  • 如何给异地网站做镜像深圳seo公司
  • 电子商务网站开发工具德州市建设工程协会网站
  • 网站外链建设工作计划网站建设与管理拼音
  • 建设一个商城式网站可以吗移动端网站咋做
  • 郓城网站开发阿里云建站论坛网站