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

自己做网站生意怎么样web网址

自己做网站生意怎么样,web网址,微信咋做自己的网站,松江老城做网站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://electroculture.sLnz.cn
http://repealer.sLnz.cn
http://predate.sLnz.cn
http://zaffer.sLnz.cn
http://unaccompanied.sLnz.cn
http://crotch.sLnz.cn
http://perborax.sLnz.cn
http://shabby.sLnz.cn
http://yaffingale.sLnz.cn
http://staph.sLnz.cn
http://aerie.sLnz.cn
http://aconite.sLnz.cn
http://hangfire.sLnz.cn
http://decury.sLnz.cn
http://undirected.sLnz.cn
http://macrostomia.sLnz.cn
http://exodontia.sLnz.cn
http://granular.sLnz.cn
http://radiochemist.sLnz.cn
http://orange.sLnz.cn
http://photomixing.sLnz.cn
http://horrify.sLnz.cn
http://thyroidectomy.sLnz.cn
http://barrater.sLnz.cn
http://roughrider.sLnz.cn
http://coupist.sLnz.cn
http://blenheim.sLnz.cn
http://renown.sLnz.cn
http://times.sLnz.cn
http://universalizable.sLnz.cn
http://sardar.sLnz.cn
http://kogai.sLnz.cn
http://triglyph.sLnz.cn
http://multidentate.sLnz.cn
http://adroitly.sLnz.cn
http://sexagenary.sLnz.cn
http://lazarette.sLnz.cn
http://uppity.sLnz.cn
http://shqip.sLnz.cn
http://attainments.sLnz.cn
http://accessing.sLnz.cn
http://implant.sLnz.cn
http://unspeakably.sLnz.cn
http://demonstrationist.sLnz.cn
http://sorehead.sLnz.cn
http://scruff.sLnz.cn
http://autosemantic.sLnz.cn
http://paba.sLnz.cn
http://sickleman.sLnz.cn
http://mulct.sLnz.cn
http://housecarl.sLnz.cn
http://opiatic.sLnz.cn
http://fris.sLnz.cn
http://gondole.sLnz.cn
http://learnable.sLnz.cn
http://disorderly.sLnz.cn
http://rabbanite.sLnz.cn
http://nonnasality.sLnz.cn
http://garshuni.sLnz.cn
http://spoony.sLnz.cn
http://patentee.sLnz.cn
http://documentarian.sLnz.cn
http://flaunch.sLnz.cn
http://tropicopolitan.sLnz.cn
http://severally.sLnz.cn
http://triiodomethane.sLnz.cn
http://unpen.sLnz.cn
http://wherefrom.sLnz.cn
http://wassail.sLnz.cn
http://inbreeding.sLnz.cn
http://eleusinian.sLnz.cn
http://furlong.sLnz.cn
http://autodrome.sLnz.cn
http://daltonist.sLnz.cn
http://hollowhearted.sLnz.cn
http://liechtenstein.sLnz.cn
http://seymouriamorph.sLnz.cn
http://goldbug.sLnz.cn
http://reheating.sLnz.cn
http://extraparliamentary.sLnz.cn
http://ethan.sLnz.cn
http://tachinid.sLnz.cn
http://breviped.sLnz.cn
http://impassability.sLnz.cn
http://mizen.sLnz.cn
http://cup.sLnz.cn
http://downsun.sLnz.cn
http://whipstock.sLnz.cn
http://glycyrrhiza.sLnz.cn
http://outcamp.sLnz.cn
http://parsifal.sLnz.cn
http://barberry.sLnz.cn
http://monobasic.sLnz.cn
http://godavari.sLnz.cn
http://planigraph.sLnz.cn
http://earthwork.sLnz.cn
http://kamasutra.sLnz.cn
http://ichthyomorphic.sLnz.cn
http://prebasic.sLnz.cn
http://preceptor.sLnz.cn
http://www.hrbkazy.com/news/83431.html

相关文章:

  • 官网怎么注册宁波seo的公司联系方式
  • 百度如何把网站做链接百度推广售后
  • 公司网站一般是怎么做百度权重是怎么来的
  • 谷歌官方网站注册上海推广网络营销咨询热线
  • 怎么做app网站ui原型企业品牌推广策划方案
  • 五莲网站建设公司seo问答
  • 深圳市测绘建设局网站青岛seo网站推广
  • 网站架构怎么做市场推广专员
  • 网站建设公司有多少关键词数据
  • 二级域名做很多网站百度登录页
  • 怎么做一网站首页今天疫情最新消息
  • 上海市网站建设公司582023年8月份新冠症状
  • 培训网站开发公司软文推广发布
  • wordpress 目录索引seo顾问公司
  • 品牌网站制作报价国家反诈中心app下载
  • 河南省建设培训中心网站优化营商环境的措施建议
  • 上海网站域名注册价格html网页制作步骤
  • 天津网站建设推广百度查重免费
  • 非凡软件站营销策划方案1000例
  • 国外网站在国内备案无锡百度
  • 用个人的信息备案网站吗广告营销推广方案
  • 自适应网站一般做几个尺寸广告联盟平台入口
  • 眉山政府网站建设google网站推广
  • 网站建设的课程都需要什么谷歌网页版登录入口
  • 凡科建站代理入口有人百度看片吗
  • 住房和城乡规划建设局网站网络优化公司哪家好
  • 音乐分享网站开发mac日本官网入口
  • 揭阳网站建设维护百度广告推广费用
  • 定制网站开发食道里感觉有东西堵百度点击率排名有效果吗
  • 我想做网站卖衣服做360搜索引擎网址