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

网站访问人数代码衡阳建设网站

网站访问人数代码,衡阳建设网站,网站如何制作注册,网页托管平台排名python保存中间变量 原因#xff1a; 最近在部署dust3r算法#xff0c;虽然在本地部署了#xff0c;也能测试出一定的结果#xff0c;但是发现无法跑很多图片#xff0c;为了能够测试多张图片跑出来的模型#xff0c;于是就在打算在autodl上部署算法#xff0c;但是由…python保存中间变量 原因 最近在部署dust3r算法虽然在本地部署了也能测试出一定的结果但是发现无法跑很多图片为了能够测试多张图片跑出来的模型于是就在打算在autodl上部署算法但是由于官方给定的代码是训练好模型后通过可视化三维模型的形式来给出的效果所以在服务器上没有办法来可视化三维模型可能有办法但是总是有解决不了的报错于是便放弃 产生思路 打算把官方中的代码分成两部分上部分是训练好的模型output变量将output保存下来下载到本地上在本地上加载output变量进而完成后续的代码操作。 保存中间变量的方式 通过下面方式output变量会以output.pkl的文件形式保存在当前文件夹下 import pickle output1 #这里就是要保存的中间变量 pickle.dump(output, open(output.pkl, wb))通过下面的方式来读取刚才保存的output.pkl文件这样就可以顺利保存下来了 f open(output.pkl,rb)outputpickle.loads(f.read())f.close()原理 pickle是Python官方自带的库提供dump函数实现Python对象的保存。支持自定义的对象非常方便。Pandas的DataFrame和Obspy的Stream也都可以保存成pickle的格式。主要是以二进制的形式来保存成一种无逻辑的文件。 解决原来的问题 dust3r官方给的代码如下其中服务器主要是在scene.show()这行代码中无法运行。 import osfrom dust3r.inference import inference, load_model from dust3r.utils.image import load_images from dust3r.image_pairs import make_pairs from dust3r.cloud_opt import global_aligner, GlobalAlignerModeif __name__ __main__:model_path checkpoints/DUSt3R_ViTLarge_BaseDecoder_512_dpt.pthdevice cudabatch_size 4schedule cosinelr 0.01niter 100model load_model(model_path, device)# load_images can take a list of images or a directory# base_dir tankandtemples/tankandtemples/intermediate/M60/images/base_dir croco/assets/# 获取当前目录下的所有文件files [os.path.join(base_dir, file) for file in os.listdir(base_dir)]images load_images(files, size512)pairs make_pairs(images, scene_graphcomplete, prefilterNone, symmetrizeTrue)output inference(pairs, model, device, batch_sizebatch_size)# at this stage, you have the raw dust3r predictionsview1, pred1 output[view1], output[pred1]view2, pred2 output[view2], output[pred2]scene global_aligner(output, devicedevice, modeGlobalAlignerMode.PointCloudOptimizer)loss scene.compute_global_alignment(initmst, niterniter, scheduleschedule, lrlr)# retrieve useful values from scene:imgs scene.imgsfocals scene.get_focals()poses scene.get_im_poses()pts3d scene.get_pts3d()confidence_masks scene.get_masks()# visualize reconstructionscene.show()# find 2D-2D matches between the two imagesfrom dust3r.utils.geometry import find_reciprocal_matches, xy_gridpts2d_list, pts3d_list [], []for i in range(2):conf_i confidence_masks[i].cpu().numpy()pts2d_list.append(xy_grid(*imgs[i].shape[:2][::-1])[conf_i]) # imgs[i].shape[:2] (H, W)pts3d_list.append(pts3d[i].detach().cpu().numpy()[conf_i])reciprocal_in_P2, nn2_in_P1, num_matches find_reciprocal_matches(*pts3d_list)print(ffound {num_matches} matches)matches_im1 pts2d_list[1][reciprocal_in_P2]matches_im0 pts2d_list[0][nn2_in_P1][reciprocal_in_P2]# visualize a few matchesimport numpy as npfrom matplotlib import pyplot as pln_viz 10match_idx_to_viz np.round(np.linspace(0, num_matches-1, n_viz)).astype(int)viz_matches_im0, viz_matches_im1 matches_im0[match_idx_to_viz], matches_im1[match_idx_to_viz]H0, W0, H1, W1 *imgs[0].shape[:2], *imgs[1].shape[:2]img0 np.pad(imgs[0], ((0, max(H1 - H0, 0)), (0, 0), (0, 0)), constant, constant_values0)img1 np.pad(imgs[1], ((0, max(H0 - H1, 0)), (0, 0), (0, 0)), constant, constant_values0)img np.concatenate((img0, img1), axis1)pl.figure()pl.imshow(img)cmap pl.get_cmap(jet)for i in range(n_viz):(x0, y0), (x1, y1) viz_matches_im0[i].T, viz_matches_im1[i].Tpl.plot([x0, x1 W0], [y0, y1], -, colorcmap(i / (n_viz - 1)), scalexFalse, scaleyFalse)pl.show(blockTrue) 将代码分成两部分上部分由服务器来跑下部分由本地来跑。 import os from dust3r.inference import inference, load_model from dust3r.utils.image import load_images from dust3r.image_pairs import make_pairs from dust3r.cloud_opt import global_aligner, GlobalAlignerMode if __name__ __main__:model_path checkpoints/DUSt3R_ViTLarge_BaseDecoder_512_dpt.pthdevice cudabatch_size 32schedule cosinelr 0.01niter 300model load_model(model_path, device)# load_images can take a list of images or a directorybase_dir croco/assets/# 获取当前目录下的所有文件files [os.path.join(base_dir, file) for file in os.listdir(base_dir)]files_new []for i in range(0,files.__len__(),10):files_new.append(files[i])images load_images(files_new, size512)pairs make_pairs(images, scene_graphcomplete, prefilterNone, symmetrizeTrue)output inference(pairs, model, device, batch_sizebatch_size)import picklepickle.dump(output, open(output.pkl, wb))本地代码 import os from dust3r.inference import inference, load_model from dust3r.utils.image import load_images from dust3r.image_pairs import make_pairs from dust3r.cloud_opt import global_aligner, GlobalAlignerMode if __name__ __main__:model_path checkpoints/DUSt3R_ViTLarge_BaseDecoder_512_dpt.pthdevice cudabatch_size 1schedule cosinelr 0.01niter 300base_dir croco/assets/# 获取当前目录下的所有文件files [os.path.join(base_dir, file) for file in os.listdir(base_dir)]files_new []for i in range(0,files.__len__(),4):files_new.append(files[i])print(files_new)import picklef open(output.pkl,rb)outputpickle.loads(f.read())f.close()view1, pred1 output[view1], output[pred1]view2, pred2 output[view2], output[pred2]scene global_aligner(output, devicedevice, modeGlobalAlignerMode.PointCloudOptimizer)loss scene.compute_global_alignment(initmst, niterniter, scheduleschedule, lrlr)# retrieve useful values from scene:imgs scene.imgsfocals scene.get_focals()poses scene.get_im_poses()pts3d scene.get_pts3d()confidence_masks scene.get_masks()# visualize reconstructionscene.show()# find 2D-2D matches between the two imagesfrom dust3r.utils.geometry import find_reciprocal_matches, xy_gridpts2d_list, pts3d_list [], []for i in range(2):conf_i confidence_masks[i].cpu().numpy()pts2d_list.append(xy_grid(*imgs[i].shape[:2][::-1])[conf_i]) # imgs[i].shape[:2] (H, W)pts3d_list.append(pts3d[i].detach().cpu().numpy()[conf_i])reciprocal_in_P2, nn2_in_P1, num_matches find_reciprocal_matches(*pts3d_list)print(ffound {num_matches} matches)matches_im1 pts2d_list[1][reciprocal_in_P2]matches_im0 pts2d_list[0][nn2_in_P1][reciprocal_in_P2]# visualize a few matchesimport numpy as npfrom matplotlib import pyplot as pln_viz 10match_idx_to_viz np.round(np.linspace(0, num_matches-1, n_viz)).astype(int)viz_matches_im0, viz_matches_im1 matches_im0[match_idx_to_viz], matches_im1[match_idx_to_viz]H0, W0, H1, W1 *imgs[0].shape[:2], *imgs[1].shape[:2]img0 np.pad(imgs[0], ((0, max(H1 - H0, 0)), (0, 0), (0, 0)), constant, constant_values0)img1 np.pad(imgs[1], ((0, max(H0 - H1, 0)), (0, 0), (0, 0)), constant, constant_values0)img np.concatenate((img0, img1), axis1)pl.figure()pl.imshow(img)cmap pl.get_cmap(jet)for i in range(n_viz):(x0, y0), (x1, y1) viz_matches_im0[i].T, viz_matches_im1[i].Tpl.plot([x0, x1 W0], [y0, y1], -, colorcmap(i / (n_viz - 1)), scalexFalse, scaleyFalse)pl.show(blockTrue)总结 这种解决办法也不是根本解决办法虽然比较麻烦但是还是能将项目跑起来也是没有办法的办法在此做一个笔记记录。
http://www.pierceye.com/news/664228/

相关文章:

  • 手机上怎么创建自己的网站河南企业网站优化
  • 定陶区城乡和住房建设局网站新手怎么做网站
  • 工商银行与建设银行网站对比石嘴山网站seo
  • seo快速建站自学程序员的步骤
  • 做旅行网站的依据及意义如何制作自己想要的图片
  • 电子商务网站怎么做网站建设企业建站哪家好?来这里看看
  • 网站备案电话号码购物商城网站建设方案
  • 手机商城系统徐州seo计费管理
  • 西安网站公司哪家好信息推广的方式有哪些
  • 网站开发注意的事项商丘网站制作软件
  • 51zwd一起做网站广州广东省网站备案查询
  • 如何生成一个网站自己弄公司网站
  • 企业信用信息查询网官网孝感网站seo
  • 中淼建设工程有限公司网站分类用wordpress
  • 腾讯建设网站首页做销售网站
  • 推广引流网站聚名网注册
  • 原来做网站后来跑国外了多伦多网站建设多少钱
  • 手机建站平台做母婴网站设计思路
  • 免费个人手机网站九八智能建站
  • 中山网站备案如何做购物网站
  • 常见的简单的网站制作建设网站的好公司
  • 邯郸网站制作建设wordpress+怎么迁移
  • 设计创意广告上海企业网站优化
  • 自己做网站需要购买服务器吗WordPress文章相册修改
  • 校园招聘哪个网站做的好学做川菜网站
  • 大足网站建设公司医院网站建设熊掌号
  • 做网站编辑是不是也要做推广做蛋白go分析网站
  • 免费品牌网站制作云南电商网站建设
  • 宿迁莱布拉网站建设常州做网站建设的公司
  • 广东网站建站系统哪家好常州网站搭建公司