Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expired ssl certificate #81

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ignore all kind of files
*.*
# *.*
#except php files
!*.py
!*.yml
Expand Down
2 changes: 1 addition & 1 deletion MiDaS/run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Compute depth maps for images in the input folder.
"""
"""
import os
import glob
import torch
Expand Down
14 changes: 13 additions & 1 deletion argument.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,45 @@ depth_edge_model_ckpt: checkpoints/edge-model.pth
depth_feat_model_ckpt: checkpoints/depth-model.pth
rgb_feat_model_ckpt: checkpoints/color-model.pth
MiDaS_model_ckpt: MiDaS/model.pt
fps: 40

fps: 40
num_frames: 240
x_shift_range: [0.00, 0.00, -0.02, -0.02]
y_shift_range: [0.00, 0.00, -0.02, -0.00]
z_shift_range: [-0.05, -0.05, -0.07, -0.07]

traj_types: ['double-straight-line', 'double-straight-line', 'circle', 'circle']
video_postfix: ['dolly-zoom-in', 'zoom-in', 'circle', 'swing']

specific: ''
longer_side_len: 960

src_folder: image
depth_folder: depth
mesh_folder: mesh
video_folder: video

load_ply: False
save_ply: True
inference_video: True

gpu_ids: 0

offscreen_rendering: False

img_format: '.jpg'
depth_format: '.npy'

require_midas: True

depth_threshold: 0.04
ext_edge_threshold: 0.002

sparse_iter: 5
filter_size: [7, 7, 5, 5, 5]
sigma_s: 4.0
sigma_r: 0.5

redundant_number: 12
background_thickness: 70
context_thickness: 140
Expand Down
8 changes: 4 additions & 4 deletions download.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/sh
mkdir checkpoints
wget https://filebox.ece.vt.edu/~jbhuang/project/3DPhoto/model/color-model.pth
wget --no-check-certificate https://filebox.ece.vt.edu/~jbhuang/project/3DPhoto/model/color-model.pth
mv color-model.pth checkpoints/.
wget https://filebox.ece.vt.edu/~jbhuang/project/3DPhoto/model/depth-model.pth
wget --no-check-certificate https://filebox.ece.vt.edu/~jbhuang/project/3DPhoto/model/depth-model.pth
mv depth-model.pth checkpoints/.
wget https://filebox.ece.vt.edu/~jbhuang/project/3DPhoto/model/edge-model.pth
wget --no-check-certificate https://filebox.ece.vt.edu/~jbhuang/project/3DPhoto/model/edge-model.pth
mv edge-model.pth checkpoints/.
wget https://filebox.ece.vt.edu/~jbhuang/project/3DPhoto/model/model.pt
wget --no-check-certificate https://filebox.ece.vt.edu/~jbhuang/project/3DPhoto/model/model.pt
mv model.pt MiDaS/.
Binary file added image/blackhole.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/milkyway.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/nebula.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/neowise1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/neowise2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 47 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# imports
import numpy as np
import argparse
import glob
Expand All @@ -18,44 +19,54 @@
import copy
from networks import Inpaint_Color_Net, Inpaint_Depth_Net, Inpaint_Edge_Net
from MiDaS.run import run_depth
from MiDaS.monodepth_net import MonoDepthNet
from MiDaS.monodepth_net import MonoDepthNet # model to compute depth
import MiDaS.MiDaS_utils as MiDaS_utils
from bilateral_filtering import sparse_bilateral_filtering

#wandb
import wandb
wandb.login()

# command line arguments
parser = argparse.ArgumentParser()
parser.add_argument('--config', type=str, default='argument.yml',help='Configure of post processing')
args = parser.parse_args()
config = yaml.load(open(args.config, 'r'))
if config['offscreen_rendering'] is True:
vispy.use(app='egl')

# create some directories
os.makedirs(config['mesh_folder'], exist_ok=True)
os.makedirs(config['video_folder'], exist_ok=True)
os.makedirs(config['depth_folder'], exist_ok=True)
sample_list = get_MiDaS_samples(config['src_folder'], config['depth_folder'], config, config['specific'])
sample_list = get_MiDaS_samples(config['src_folder'], config['depth_folder'], config, config['specific']) # dict of important stuffs
normal_canvas, all_canvas = None, None

# find device
if isinstance(config["gpu_ids"], int) and (config["gpu_ids"] >= 0):
device = config["gpu_ids"]
else:
device = "cpu"

print(f"running on device {device}")

# iterate over each image.
for idx in tqdm(range(len(sample_list))):
depth = None
sample = sample_list[idx]
sample = sample_list[idx] # select image
print("Current Source ==> ", sample['src_pair_name'])
mesh_fi = os.path.join(config['mesh_folder'], sample['src_pair_name'] +'.ply')
image = imageio.imread(sample['ref_img_fi'])

print(f"Running depth extraction at {time.time()}")
if config['require_midas'] is True:
run_depth([sample['ref_img_fi']], config['src_folder'], config['depth_folder'],
run_depth([sample['ref_img_fi']], config['src_folder'], config['depth_folder'], # compute depth
config['MiDaS_model_ckpt'], MonoDepthNet, MiDaS_utils, target_w=640)
if 'npy' in config['depth_format']:
config['output_h'], config['output_w'] = np.load(sample['depth_fi']).shape[:2]
else:
config['output_h'], config['output_w'] = imageio.imread(sample['depth_fi']).shape[:2]

frac = config['longer_side_len'] / max(config['output_h'], config['output_w'])
config['output_h'], config['output_w'] = int(config['output_h'] * frac), int(config['output_w'] * frac)
config['original_h'], config['original_w'] = config['output_h'], config['output_w']
Expand All @@ -65,32 +76,40 @@
config['gray_image'] = True
else:
config['gray_image'] = False

image = cv2.resize(image, (config['output_w'], config['output_h']), interpolation=cv2.INTER_AREA)
depth = read_MiDaS_depth(sample['depth_fi'], 3.0, config['output_h'], config['output_w'])

depth = read_MiDaS_depth(sample['depth_fi'], 3.0, config['output_h'], config['output_w']) # read normalized depth computed

mean_loc_depth = depth[depth.shape[0]//2, depth.shape[1]//2]

if not(config['load_ply'] is True and os.path.exists(mesh_fi)):
vis_photos, vis_depths = sparse_bilateral_filtering(depth.copy(), image.copy(), config, num_iter=config['sparse_iter'], spdb=False)
vis_photos, vis_depths = sparse_bilateral_filtering(depth.copy(), image.copy(), config, num_iter=config['sparse_iter'], spdb=False) # do bilateral filtering
depth = vis_depths[-1]
model = None
torch.cuda.empty_cache()

## MODEL INITS

print("Start Running 3D_Photo ...")
print(f"Loading edge model at {time.time()}")
depth_edge_model = Inpaint_Edge_Net(init_weights=True)
depth_edge_model = Inpaint_Edge_Net(init_weights=True) # init edge inpainting model
depth_edge_weight = torch.load(config['depth_edge_model_ckpt'],
map_location=torch.device(device))
depth_edge_model.load_state_dict(depth_edge_weight)
depth_edge_model = depth_edge_model.to(device)
depth_edge_model.eval()
depth_edge_model.eval() # in eval mode

print(f"Loading depth model at {time.time()}")
depth_feat_model = Inpaint_Depth_Net()
depth_feat_model = Inpaint_Depth_Net() # init depth inpainting model
depth_feat_weight = torch.load(config['depth_feat_model_ckpt'],
map_location=torch.device(device))
depth_feat_model.load_state_dict(depth_feat_weight, strict=True)
depth_feat_model = depth_feat_model.to(device)
depth_feat_model.eval()
depth_feat_model = depth_feat_model.to(device)
print(f"Loading rgb model at {time.time()}")

print(f"Loading rgb model at {time.time()}") # init color inpainting model
rgb_model = Inpaint_Color_Net()
rgb_feat_weight = torch.load(config['rgb_feat_model_ckpt'],
map_location=torch.device(device))
Expand All @@ -101,7 +120,8 @@


print(f"Writing depth ply (and basically doing everything) at {time.time()}")
rt_info = write_ply(image,
# do some mesh work
rt_info = write_ply(image,
depth,
sample['int_mtx'],
mesh_fi,
Expand All @@ -119,7 +139,7 @@
depth_feat_model = None
torch.cuda.empty_cache()
if config['save_ply'] is True or config['load_ply'] is True:
verts, colors, faces, Height, Width, hFov, vFov = read_ply(mesh_fi)
verts, colors, faces, Height, Width, hFov, vFov = read_ply(mesh_fi) # read from whatever mesh thing has done
else:
verts, colors, faces, Height, Width, hFov, vFov = rt_info

Expand All @@ -135,3 +155,18 @@
image.copy(), copy.deepcopy(sample['int_mtx']), config, image,
videos_poses, video_basename, config.get('original_h'), config.get('original_w'), border=border, depth=depth, normal_canvas=normal_canvas, all_canvas=all_canvas,
mean_loc_depth=mean_loc_depth)

wandb.init(entity='authors', project='3D-Inpainting')

for vid_file in os.listdir('video/'):

wandb.log({'{}'.format(vid_file.split('.')[0]): wandb.Video('video/'+vid_file)})

for img_file in os.listdir('image/'):
wandb.log({'{}'.format(img_file.split('.')[0]): [wandb.Image("image/{}".format(img_file))]})

for depth_file in os.listdir('depth/'):
if depth_file.endswith('.npy'):
depth_img = np.load("depth/{}".format(depth_file))
wandb.log({'{}'.format(depth_file.split('.')[0]): [wandb.Image(depth_img)]})

1 change: 1 addition & 0 deletions mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1826,6 +1826,7 @@ def write_ply(image,
depth_edge_model,
depth_edge_model_init,
depth_feat_model):

depth = depth.astype(np.float64)
input_mesh, xy2depth, image, depth = create_mesh(depth, image, int_mtx, config)

Expand Down
3 changes: 2 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ def clean_far_edge(mask_edge, mask_edge_with_id, context_edge, mask, info_on_pix

return far_edge, uncleaned_far_edge, far_edge_with_id, near_edge_with_id

# called by main after creating some directories.
def get_MiDaS_samples(image_folder, depth_folder, config, specific=None, aft_certain=None):
lines = [os.path.splitext(os.path.basename(xx))[0] for xx in glob.glob(os.path.join(image_folder, '*' + config['img_format']))]
samples = []
Expand Down Expand Up @@ -949,7 +950,7 @@ def read_MiDaS_depth(disp_fi, disp_rescale=10., h=None, w=None):
disp = (disp / disp.max()) * disp_rescale
if h is not None and w is not None:
disp = resize(disp / disp.max(), (h, w), order=1) * disp.max()
depth = 1. / np.maximum(disp, 0.05)
depth = 1. / np.maximum(disp, 0.05) # normalize depth

return depth

Expand Down