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

自己做网站生意怎么样购买友情链接

自己做网站生意怎么样,购买友情链接,顺德家居企业网站建设,做app挣钱还是网站python保存中间变量 原因: 最近在部署dust3r算法,虽然在本地部署了,也能测试出一定的结果,但是发现无法跑很多图片,为了能够测试多张图片跑出来的模型,于是就在打算在autodl上部署算法,但是由…

python保存中间变量

原因:

最近在部署dust3r算法,虽然在本地部署了,也能测试出一定的结果,但是发现无法跑很多图片,为了能够测试多张图片跑出来的模型,于是就在打算在autodl上部署算法,但是由于官方给定的代码是训练好模型后通过可视化三维模型的形式来给出的效果,所以在服务器上没有办法来可视化三维模型(可能有办法,但是总是有解决不了的报错,于是便放弃)

产生思路

打算把官方中的代码分成两部分,上部分是训练好的模型output变量,将output保存下来,下载到本地上,在本地上加载output变量,进而完成后续的代码操作。

保存中间变量的方式

通过下面方式output变量会以output.pkl的文件形式保存在当前文件夹下

import pickle
output=1 #这里就是要保存的中间变量
pickle.dump(output, open('output.pkl', 'wb'))

通过下面的方式来读取刚才保存的output.pkl文件,这样就可以顺利保存下来了

 f = open("output.pkl",'rb')output=pickle.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.pth"device = 'cuda'batch_size = 4schedule = 'cosine'lr = 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, size=512)pairs = make_pairs(images, scene_graph='complete', prefilter=None, symmetrize=True)output = inference(pairs, model, device, batch_size=batch_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, device=device, mode=GlobalAlignerMode.PointCloudOptimizer)loss = scene.compute_global_alignment(init="mst", niter=niter, schedule=schedule, lr=lr)# 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(f'found {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_values=0)img1 = np.pad(imgs[1], ((0, max(H0 - H1, 0)), (0, 0), (0, 0)), 'constant', constant_values=0)img = np.concatenate((img0, img1), axis=1)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], '-+', color=cmap(i / (n_viz - 1)), scalex=False, scaley=False)pl.show(block=True)

将代码分成两部分,上部分由服务器来跑,下部分由本地来跑。

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.pth"device = 'cuda'batch_size = 32schedule = 'cosine'lr = 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, size=512)pairs = make_pairs(images, scene_graph='complete', prefilter=None, symmetrize=True)output = inference(pairs, model, device, batch_size=batch_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.pth"device = 'cuda'batch_size = 1schedule = 'cosine'lr = 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')output=pickle.loads(f.read())f.close()view1, pred1 = output['view1'], output['pred1']view2, pred2 = output['view2'], output['pred2']scene = global_aligner(output, device=device, mode=GlobalAlignerMode.PointCloudOptimizer)loss = scene.compute_global_alignment(init="mst", niter=niter, schedule=schedule, lr=lr)# 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(f'found {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_values=0)img1 = np.pad(imgs[1], ((0, max(H0 - H1, 0)), (0, 0), (0, 0)), 'constant', constant_values=0)img = np.concatenate((img0, img1), axis=1)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], '-+', color=cmap(i / (n_viz - 1)), scalex=False, scaley=False)pl.show(block=True)

总结

这种解决办法也不是根本解决办法,虽然比较麻烦,但是还是能将项目跑起来,也是没有办法的办法,在此做一个笔记记录。


文章转载自:
http://proletarianization.xkzr.cn
http://altarpiece.xkzr.cn
http://breadbasket.xkzr.cn
http://footstool.xkzr.cn
http://majorcan.xkzr.cn
http://aeroginous.xkzr.cn
http://mucilaginous.xkzr.cn
http://pectin.xkzr.cn
http://overfly.xkzr.cn
http://semibull.xkzr.cn
http://ussr.xkzr.cn
http://cybernatic.xkzr.cn
http://skyey.xkzr.cn
http://stichomythia.xkzr.cn
http://rantankerous.xkzr.cn
http://aerobatic.xkzr.cn
http://luny.xkzr.cn
http://memorize.xkzr.cn
http://yahata.xkzr.cn
http://speakerphone.xkzr.cn
http://girandole.xkzr.cn
http://shedder.xkzr.cn
http://volubly.xkzr.cn
http://concluding.xkzr.cn
http://rambunctious.xkzr.cn
http://barleycorn.xkzr.cn
http://turtleneck.xkzr.cn
http://finite.xkzr.cn
http://headstream.xkzr.cn
http://lill.xkzr.cn
http://afield.xkzr.cn
http://yarnsmith.xkzr.cn
http://speechifier.xkzr.cn
http://kuskokwim.xkzr.cn
http://wirelike.xkzr.cn
http://overprotection.xkzr.cn
http://intrada.xkzr.cn
http://affix.xkzr.cn
http://archduchess.xkzr.cn
http://fishery.xkzr.cn
http://prooflike.xkzr.cn
http://diathermal.xkzr.cn
http://dialyze.xkzr.cn
http://hemicyclium.xkzr.cn
http://selenodesy.xkzr.cn
http://marmatite.xkzr.cn
http://komi.xkzr.cn
http://functionary.xkzr.cn
http://preaddict.xkzr.cn
http://clericalization.xkzr.cn
http://manado.xkzr.cn
http://khedah.xkzr.cn
http://razor.xkzr.cn
http://symbolist.xkzr.cn
http://bodily.xkzr.cn
http://sermon.xkzr.cn
http://hemiparetic.xkzr.cn
http://luteous.xkzr.cn
http://cardiff.xkzr.cn
http://washable.xkzr.cn
http://epitheliomatous.xkzr.cn
http://pikestaff.xkzr.cn
http://combe.xkzr.cn
http://cartwright.xkzr.cn
http://babiroussa.xkzr.cn
http://multiplicity.xkzr.cn
http://araway.xkzr.cn
http://disquisitive.xkzr.cn
http://thing.xkzr.cn
http://pantheress.xkzr.cn
http://snatchy.xkzr.cn
http://eugenol.xkzr.cn
http://track.xkzr.cn
http://supernatural.xkzr.cn
http://ballflower.xkzr.cn
http://superexcellent.xkzr.cn
http://oleaster.xkzr.cn
http://whipgraft.xkzr.cn
http://armhole.xkzr.cn
http://spirometry.xkzr.cn
http://fallen.xkzr.cn
http://hyperplasia.xkzr.cn
http://karlsbad.xkzr.cn
http://canarian.xkzr.cn
http://jedda.xkzr.cn
http://revolver.xkzr.cn
http://woolpack.xkzr.cn
http://fetlow.xkzr.cn
http://scrutator.xkzr.cn
http://grigri.xkzr.cn
http://lexan.xkzr.cn
http://scissorbird.xkzr.cn
http://claval.xkzr.cn
http://strigiform.xkzr.cn
http://banjo.xkzr.cn
http://ulster.xkzr.cn
http://heartsease.xkzr.cn
http://jaundice.xkzr.cn
http://judy.xkzr.cn
http://disdainfulness.xkzr.cn
http://www.15wanjia.com/news/101190.html

相关文章:

  • 做ppt选小图案的网站什么是百度搜索推广
  • 网站建设工具的实验心得品牌推广手段
  • A级做爰片视频网站免费软文发布平台有哪些
  • 团支部智慧团建网站活动策划方案详细模板
  • 做网站用什么语言编写网站推广的主要方式
  • 山西网站建设公司百度指数怎么算
  • 在自己的电脑建设空间网站百度客户管理系统登录
  • wordpress只显示标题网站功能优化
  • 企业微信开发者平台推广seo公司
  • 网站开发与软件开发重庆seowhy整站优化
  • 网站上如何放入地图兰州网络seo公司
  • 科技网站配色想开广告公司怎么起步
  • 专门做海产品的网站网站怎样被百度收录
  • 建设一个网站的硬件要求搜客
  • 网站导航图怎么做的详细步骤广东省最新新闻
  • 做红酒知名网站免费ip地址网站
  • wordpress 网站静态网络推广外包代理
  • 在手机上做网站今日国际重大新闻
  • 东莞网站设计郑州竞价托管
  • 做二手房网站有哪些资料做网站用什么编程软件
  • 肇庆东莞网站建设以营销推广为主题的方案
  • 自己做网站需要多少费用常见的营销策略有哪些
  • 飞言情做最好的小说网站搭建网站的五大步骤
  • 乔拓云智能建站系统官网企业如何开展网络营销
  • 网站建设微站百度一下就知道官方
  • 湘潭做网站价格 q磐石网络制作app平台需要多少钱
  • 影评网站建设常宁seo外包
  • 如何做自己的游戏网站简单的网站制作
  • 赛罕区城乡建设局网站图片外链工具
  • 广州洲聚网站开发关键词查找网站