update for lite version of pytorch3d

update pytorch3d to lite version that uses a slimmed down repo only containing what we need
pull/15/head
MSFTserver 3 years ago
parent 92d90c0666
commit 3735124ac3
  1. 16
      disco.py
  2. 6
      disco_xform_utils.py

@ -384,6 +384,7 @@ if is_colab:
#gitclone("https://github.com/facebookresearch/SLIP.git") #gitclone("https://github.com/facebookresearch/SLIP.git")
gitclone("https://github.com/crowsonkb/guided-diffusion") gitclone("https://github.com/crowsonkb/guided-diffusion")
gitclone("https://github.com/assafshocher/ResizeRight.git") gitclone("https://github.com/assafshocher/ResizeRight.git")
gitclone("https://github.com/MSFTserver/pytorch3d-lite.git")
pipie("./CLIP") pipie("./CLIP")
pipie("./guided-diffusion") pipie("./guided-diffusion")
multipip_res = subprocess.run(['pip', 'install', 'lpips', 'datetime', 'timm', 'ftfy'], stdout=subprocess.PIPE).stdout.decode('utf-8') multipip_res = subprocess.run(['pip', 'install', 'lpips', 'datetime', 'timm', 'ftfy'], stdout=subprocess.PIPE).stdout.decode('utf-8')
@ -409,19 +410,8 @@ if not path_exists(f'{model_path}/dpt_large-midas-2f21e586.pt'):
import sys import sys
import torch import torch
#Install pytorch3d
if is_colab:
pyt_version_str=torch.__version__.split("+")[0].replace(".", "")
version_str="".join([
f"py3{sys.version_info.minor}_cu",
torch.version.cuda.replace(".",""),
f"_pyt{pyt_version_str}"
])
multipip_res = subprocess.run(['pip', 'install', 'fvcore', 'iopath'], stdout=subprocess.PIPE).stdout.decode('utf-8')
print(multipip_res)
subprocess.run(['pip', 'install', '--no-index', '--no-cache-dir', 'pytorch3d', '-f', f'https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/{version_str}/download.html'], stdout=subprocess.PIPE).stdout.decode('utf-8')
# sys.path.append('./SLIP') # sys.path.append('./SLIP')
sys.path.append('./pytorch3d-lite')
sys.path.append('./ResizeRight') sys.path.append('./ResizeRight')
sys.path.append('./MiDaS') sys.path.append('./MiDaS')
from dataclasses import dataclass from dataclasses import dataclass
@ -625,7 +615,7 @@ def init_midas_depth_model(midas_model_type="dpt_large", optimize=True):
# https://gist.github.com/adefossez/0646dbe9ed4005480a2407c62aac8869 # https://gist.github.com/adefossez/0646dbe9ed4005480a2407c62aac8869
import pytorch3d.transforms as p3dT import py3d_tools as p3dT
import disco_xform_utils as dxf import disco_xform_utils as dxf
def interp(t): def interp(t):

@ -1,5 +1,5 @@
import torch, torchvision import torch, torchvision
import pytorch3d.renderer.cameras as p3dCam import py3d_tools as p3d
import midas_utils import midas_utils
from PIL import Image from PIL import Image
import numpy as np import numpy as np
@ -81,8 +81,8 @@ def transform_image_3d(img_filepath, midas_model, midas_transform, device, rot_m
depth_tensor = torch.from_numpy(depth_map).squeeze().to(device) depth_tensor = torch.from_numpy(depth_map).squeeze().to(device)
pixel_aspect = 1.0 # really.. the aspect of an individual pixel! (so usually 1.0) pixel_aspect = 1.0 # really.. the aspect of an individual pixel! (so usually 1.0)
persp_cam_old = p3dCam.FoVPerspectiveCameras(near, far, pixel_aspect, fov=fov_deg, degrees=True, device=device) persp_cam_old = p3d.FoVPerspectiveCameras(near, far, pixel_aspect, fov=fov_deg, degrees=True, device=device)
persp_cam_new = p3dCam.FoVPerspectiveCameras(near, far, pixel_aspect, fov=fov_deg, degrees=True, R=rot_mat, T=torch.tensor([translate]), device=device) persp_cam_new = p3d.FoVPerspectiveCameras(near, far, pixel_aspect, fov=fov_deg, degrees=True, R=rot_mat, T=torch.tensor([translate]), device=device)
# range of [-1,1] is important to torch grid_sample's padding handling # range of [-1,1] is important to torch grid_sample's padding handling
y,x = torch.meshgrid(torch.linspace(-1.,1.,h,dtype=torch.float32,device=device),torch.linspace(-1.,1.,w,dtype=torch.float32,device=device)) y,x = torch.meshgrid(torch.linspace(-1.,1.,h,dtype=torch.float32,device=device),torch.linspace(-1.,1.,w,dtype=torch.float32,device=device))

Loading…
Cancel
Save