深度学习pytorch之hub模块
pytorchhub模块里面有很多模型
https://pytorch.org/hub/
github网址:https://github.com/pytorch/pytorch
import torch
model = torch.hub.load('pytorch/vision:v0.10.0', 'fcn_resnet50', pretrained=True)
# or
# model = torch.hub.load('pytorch/vision:v0.10.0', 'fcn_resnet101', pretrained=True)
model.eval()
All pre-trained models expect input images normalized in the same way, i.e. mini-batches of 3-channel RGB images of shape (N, 3, H, W), where N is the number of images, H and W are expected to be at least 224 pixels. The images have to be loaded in to a range of [0, 1] and then normalized using mean = [0.485, 0.456, 0.406] and std = [0.229, 0.224, 0.225].The model returns an OrderedDict with two Tensors that are of the same height and width as the input Tensor, but with 21 classes. output['out'] contains the semantic masks, and output['aux'] contains the auxillary loss values per-pixel. In inference mode, output['aux'] is not useful. So, output['out'] is of shape (N, 21, H, W). More documentation can be found here.# Download an example image from the pytorch website
import urllib
url, filename = ("https://github.com/pytorch/hub/raw/master/images/deeplab1.png", "deeplab1.png")
try: urllib.URLopener().retrieve(url, filename)
except: urllib.request.urlretrieve(url, filename)
# sample execution (requires torchvision)
from PIL import Image
from torchvision import transforms
input_image = Image.open(filename)
input_image = input_image.convert("RGB")
preprocess = transforms.Compose([transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])input_tensor = preprocess(input_image)
input_batch = input_tensor.unsqueeze(0) # create a mini-batch as expected by the model# move the input and model to GPU for speed if available
if torch.cuda.is_available():input_batch = input_batch.to('cuda')model.to('cuda')with torch.no_grad():output = model(input_batch)['out'][0]
output_predictions = output.argmax(0)
The output here is of shape (21, H, W), and at each location, there are unnormalized probabilities corresponding to the prediction of each class. To get the maximum prediction of each class, and then use it for a downstream task, you can do output_predictions = output.argmax(0).Here’s a small snippet that plots the predictions, with each color being assigned to each class (see the visualized image on the left).# create a color pallette, selecting a color for each class
palette = torch.tensor([2 ** 25 - 1, 2 ** 15 - 1, 2 ** 21 - 1])
colors = torch.as_tensor([i for i in range(21)])[:, None] * palette
colors = (colors % 255).numpy().astype("uint8")# plot the semantic segmentation predictions of 21 classes in each color
r = Image.fromarray(output_predictions.byte().cpu().numpy()).resize(input_image.size)
r.putpalette(colors)import matplotlib.pyplot as plt
plt.imshow(r)
# plt.show()
Model Description
FCN-ResNet is constructed by a Fully-Convolutional Network model, using a ResNet-50 or a ResNet-101 backbone. The pre-trained models have been trained on a subset of COCO train2017, on the 20 categories that are present in the Pasca
根据灰色的部分复制相应的代码
相关文章:

深度学习pytorch之hub模块
pytorchhub模块里面有很多模型 https://pytorch.org/hub/ github网址:https://github.com/pytorch/pytorch import torch model torch.hub.load(pytorch/vision:v0.10.0, fcn_resnet50, pretrainedTrue) # or # model torch.hub.load(pytorch/vision:v0.10.0, fc…...

LeetCode 2258. 逃离火灾:BFS
【LetMeFly】2258.逃离火灾 力扣题目链接:https://leetcode.cn/problems/escape-the-spreading-fire/ 给你一个下标从 0 开始大小为 m x n 的二维整数数组 grid ,它表示一个网格图。每个格子为下面 3 个值之一: 0 表示草地。1 表示着火的格…...

C# PaddleInference.PP-HumanSeg 人像分割 替换背景色
效果 项目 VS2022.net4.8OpenCvSharp4Sdcb.PaddleInference 包含4个分割模型 modnet-hrnet_w18 modnet-mobilenetv2 ppmatting-hrnet_w18-human_512 ppmattingv2-stdc1-human_512 代码 using OpenCvSharp; using Sdcb.PaddleInference; using System; using System.Col…...
Java 变量初始化的两种方式和优缺点比较
第一种初始化方式:(优先推荐) String fileRename null; File fileToSave null; 这种方式将变量的作用域限定在循环外部,即在整个代码块中都可以使用这些变量。初始值为null表示变量在开始时没有具体的数值。 这种方式更好的…...
15.三数之和
题目来源: leetcode题目,网址:15. 三数之和 - 力扣(LeetCode) 解题思路: 1.三重循环暴力遍历,超时原因,三重循环复杂度太高 2.双重循环哈希表,超时原因,哈…...

竞赛选题 深度学习疲劳驾驶检测 opencv python
文章目录 0 前言1 课题背景2 实现目标3 当前市面上疲劳驾驶检测的方法4 相关数据集5 基于头部姿态的驾驶疲劳检测5.1 如何确定疲劳状态5.2 算法步骤5.3 打瞌睡判断 6 基于CNN与SVM的疲劳检测方法6.1 网络结构6.2 疲劳图像分类训练6.3 训练结果 7 最后 0 前言 🔥 优…...
PROFINET和UDP、MODBUS-RTU通信速度对比实验
这篇博客我们介绍PROFINET 和MODBUS-RTU通信实验时的数据刷新速度,以及这种速度不同对控制系统带来的挑战都有哪些,在介绍这篇对比实验之前大家可以参考下面的文章链接: S7-1200PLC和SMART PLC的PN智能从站通信 S7-200 SMART 和 S7-1200PLC进行PROFINET IO通信-CSDN博客文…...

CSS3 多媒体查询、网格布局
一、CSS3多媒体查询: CSS3 多媒体查询继承了CSS2多媒体类型的所有思想,取代了查找设备的类型。CSS3根据设置自适应显示。 多媒体查询语法: media not|only mediatype and (expressions) { CSS 代码...; } not: not是用来排除掉某些特定…...
SpringBoot基础(九)-- 配置文件优先级
目录 1. 3种格式的配置文件的优先级 2. 案例演示 小结: 3. 小技巧:自动提示功能消失解决方案...

C++ static关键字
C static关键字 1、概述2、重要概念解释3、分情况案例解释3.1 static在类内使用3.2 static在类外使用案例一:案例二:案例三 1、概述 static关键字分为两种情况: 1.在类内使用 2.在类外使用 2、重要概念解释 (1)翻译…...

Anaconda Powershell Prompt和Anaconda Prompt的区别
先说结论:主要功能应该一样。区别在于powershell支持的命令更多。比如查询路径的命令pwd和列表命令ls。 Anaconda PowerShell Prompt和Anaconda Prompt是Anaconda发行版中两个不同的命令提示符工具。 Anaconda Prompt是Anaconda发布的默认命令提示符工具࿰…...
关于tcp发送成功但对端无法接收情况的思考
用到一个http服务,但调用频率很高,每次请求都使用短连接的话,有点浪费。 所以尝试复用http连接,请求的时候在头部添加Connection:Keep-alive,对端支持,但会在一定时常或一定请求次数后关闭该连接…...
01-解码-H264转YUV
整体方案: 采集端:摄像头采集(YUV)->编码(YUV转H264)->RTMP推流 客户端:RTMP拉流->解码(H264转YUV)->YUV显示(SDL2) H264码流转YUV是视频解码部分,具体的代码实现如下。 #include <stdio.h> #include <stdlib.h> #ifdef __cplusplus ext…...

keepalived+Nginx+邮件
实验场景: 我使用keepalived保证nginx的高可用,我想知道什么时候ip发生漂移,可以让ip发生漂移的时候 我的邮箱收到消息. 如果对keepalived不了解,这有详细解释:keepalived与nginx与MySQL-CSDN博客https://blog.csdn.ne…...

CMakeCache.txt有什么用
2023年11月11日,周六上午 CMakeCache.txt 是由 CMake 自动生成的一个缓存文件,用于记录在配置过程中生成的各种变量和选项的值。 在使用 CMake 构建项目时,CMake 会根据 CMakeLists.txt 文件中的配置和命令,解析项目的源代码并生…...

ZYNQ_project:key_breath
[Synth 8-327] inferring latch for variable led_breath_reg ["C:/Users/warrior/Desktop/ZYNQ/pl/key_breath/rtl/led_breath.v":66] 因为在组合逻辑中,用了非阻塞赋值的方式赋值信号。 组合逻辑自己给自己赋值会产生组合回环,输出不稳定。 …...
设计模式 (原则)
在软件开发中,为了提高软件系统的可维护性和可复用性,增加软件的可扩展性和灵活性,程序员要尽量根据6条原则来开发程序,从而提高软件开发效率、节约软件开发成本和维护成本 一、开闭原则 对扩展开放,对修改关闭。 案…...
LeetCode 每日一题 2023/11/6-2023/11/12
记录了初步解题思路 以及本地实现代码;并不一定为最优 也希望大家能一起探讨 一起进步 目录 11/6 318. 最大单词长度乘积11/7 2586. 统计范围内的元音字符串数11/8 2609. 最长平衡子字符串11/9 2258. 逃离火灾11/10 2300. 咒语和药水的成功对数11/11 765. 情侣牵手1…...

Linux 基于 LVM 逻辑卷的磁盘管理【简明教程】
一、传统磁盘管理的弊端 传统的磁盘管理:使用MBR先对硬盘分区,然后对分区进行文件系统的格式化最后再将该分区挂载上去。 传统的磁盘管理当分区没有空间使用进行扩展时,操作比较麻烦。分区使用空间已经满了,不再够用了ÿ…...

CTFHUB-WEB-SQL注入
sql学的太不好了,回炉重造 判断 Sql 注入漏洞的类型: 1.数字型 当输入的参 x 为整型时,通常 abc.php 中 Sql 语句类型大致如下:select * from <表名> where id x这种类型可以使用经典的 and 11 和 and 12 来判断ÿ…...

Chapter03-Authentication vulnerabilities
文章目录 1. 身份验证简介1.1 What is authentication1.2 difference between authentication and authorization1.3 身份验证机制失效的原因1.4 身份验证机制失效的影响 2. 基于登录功能的漏洞2.1 密码爆破2.2 用户名枚举2.3 有缺陷的暴力破解防护2.3.1 如果用户登录尝试失败次…...

css实现圆环展示百分比,根据值动态展示所占比例
代码如下 <view class""><view class"circle-chart"><view v-if"!!num" class"pie-item" :style"{background: conic-gradient(var(--one-color) 0%,#E9E6F1 ${num}%),}"></view><view v-else …...

Nuxt.js 中的路由配置详解
Nuxt.js 通过其内置的路由系统简化了应用的路由配置,使得开发者可以轻松地管理页面导航和 URL 结构。路由配置主要涉及页面组件的组织、动态路由的设置以及路由元信息的配置。 自动路由生成 Nuxt.js 会根据 pages 目录下的文件结构自动生成路由配置。每个文件都会对…...

多模态大语言模型arxiv论文略读(108)
CROME: Cross-Modal Adapters for Efficient Multimodal LLM ➡️ 论文标题:CROME: Cross-Modal Adapters for Efficient Multimodal LLM ➡️ 论文作者:Sayna Ebrahimi, Sercan O. Arik, Tejas Nama, Tomas Pfister ➡️ 研究机构: Google Cloud AI Re…...

基于Springboot+Vue的办公管理系统
角色: 管理员、员工 技术: 后端: SpringBoot, Vue2, MySQL, Mybatis-Plus 前端: Vue2, Element-UI, Axios, Echarts, Vue-Router 核心功能: 该办公管理系统是一个综合性的企业内部管理平台,旨在提升企业运营效率和员工管理水…...
如何通过git命令查看项目连接的仓库地址?
要通过 Git 命令查看项目连接的仓库地址,您可以使用以下几种方法: 1. 查看所有远程仓库地址 使用 git remote -v 命令,它会显示项目中配置的所有远程仓库及其对应的 URL: git remote -v输出示例: origin https://…...
LangChain【6】之输出解析器:结构化LLM响应的关键工具
文章目录 一 LangChain输出解析器概述1.1 什么是输出解析器?1.2 主要功能与工作原理1.3 常用解析器类型 二 主要输出解析器类型2.1 Pydantic/Json输出解析器2.2 结构化输出解析器2.3 列表解析器2.4 日期解析器2.5 Json输出解析器2.6 xml输出解析器 三 高级使用技巧3…...
C++ 类基础:封装、继承、多态与多线程模板实现
前言 C 是一门强大的面向对象编程语言,而类(Class)作为其核心特性之一,是理解和使用 C 的关键。本文将深入探讨 C 类的基本特性,包括封装、继承和多态,同时讨论类中的权限控制,并展示如何使用类…...
无需布线的革命:电力载波技术赋能楼宇自控系统-亚川科技
无需布线的革命:电力载波技术赋能楼宇自控系统 在楼宇自动化领域,传统控制系统依赖复杂的专用通信线路,不仅施工成本高昂,后期维护和扩展也极为不便。电力载波技术(PLC)的突破性应用,彻底改变了…...

python可视化:俄乌战争时间线关键节点与深层原因
俄乌战争时间线可视化分析:关键节点与深层原因 俄乌战争是21世纪欧洲最具影响力的地缘政治冲突之一,自2022年2月爆发以来已持续超过3年。 本文将通过Python可视化工具,系统分析这场战争的时间线、关键节点及其背后的深层原因,全面…...