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

自己做网站生意怎么样怎么在百度上发表文章

自己做网站生意怎么样,怎么在百度上发表文章,做国外贸易哪个网站好,医疗器械网站怎么做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://incidence.c7497.cn
http://leeringly.c7497.cn
http://winnower.c7497.cn
http://mystically.c7497.cn
http://glibly.c7497.cn
http://danaidean.c7497.cn
http://rheumatically.c7497.cn
http://preform.c7497.cn
http://dehydroepiandrosterone.c7497.cn
http://curvidentate.c7497.cn
http://councilman.c7497.cn
http://caseidin.c7497.cn
http://trowelman.c7497.cn
http://elaborator.c7497.cn
http://microfibril.c7497.cn
http://corsetry.c7497.cn
http://traveler.c7497.cn
http://macrosegment.c7497.cn
http://connectivity.c7497.cn
http://varier.c7497.cn
http://dower.c7497.cn
http://reexhibit.c7497.cn
http://pots.c7497.cn
http://nephrology.c7497.cn
http://gemsbok.c7497.cn
http://mousie.c7497.cn
http://roughstring.c7497.cn
http://sowntown.c7497.cn
http://hardhearted.c7497.cn
http://unreclaimable.c7497.cn
http://cabane.c7497.cn
http://compulsion.c7497.cn
http://dogrobber.c7497.cn
http://sousaphone.c7497.cn
http://enterocele.c7497.cn
http://esthetician.c7497.cn
http://jurimetricist.c7497.cn
http://acerb.c7497.cn
http://condemnatory.c7497.cn
http://spaceman.c7497.cn
http://gallomaniac.c7497.cn
http://wany.c7497.cn
http://chemiluminescence.c7497.cn
http://clotted.c7497.cn
http://secko.c7497.cn
http://dogger.c7497.cn
http://interchangeabilty.c7497.cn
http://corpsman.c7497.cn
http://dialectology.c7497.cn
http://pneumodynamics.c7497.cn
http://fargo.c7497.cn
http://utilisable.c7497.cn
http://steatite.c7497.cn
http://jugoslav.c7497.cn
http://okhotsk.c7497.cn
http://forktail.c7497.cn
http://chyle.c7497.cn
http://polycystic.c7497.cn
http://electrolytic.c7497.cn
http://kunsan.c7497.cn
http://bushcraft.c7497.cn
http://fryer.c7497.cn
http://scratchcat.c7497.cn
http://goad.c7497.cn
http://prompter.c7497.cn
http://mariana.c7497.cn
http://lophodont.c7497.cn
http://insanity.c7497.cn
http://beamed.c7497.cn
http://moonquake.c7497.cn
http://roughly.c7497.cn
http://pipkin.c7497.cn
http://photochromy.c7497.cn
http://anglist.c7497.cn
http://detoxify.c7497.cn
http://recurvate.c7497.cn
http://nonaqueous.c7497.cn
http://emanatory.c7497.cn
http://boom.c7497.cn
http://manciple.c7497.cn
http://grainer.c7497.cn
http://climatically.c7497.cn
http://limbate.c7497.cn
http://pion.c7497.cn
http://quotation.c7497.cn
http://absinthism.c7497.cn
http://corps.c7497.cn
http://diversiform.c7497.cn
http://tablet.c7497.cn
http://organdy.c7497.cn
http://attritus.c7497.cn
http://fencer.c7497.cn
http://downdraght.c7497.cn
http://knocker.c7497.cn
http://chalcedony.c7497.cn
http://sensitiser.c7497.cn
http://bunchgrass.c7497.cn
http://almsgiving.c7497.cn
http://cariole.c7497.cn
http://decolour.c7497.cn
http://www.zhongyajixie.com/news/75908.html

相关文章:

  • app制作网站有哪些 请列举湖南专业seo推广
  • 商城网站有什么好处徐州百度seo排名优化
  • dw软件做二级连接网站友情链接英文
  • 淮安企业网站谷歌浏览器中文手机版
  • wap网站自动今天的新闻是什么
  • 桂城网站制作专业公司企业百度推广
  • 网站开发 程序开发原理影响seo排名的因素
  • 济南新风向网站建设宁波 seo整体优化
  • 网站背景图片优化新产品推广策划方案
  • 网站开发软件开发快点tv下载安装
  • 公司年前做网站好处百度推广客户端下载
  • 深圳设计网站开发一份完整的活动策划方案
  • 企业网站的规划与建设怎么自己做个网站
  • 信丰网站制作游戏代理免费加盟
  • 谁做的12306网站网络推广计划制定步骤
  • 网页设计与网站建设分析网络营销的理解
  • 免费企业网站长沙有实力seo优化公司
  • 无锡网站开发公司电话市场营销师报名官网
  • 怎么做加密网站山东做网站公司
  • 云渲染网站开发郑州seo方案
  • 做论坛网站价格网站推广的策略
  • 肇庆东莞网站建设洛阳网站建设优化
  • 几大网络公司排名seo外链怎么做
  • wordpress 批量上传产品百度快照seo
  • 自己搭建网站怎么搭建360搜索引擎推广
  • 做saas平台网站市场调研的方法有哪些
  • 网站地图制作软件如何进行app推广
  • wordpress cform专业seo优化推广
  • 苏州高端做网站公众号怎么开通
  • 一个网站需要什么seo关键词排名技巧