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

做篮球网站用的背景图买卖链接网

做篮球网站用的背景图,买卖链接网,公司注册代办北京,欢迎你的加入CenterNet模型推理部分解析 CenterNet官方代码环境部署 CenterNet作为2019年CVPR推出的论文,论文中给出了官方代码所在的github仓库地址。https://github.com/xingyizhou/CenterNet。 整个代码的代码量并不是特别大,但整个项目的难点在于使用了老版本的…

CenterNet模型推理部分解析

CenterNet官方代码环境部署

CenterNet作为2019年CVPR推出的论文,论文中给出了官方代码所在的github仓库地址。https://github.com/xingyizhou/CenterNet。

在这里插入图片描述

整个代码的代码量并不是特别大,但整个项目的难点在于使用了老版本的pytorch<1.0与一些依赖的资源库从而导致了整个项目在启动和加载时或产生很多的错误。

GPU版本安装问题

在这里插入图片描述
在官方代码的Readme文件夹的下面给出了安装步骤的文件。首先文件中说明了当时使用的时python3.6版本。(不建议使用python3.6版本

自己使用的conda激活虚拟环境后使用的是3.8版本。

对出错的部分没有进行截图,因此只是简单的进行一定的陈述。

  1. 错误一:使用pip来安装CUDA的pytorch版本,我在安装的时候发现,如果使用pip来安装torch会安装的是torch+cu这种版本。而使用conda安装的话会安装一些CUDA相关的依赖

在这里插入图片描述
而在安装dcnv2的过程中需要CUDA相关库的支持。所以pytorch要使用conda来进行安装。 (最好之间安装Gpu的版本)

gpu.c相关文件也需要编译而且容易报错。

  1. DCNV2文件对torch版本的不支持,(自己当时使用git切换conda的虚拟环境安装.make.sh文件时候报错)需要使用最新的DCNV2库,卸载之后重新安装替代。

在这里插入图片描述

  1. 踩坑的地方在启动setup.py文件之后,可能会产生两个错误,第一个是因为缺少c++的编译环境,缺少支持库的错误。第二个是说c++库的版本过高不支持

网上查的原因是因为CUDA更新比较慢,而vistual Studio的更新过快。我自己将2022的版本降为2019年的启动成功。

  1. 一定要下载nvcc完全对应的版本,我自己的是12.1但当时安装习惯安装的是11.8nvcc会报错

在这里插入图片描述
总结:我个人使用的是pytorch2.3.0的版本来进行安装的,如果安装过程中出现错误,可以联系博主简单交流。

模型推理部分代码

检测部分的启动参数示例

ctdet
–demo
…/images/17790319373_bd19b24cfc_k.jpg
–load_model
…/models/ctdet_coco_dla_2x.pth

启动部分会产生一个模型下载失败的错误,将模型自己手动的下载到C盘的cache->torch…文件下面即可以启动模型成功。

自己断点调试,报错的一部分主要是网络错误,作用是加载预训练的一部分权重数据。

在这里插入图片描述

和Yolo一样也是可以检测视频文件的。

断点调试分析

在这里插入图片描述

推理过程整体的执行流程图与代码

在这里插入图片描述

def demo(opt):os.environ['CUDA_VISIBLE_DEVICES'] = opt.gpus_str #指定GPU对哪些环境变量可用opt.debug = max(opt.debug, 1) # 设置debug属性便于进行调试Detector = detector_factory[opt.task]detector = Detector(opt)if opt.demo == 'webcam' or \opt.demo[opt.demo.rfind('.') + 1:].lower() in video_ext:cam = cv2.VideoCapture(0 if opt.demo == 'webcam' else opt.demo)detector.pause = Falsewhile True:_, img = cam.read()cv2.imshow('input', img)ret = detector.run(img)time_str = ''for stat in time_stats:time_str = time_str + '{} {:.3f}s |'.format(stat, ret[stat])print(time_str)if cv2.waitKey(1) == 27:return  # esc to quitelse:if os.path.isdir(opt.demo): # 如果参数中的待检测数据是文件夹image_names = []ls = os.listdir(opt.demo)for file_name in sorted(ls):ext = file_name[file_name.rfind('.') + 1:].lower()if ext in image_ext:image_names.append(os.path.join(opt.demo, file_name))else: # 普通文件image_names = [opt.demo] #获取文件名for (image_name) in image_names:ret = detector.run(image_name) # 通过检测网络执行推理(核心)time_str = ''for stat in time_stats:time_str = time_str + '{} {:.3f}s |'.format(stat, ret[stat])print(time_str)

核心推理函数的细化分析

在这里插入图片描述

run()函数整体的部分

  def run(self, image_or_path_or_tensor, meta=None):load_time, pre_time, net_time, dec_time, post_time = 0, 0, 0, 0, 0 #时间变量初始化merge_time, tot_time = 0, 0debugger = Debugger(dataset=self.opt.dataset, ipynb=(self.opt.debug==3), # Debugger便于调试与错误诊断theme=self.opt.debugger_theme)start_time = time.time()pre_processed = Falseif isinstance(image_or_path_or_tensor, np.ndarray):image = image_or_path_or_tensorelif type(image_or_path_or_tensor) == type (''): image = cv2.imread(image_or_path_or_tensor) # 通过opencv读取图片else:image = image_or_path_or_tensor['image'][0].numpy()pre_processed_images = image_or_path_or_tensorpre_processed = Trueloaded_time = time.time()load_time += (loaded_time - start_time)detections = [] # 检测列表for scale in self.scales:scale_start_time = time.time()if not pre_processed:images, meta = self.pre_process(image, scale, meta) # 执行图片的预处理else:# import pdb; pdb.set_trace()images = pre_processed_images['images'][scale][0]meta = pre_processed_images['meta'][scale]meta = {k: v.numpy()[0] for k, v in meta.items()}images = images.to(self.opt.device) # 将image张量移动到GPU上torch.cuda.synchronize() # 确保CUDA操作完成pre_process_time = time.time()pre_time += pre_process_time - scale_start_timeoutput, dets, forward_time = self.process(images, return_time=True)torch.cuda.synchronize()net_time += forward_time - pre_process_time # 根据之前的函数计算出推理解码等一系列的时间decode_time = time.time()dec_time += decode_time - forward_timeif self.opt.debug >= 2:self.debug(debugger, images, dets, output, scale)dets = self.post_process(dets, meta, scale) # 执行后处理的过程(得到80个类别的列表信息部分含有数据)torch.cuda.synchronize()post_process_time = time.time()post_time += post_process_time - decode_time # 计算后处理时间detections.append(dets)results = self.merge_outputs(detections)torch.cuda.synchronize()end_time = time.time()merge_time += end_time - post_process_timetot_time += end_time - start_timeif self.opt.debug >= 1:self.show_results(debugger, image, results) # 调用opencv函数显示结果return {'results': results, 'tot': tot_time, 'load': load_time, # 放入所有的信息进行返回'pre': pre_time, 'net': net_time, 'dec': dec_time,'post': post_time, 'merge': merge_time}

预处理函数的执行部分

  def pre_process(self, image, scale, meta=None):height, width = image.shape[0:2]new_height = int(height * scale)new_width  = int(width * scale)if self.opt.fix_res: # 转为输入大小512 x 512inp_height, inp_width = self.opt.input_h, self.opt.input_wc = np.array([new_width / 2., new_height / 2.], dtype=np.float32)s = max(height, width) * 1.0else:inp_height = (new_height | self.opt.pad) + 1inp_width = (new_width | self.opt.pad) + 1c = np.array([new_width // 2, new_height // 2], dtype=np.float32)s = np.array([inp_width, inp_height], dtype=np.float32)trans_input = get_affine_transform(c, s, 0, [inp_width, inp_height])# 获取仿射变换矩阵resized_image = cv2.resize(image, (new_width, new_height))# 读取图片裁剪inp_image = cv2.warpAffine(resized_image, trans_input, (inp_width, inp_height),flags=cv2.INTER_LINEAR) # 应用之前的仿射矩阵进行仿射变换inp_image = ((inp_image / 255. - self.mean) / self.std).astype(np.float32) # 归一化处理images = inp_image.transpose(2, 0, 1).reshape(1, 3, inp_height, inp_width)if self.opt.flip_test:images = np.concatenate((images, images[:, :, :, ::-1]), axis=0)images = torch.from_numpy(images) # 转为张量的格式meta = {'c': c, 's': s, 'out_height': inp_height // self.opt.down_ratio, # opt.down_ratio:下采样倍率'out_width': inp_width // self.opt.down_ratio} # 储存c:中心点坐标 s:缩放因子return images, meta # 128x128(下采样4倍的特征图)

解码扩增部分对应的代码信息

def ctdet_decode(heat, wh, reg=None, cat_spec_wh=False, K=100):batch, cat, height, width = heat.size() # cat:表示类别的数目# heat = torch.sigmoid(heat)# perform nms on heatmapsheat = _nms(heat) # maxpooling(3x3)类似nms算法# scores:得分最高的 K 个点的得分。# inds:得分最高的 K 个点的索引。# clses:得分最高的 K 个点对应的类别。# ys:得分最高的 K 个点的 y 坐标。# xs:得分最高的 K 个点的 x 坐标。scores, inds, clses, ys, xs = _topk(heat, K=K) # 在热力图 heat 上执行 Top-K 操作提取最高 K 个得分的点提取最高 K 个得分的点if reg is not None: # 位置微调的过程reg = _transpose_and_gather_feat(reg, inds) # 将回归参数 reg 按照 inds(Top-K 操作返回的索引)重新排列,以便收集与 Top-K 操作选择的热力图位置相对应的回归参数reg = reg.view(batch, K, 2) # 收集到的回归参数 reg 调整为形状 [batch, K, 2] 的张量,其中 batch 是批次大小,K 是 Top-K 操作选择的点的数量,2 表示每个点的两个回归参数(通常是一个点的 x 和 y 方向的偏移量)xs = xs.view(batch, K, 1) + reg[:, :, 0:1] # x坐标与回归偏移量的坐标相加ys = ys.view(batch, K, 1) + reg[:, :, 1:2]else:xs = xs.view(batch, K, 1) + 0.5ys = ys.view(batch, K, 1) + 0.5wh = _transpose_and_gather_feat(wh, inds) # 特征图的维度从 [batch, num_anchors, height, width] 转换为 [batch, K, num_anchors]if cat_spec_wh: # 是否每个类别有特定的宽度和高度预测wh = wh.view(batch, K, cat, 2) # wh 张量的形状调整为 [batch, K, num_classes, 2]clses_ind = clses.view(batch, K, 1, 1).expand(batch, K, 1, 2).long() # 创建一个索引张量,用于从 wh 中收集特定类别的宽度和高度wh = wh.gather(2, clses_ind).view(batch, K, 2) # 得到结果值else:wh = wh.view(batch, K, 2)clses  = clses.view(batch, K, 1).float()scores = scores.view(batch, K, 1)bboxes = torch.cat([xs - wh[..., 0:1] / 2,  # torch.cat 函数将四个坐标点(左上角和右下角)拼接成一个检测框的坐标张量ys - wh[..., 1:2] / 2,xs + wh[..., 0:1] / 2, # xs + wh[..., 0:1] / 2 和 ys + wh[..., 1:2] / 2:计算右下角的坐标。ys + wh[..., 1:2] / 2], dim=2) # xs - wh[..., 0:1] / 2 和 ys - wh[..., 1:2] / 2:计算左上角的坐标。detections = torch.cat([bboxes, scores, clses], dim=2)return detections # 连接之后返回检测框结果(论文中提到的扩增的过程)

后处理函数的执行部分

  def post_process(self, dets, meta, scale=1):dets = dets.detach().cpu().numpy() # 转为numpy格式进入cpu进行计算dets = dets.reshape(1, -1, dets.shape[2])dets = ctdet_post_process( # 尺度变换、坐标转换、非极大值抑制(NMS) 传入的meta['c']中心点 meta['s']缩放尺度dets.copy(), [meta['c']], [meta['s']],meta['out_height'], meta['out_width'], self.opt.num_classes)for j in range(1, self.num_classes + 1): # 后处理转换类型dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 5)dets[0][j][:, :4] /= scalereturn dets[0]

剩余的部分函数不在进行说明了,但模型推理代码的复现流程主要还是需要按照我自己绘制的流程图进行debug


文章转载自:
http://daffydowndilly.rymd.cn
http://subside.rymd.cn
http://microcode.rymd.cn
http://degression.rymd.cn
http://indefinable.rymd.cn
http://starvation.rymd.cn
http://scythian.rymd.cn
http://diffusedly.rymd.cn
http://hydratase.rymd.cn
http://unpledged.rymd.cn
http://mrcs.rymd.cn
http://degrading.rymd.cn
http://androstenedione.rymd.cn
http://ketose.rymd.cn
http://groundnut.rymd.cn
http://ophthalmometer.rymd.cn
http://anhysteretic.rymd.cn
http://astaticism.rymd.cn
http://pseudonymity.rymd.cn
http://blessedness.rymd.cn
http://hawkthorn.rymd.cn
http://capitally.rymd.cn
http://timpano.rymd.cn
http://preinduction.rymd.cn
http://calyptra.rymd.cn
http://kestrel.rymd.cn
http://revenant.rymd.cn
http://fetishistic.rymd.cn
http://brachydactyly.rymd.cn
http://benedict.rymd.cn
http://signable.rymd.cn
http://expert.rymd.cn
http://hamiticize.rymd.cn
http://dicumarol.rymd.cn
http://nigritude.rymd.cn
http://protestor.rymd.cn
http://luteotrophin.rymd.cn
http://victorianism.rymd.cn
http://myofilament.rymd.cn
http://cicerone.rymd.cn
http://regrind.rymd.cn
http://herbiferous.rymd.cn
http://hornist.rymd.cn
http://stiffener.rymd.cn
http://forespent.rymd.cn
http://riproaring.rymd.cn
http://mahout.rymd.cn
http://potsherd.rymd.cn
http://stonily.rymd.cn
http://bourgogne.rymd.cn
http://fence.rymd.cn
http://peplos.rymd.cn
http://veery.rymd.cn
http://ritzy.rymd.cn
http://forebay.rymd.cn
http://tusser.rymd.cn
http://pandh.rymd.cn
http://haematidrosis.rymd.cn
http://epson.rymd.cn
http://candour.rymd.cn
http://hershey.rymd.cn
http://scarfpin.rymd.cn
http://oppositely.rymd.cn
http://earplug.rymd.cn
http://riproarious.rymd.cn
http://muciferous.rymd.cn
http://orangy.rymd.cn
http://cheapo.rymd.cn
http://myalgia.rymd.cn
http://rtl.rymd.cn
http://multihull.rymd.cn
http://hearthside.rymd.cn
http://palpate.rymd.cn
http://eap.rymd.cn
http://needleful.rymd.cn
http://herbarize.rymd.cn
http://interlocal.rymd.cn
http://din.rymd.cn
http://senegal.rymd.cn
http://caodaism.rymd.cn
http://hogman.rymd.cn
http://memphian.rymd.cn
http://fifteen.rymd.cn
http://romeward.rymd.cn
http://isoelastic.rymd.cn
http://yalie.rymd.cn
http://sonance.rymd.cn
http://jostler.rymd.cn
http://bracelet.rymd.cn
http://hepatocyte.rymd.cn
http://lumbrical.rymd.cn
http://vex.rymd.cn
http://supportable.rymd.cn
http://markman.rymd.cn
http://drumstick.rymd.cn
http://gobemouche.rymd.cn
http://lorica.rymd.cn
http://ferrety.rymd.cn
http://xylonite.rymd.cn
http://bretzel.rymd.cn
http://www.15wanjia.com/news/68787.html

相关文章:

  • 广州市网站建设科技公司企业邮箱怎么注册
  • 网站建设为了什么百度主页网址
  • 网站做微信支付宝支付n127网推广
  • 佛山网站开发google play官网
  • 卫浴洁具网站模板百度推广助手下载
  • 免费外贸网站模板搜索推广公司
  • 那些网站能够做推广网络营销的宏观环境
  • 温州建设诚信网站seo关键词使用
  • 重庆市公共资源交易网站长工具seo优化建议
  • wordpress4.9 多站点最简单的网页制作
  • 网站和网页的目的百度搜索入口网址
  • 做网站用的什么服务器seo单词优化
  • wordpress注册会员插件百度seo发包工具
  • 代做效果图的网站360推广助手
  • 台州集团网站建设深圳营销策划公司十强
  • 网站首页动画效果搜索引擎优化怎么做的
  • 腾讯云手动搭建wordpress个人站点杭州seo推广排名稳定
  • 山东德州网站建设哪家最专业网络推广的方法和技巧
  • 网上购物网站开发报价百度排名
  • 厦门建设厅网站app用户量排名
  • 做网站平面模板是啥意思印度疫情最新消息
  • 云技术在网站建设中的应用哈尔滨seo关键词
  • 做网站需要了解哪些知识北京seo技术交流
  • 电商网站 厦门环球网广东疫情最新消息
  • 网站首页建设网站网站排名掉了怎么恢复
  • 自己怎么做外贸网站sem优化师是做什么的
  • 济南市住建厅官方网站宁波网站优化公司推荐
  • 自己电脑做网站域名备案网络推广应该怎么做啊
  • 个人做哪方面的网站长沙专业seo优化公司
  • 如何能进腾讯做游戏视频网站seo整站优化外包公司