1、.,*,+,?, \d,\w,\s,\b分别是什么? py

时间: 2023-12-20 20:04:53 浏览: 12
以上都是 Python 中的正则表达式元字符,具体含义如下: - "." 代表任意单个字符。 - "*" 代表匹配前面的字符 0 次或多次。 - " " 代表空格字符。 - "?" 代表匹配前面的字符 0 次或 1 次。 - "\d" 代表任意一位数字。 - "\w" 代表任意一个字符或数字或下划线。 - "\s" 代表任意一个空白字符。 - "\b" 代表单词边界。
相关问题

Traceback (most recent call last): File "D:\anaconda3\envs\ml-lab\lib\site-packages\IPython\core\interactiveshell.py", line 3505, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-2-6c57772f5021>", line 1, in <module> runfile('D:/ml-lab/.idea/not1.py', wdir='D:/ml-lab/.idea') File "D:\PyCharm 2021.3.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 198, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script File "D:\PyCharm 2021.3.3\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "D:/ml-lab/.idea/not1.py", line 86, in <module> svm.fit(train_X, train_y) File "D:/ml-lab/.idea/not1.py", line 32, in fit self.E = self._E(self.X, self.y, self.b, self.alpha) File "D:/ml-lab/.idea/not1.py", line 83, in _E return np.dot(X, self.w) + b - y为啥报错

这是一个 Python 的 Traceback 错误信息,可以看到报错信息中包含了文件路径和行号。根据报错信息可以看出是在 `not1.py` 文件中的第 86 行出现了错误,具体是在 `svm.fit(train_X, train_y)` 这一行。在 `fit` 函数中调用了 `_E` 函数计算误差,而在 `_E` 函数中的第 83 行出现了错误。具体错误信息是 `return np.dot(X, self.w) + b - y`,这可能是由于某些变量的维度不匹配导致的。需要检查一下相关变量的维度是否正确以及是否有缺失值等问题。

yolov7 common.py 源码

以下是 YOLOv7 的 common.py 源码: ```python import math import torch.nn.functional as F import torch.nn as nn import torch def make_divisible(x, divisor): # Returns x evenly divisible by divisor return math.ceil(x / divisor) * divisor def autopad(k, p=None): # kernel, padding # Pad to 'same' if p is None: p = k // 2 if isinstance(k, int) else [x // 2 for x in k] return p class Conv(nn.Module): # Standard convolution def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True): super(Conv, self).__init__() self.conv = nn.Conv2d(c1, c2, k, stride=s, padding=autopad(k, p), groups=g, bias=False) self.bn = nn.BatchNorm2d(c2) self.act = nn.Hardswish() if act else nn.Identity() def forward(self, x): return self.act(self.bn(self.conv(x))) class Bottleneck(nn.Module): # Standard bottleneck def __init__(self, c1, c2, shortcut=True, g=1, e=0.5): super(Bottleneck, self).__init__() c_ = int(c2 * e) # hidden channels self.cv1 = Conv(c1, c_, 1, 1) self.cv2 = Conv(c_, c2, 3, 1, g=g) self.add = shortcut and c1 == c2 self.identity = nn.Identity() if self.add else None def forward(self, x): return self.identity(x) + self.cv2(self.cv1(x)) class SPP(nn.Module): # Spatial pyramid pooling layer used in YOLOv3-SPP def __init__(self, c1, c2, k=(5, 9, 13)): super(SPP, self).__init__() c_ = c1 // 2 # hidden channels self.cv1 = Conv(c1, c_, 1, 1) self.cv2 = Conv(c_ * (len(k) + 1), c2, 1, 1) self.m = nn.ModuleList([nn.MaxPool2d(kernel_size=x, stride=1, padding=x // 2) for x in k]) def forward(self, x): x = self.cv1(x) return self.cv2(torch.cat([x] + [m(x) for m in self.m], 1)) class DWConv(nn.Module): # Depthwise convolution def __init__(self, c1, c2, k=1, s=1, p=None): super(DWConv, self).__init__() self.conv = nn.Conv2d(c1, c1, k, stride=s, padding=autopad(k, p), groups=c1, bias=False) self.bn = nn.BatchNorm2d(c1) self.act = nn.Hardswish() self.project = nn.Conv2d(c1, c2, 1, bias=False) self.bn2 = nn.BatchNorm2d(c2) self.act2 = nn.Hardswish() def forward(self, x): return self.act2(self.bn2(self.project(self.act(self.bn(self.conv(x)))))) class Focus(nn.Module): # Focus wh information into c-space def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True): super(Focus, self).__init__() self.conv = Conv(c1 * 4, c2, k, s, p, g, act) def forward(self, x): # x(b,c,w,h) -> y(b,4c,w/2,h/2) return self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1)) class Concat(nn.Module): # Concatenate a list of tensors along dimension def __init__(self, dimension=1): super(Concat, self).__init__() self.d = dimension def forward(self, x): return torch.cat(x, self.d) class Detect(nn.Module): # Detect layer def __init__(self, nc, anchors): super(Detect, self).__init__() self.nc = nc # number of classes self.no = nc + 5 # number of outputs per anchor self.na = len(anchors) # number of anchors self.anchors = torch.tensor(anchors).float().view(self.na, -1) self.anchors /= self.anchors.sum(1).view(self.na, 1) # normalized anchors self.register_buffer("anchor_grid", self.anchors.clone().view(1, -1, 1, 1)) self.m = nn.Conv2d(self.no * self.na, self.no * self.na, 1) # prediction conv def forward(self, x): # x(bs,255,h,w) -> p(bs,3,85,h,w) bs, _, ny, nx = x.shape device, dtype = x.device, x.dtype stride = self.anchor_grid.device / torch.tensor([nx, ny])[None, :, None, None].to(device) grid = torch.meshgrid([torch.arange(ny), torch.arange(nx)]) y = torch.stack(grid, 2).to(device).float() x = (x.sigmoid() * 2. - 0.5) * stride # x(?,255,?,?) --sig--> x(?,255,?,?) --*2-0.5--> x(?,255,?,?) --*stride--> x(?,255,?,?) y = (y + 0.5) * stride # y(?,2,?,?) --+0.5--> y(?,2,?,?) --*stride--> y(?,2,?,?) xy = torch.stack([x, y], 2).view(bs, 2, self.na * ny * nx).permute(0, 2, 1).contiguous().view(bs, self.na * ny * nx, 2) x = self.m(x.flatten(2).permute(0, 2, 1)).view(bs, self.na, self.no, ny, nx).permute(0, 1, 3, 4, 2).contiguous() # x(bs,na,ny,nx,na) --view--> x(bs,na,ny,nx,no) --permute--> x(bs,na,ny,nx,no) if not self.training: x[..., 4:] = x[..., 4:].sigmoid() return x else: # train return x, xy, self.anchor_grid.repeat(bs, 1, ny, nx) class Model(nn.Module): # YOLOv7 model https://github.com/WongKinYiu/yolov7 def __init__(self, nc=80, anchors=((10, 13), (16, 30), (33, 23), (30, 61), (62, 45), (59, 119), (116, 90), (156, 198), (373, 326)), ch=[256, 512, 1024, 2048], depth=0.33): super(Model, self).__init__() assert depth in [0.33, 0.67, 1.0] self.depth = depth # model depth multiplier self.grid = [torch.zeros(1)] * 5 # init grid self.stride = torch.tensor([8., 16., 32., 64., 128.]) self.create_backbone(ch) self.create_neck() self.create_head(nc, anchors) def forward(self, x): z = [] for i in range(5): x = self.backbone[i](x) z.append(x) x = self.neck(z) return self.head(x) def create_backbone(self, ch): # darknet backbone self.backbone = nn.ModuleList([Focus(3, ch[0], 3), Conv(ch[0], ch[1], 3, 2), Bottleneck(ch[1], ch[2]), Conv(ch[2], ch[3], 3, 2), Bottleneck(ch[3], ch[4]), Conv(ch[4], ch[5], 3, 2), SPP(ch[5], ch[5]), Bottleneck(ch[5], ch[6]), Conv(ch[6], ch[7], 1)]) c2 = make_divisible(ch[7] * self.depth) # ch_last self.backbone.append(Bottleneck(ch[7], c2, False)) self.out_channels = [c2, ch[4], ch[2], ch[0]] def create_neck(self): # FPN-like attentional output self.neck = nn.Sequential( Concat(), Conv(self.out_channels[0], self.out_channels[0], 1), DWConv(self.out_channels[0], self.out_channels[1], 3, s=2), DWConv(self.out_channels[1], self.out_channels[2], 3, s=2), DWConv(self.out_channels[2], self.out_channels[3], 3, s=2), SPP(self.out_channels[3], self.out_channels[3]), DWConv(self.out_channels[3], self.out_channels[3], 3, dilation=3), DWConv(self.out_channels[3], self.out_channels[3], 3, dilation=3), DWConv(self.out_channels[3], self.out_channels[3], 3, dilation=3), ) def create_head(self, nc, anchors): # detection head self.head = nn.Sequential( DWConv(self.out_channels[3], self.out_channels[3], 3, dilation=3), DWConv(self.out_channels[3], self.out_channels[3], 3, dilation=3), DWConv(self.out_channels[3], self.out_channels[3], 3, dilation=3), Concat(), Conv(self.out_channels[3] * 4, self.out_channels[3], 1), nn.Conv2d(self.out_channels[3], len(anchors) * (nc + 5), 1, bias=True), Detect(nc, anchors)) def attempt_load(weights, map_location=None, inplace=True): # Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a if isinstance(weights, (list, tuple)): # Load a list of models (ensemble) ensemble = nn.ModuleList() for w in weights: model = Model() model.to(next(w.parameters()).device) try: ckpt = torch.load(w, map_location=map_location) # load state_dict = ckpt['model'].float().state_dict() # to FP32 state_dict = {k: v for k, v in state_dict.items() if model.state_dict()[k].shape == v.shape} # filter model.load_state_dict(state_dict, strict=False) # load print(f"Transferred {len(state_dict)} from {w}") except: print(f"Error loading {w}") ensemble.append(model.eval()) return ensemble else: # Load a single model model = Model() model.to(next(weights.parameters()).device) try: ckpt = torch.load(weights, map_location=map_location) # load state_dict = ckpt['model'].float().state_dict() # to FP32 state_dict = {k: v for k, v in state_dict.items() if model.state_dict()[k].shape == v.shape} # filter model.load_state_dict(state_dict, strict=False) # load print(f"Transferred {len(state_dict)} from {weights}") except: print(f"Error loading {weights}") return model.eval() ```

相关推荐

D:\2021c\python\供应货能力(高斯过程拟合).py:64: UserWarning: Glyph 20379 (\N{CJK UNIFIED IDEOGRAPH-4F9B}) missing from current font. plt.savefig(f'./img/供应商ID_{supplier}') D:\2021c\python\供应货能力(高斯过程拟合).py:64: UserWarning: Glyph 24212 (\N{CJK UNIFIED IDEOGRAPH-5E94}) missing from current font. plt.savefig(f'./img/供应商ID_{supplier}') D:\2021c\python\供应货能力(高斯过程拟合).py:64: UserWarning: Glyph 21830 (\N{CJK UNIFIED IDEOGRAPH-5546}) missing from current font. plt.savefig(f'./img/供应商ID_{supplier}') Traceback (most recent call last): File "D:\2021c\python\供应货能力(高斯过程拟合).py", line 64, in <module> plt.savefig(f'./img/供应商ID_{supplier}') File "D:\Python\Lib\site-packages\matplotlib\pyplot.py", line 1023, in savefig res = fig.savefig(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Python\Lib\site-packages\matplotlib\figure.py", line 3378, in savefig self.canvas.print_figure(fname, **kwargs) File "D:\Python\Lib\site-packages\matplotlib\backend_bases.py", line 2366, in print_figure result = print_method( ^^^^^^^^^^^^^ File "D:\Python\Lib\site-packages\matplotlib\backend_bases.py", line 2232, in <lambda> print_method = functools.wraps(meth)(lambda *args, **kwargs: meth( ^^^^^ File "D:\Python\Lib\site-packages\matplotlib\backends\backend_agg.py", line 509, in print_png self._print_pil(filename_or_obj, "png", pil_kwargs, metadata) File "D:\Python\Lib\site-packages\matplotlib\backends\backend_agg.py", line 458, in _print_pil mpl.image.imsave( File "D:\Python\Lib\site-packages\matplotlib\image.py", line 1689, in imsave image.save(fname, **pil_kwargs) File "D:\Python\Lib\site-packages\PIL\Image.py", line 2429, in save fp = builtins.open(filename, "w+b") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: './img/供应商ID_S140.png'

转python写法:#!/bin/sh time_stamp=date +%s function CheckStop() { if [ $? -ne 0 ]; then echo "execute fail, error on line_no:"$1" exit!!!" exit fi } function GenEcdsaKey() { ec_param_file_path="/tmp/ec_param.pem."$time_stamp openssl ecparam -out $ec_param_file_path -name prime256v1 -genkey CheckStop $LINENO openssl genpkey -paramfile $ec_param_file_path -out $1 CheckStop $LINENO openssl pkey -in $1 -inform PEM -out $2 -outform PEM -pubout CheckStop $LINENO rm $ec_param_file_path echo "gen_ecdsa_key succ prikey_path:"$1" pubkey_path:"$2 } function GenEcdsaSign() { ec_sign_info_file="/tmp/ec_sign_info_file."$time_stamp ec_sign_info_sha256="/tmp/ec_sign_info_sha256."$time_stamp ec_binary_sign_file="/tmp/ec_binary_sign_file."$time_stamp echo -n "$1"_"$2" > $ec_sign_info_file openssl dgst -sha256 -binary -out $ec_sign_info_sha256 $ec_sign_info_file CheckStop $LINENO openssl pkeyutl -sign -in $ec_sign_info_sha256 -out $ec_binary_sign_file -inkey $3 -keyform PEM CheckStop $LINENO openssl base64 -e -in $ec_binary_sign_file -out $4 CheckStop $LINENO rm $ec_sign_info_file $ec_sign_info_sha256 $ec_binary_sign_file echo "gen_ecdsa_sign succ sign_file_path:"$4 } function VerifyEcdsaSign() { ec_sign_info_file="/tmp/ec_sign_info_file."$time_stamp ec_sign_info_sha256="/tmp/ec_sign_info_sha256."$time_stamp ec_binary_sign_file="/tmp/ec_binary_sign_file."$time_stamp echo -n "$1"_"$2" > $ec_sign_info_file openssl dgst -sha256 -binary -out $ec_sign_info_sha256 $ec_sign_info_file CheckStop $LINENO openssl base64 -d -in $4 -out $ec_binary_sign_file CheckStop $LINENO openssl pkeyutl -verify -in $ec_sign_info_sha256 -sigfile $ec_binary_sign_file -pubin -inkey $3 -keyform PEM rm $ec_sign_info_file $ec_sign_info_sha256 $ec_binary_sign_file } function Usage() { echo "Usage:" echo "mmiot_ecdsa_sign.sh gen_ecdsa_key " echo "mmiot_ecdsa_sign.sh gen_ecdsa_sign <sn> <private_

最新推荐

recommend-type

WX小程序源码小游戏类

WX小程序源码小游戏类提取方式是百度网盘分享地址
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

用Spring boot和vue写一个登录注册界面

好的,这是一个比较常见的技术问题,我可以为您提供一些参考资料和思路。首先,您可以使用Spring Boot作为后端框架来处理用户认证和注册的逻辑,比如使用Spring Security实现用户登录认证。同时,您还需要设计相应的数据模型和数据库表结构来存储用户信息。在前端方面,您可以使用Vue.js作为框架来构建登录注册页面,使用Axios来发起API请求并和后端进行交互。当然,在实现过程中,还需要考虑一些具体细节,比如数据校验、安全性和用户体验等方面。希望这些信息能够帮助到您。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

MATLAB柱状图在数据分析中的作用:从可视化到洞察

![MATLAB柱状图在数据分析中的作用:从可视化到洞察](https://img-blog.csdnimg.cn/img_convert/1a36558cefc0339f7836cca7680c0aef.png) # 1. MATLAB柱状图概述** 柱状图是一种广泛用于数据可视化的图表类型,它使用垂直条形来表示数据中不同类别或组别的值。在MATLAB中,柱状图通过`bar`函数创建,该函数接受数据向量或矩阵作为输入,并生成相应的高度条形。 柱状图的优点在于其简单性和易于理解性。它们可以快速有效地传达数据分布和组别之间的比较。此外,MATLAB提供了广泛的定制选项,允许用户调整条形颜色、
recommend-type

命名ACL和拓展ACL标准ACL的具体区别

命名ACL和标准ACL的主要区别在于匹配条件和作用范围。命名ACL可以基于协议、端口和其他条件进行匹配,并可以应用到接口、VLAN和其他范围。而标准ACL只能基于源地址进行匹配,并只能应用到接口。拓展ACL则可以基于源地址、目的地址、协议、端口和其他条件进行匹配,并可以应用到接口、VLAN和其他范围。
recommend-type

c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf

校园超市商品信息管理系统课程设计旨在帮助学生深入理解程序设计的基础知识,同时锻炼他们的实际操作能力。通过设计和实现一个校园超市商品信息管理系统,学生掌握了如何利用计算机科学与技术知识解决实际问题的能力。在课程设计过程中,学生需要对超市商品和销售员的关系进行有效管理,使系统功能更全面、实用,从而提高用户体验和便利性。 学生在课程设计过程中展现了积极的学习态度和纪律,没有缺勤情况,演示过程流畅且作品具有很强的使用价值。设计报告完整详细,展现了对问题的深入思考和解决能力。在答辩环节中,学生能够自信地回答问题,展示出扎实的专业知识和逻辑思维能力。教师对学生的表现予以肯定,认为学生在课程设计中表现出色,值得称赞。 整个课程设计过程包括平时成绩、报告成绩和演示与答辩成绩三个部分,其中平时表现占比20%,报告成绩占比40%,演示与答辩成绩占比40%。通过这三个部分的综合评定,最终为学生总成绩提供参考。总评分以百分制计算,全面评估学生在课程设计中的各项表现,最终为学生提供综合评价和反馈意见。 通过校园超市商品信息管理系统课程设计,学生不仅提升了对程序设计基础知识的理解与应用能力,同时也增强了团队协作和沟通能力。这一过程旨在培养学生综合运用技术解决问题的能力,为其未来的专业发展打下坚实基础。学生在进行校园超市商品信息管理系统课程设计过程中,不仅获得了理论知识的提升,同时也锻炼了实践能力和创新思维,为其未来的职业发展奠定了坚实基础。 校园超市商品信息管理系统课程设计的目的在于促进学生对程序设计基础知识的深入理解与掌握,同时培养学生解决实际问题的能力。通过对系统功能和用户需求的全面考量,学生设计了一个实用、高效的校园超市商品信息管理系统,为用户提供了更便捷、更高效的管理和使用体验。 综上所述,校园超市商品信息管理系统课程设计是一项旨在提升学生综合能力和实践技能的重要教学活动。通过此次设计,学生不仅深化了对程序设计基础知识的理解,还培养了解决实际问题的能力和团队合作精神。这一过程将为学生未来的专业发展提供坚实基础,使其在实际工作中能够胜任更多挑战。