MCPcopy
hub / github.com/shunsukesaito/PIFu / gen_mesh_color

Function gen_mesh_color

lib/train_util.py:73–112  ·  view source on GitHub ↗
(opt, netG, netC, cuda, data, save_path, use_octree=True)

Source from the content-addressed store, hash-verified

71 print('Can not create marching cubes at this time.')
72
73def gen_mesh_color(opt, netG, netC, cuda, data, save_path, use_octree=True):
74 image_tensor = data['img'].to(device=cuda)
75 calib_tensor = data['calib'].to(device=cuda)
76
77 netG.filter(image_tensor)
78 netC.filter(image_tensor)
79 netC.attach(netG.get_im_feat())
80
81 b_min = data['b_min']
82 b_max = data['b_max']
83 try:
84 save_img_path = save_path[:-4] + '.png'
85 save_img_list = []
86 for v in range(image_tensor.shape[0]):
87 save_img = (np.transpose(image_tensor[v].detach().cpu().numpy(), (1, 2, 0)) * 0.5 + 0.5)[:, :, ::-1] * 255.0
88 save_img_list.append(save_img)
89 save_img = np.concatenate(save_img_list, axis=1)
90 Image.fromarray(np.uint8(save_img[:,:,::-1])).save(save_img_path)
91
92 verts, faces, _, _ = reconstruction(
93 netG, cuda, calib_tensor, opt.resolution, b_min, b_max, use_octree=use_octree)
94
95 # Now Getting colors
96 verts_tensor = torch.from_numpy(verts.T).unsqueeze(0).to(device=cuda).float()
97 verts_tensor = reshape_sample_tensor(verts_tensor, opt.num_views)
98 color = np.zeros(verts.shape)
99 interval = 10000
100 for i in range(len(color) // interval):
101 left = i * interval
102 right = i * interval + interval
103 if i == len(color) // interval - 1:
104 right = -1
105 netC.query(verts_tensor[:, :, left:right], calib_tensor)
106 rgb = netC.get_preds()[0].detach().cpu().numpy() * 0.5 + 0.5
107 color[left:right] = rgb.T
108
109 save_obj_mesh_with_color(save_path, verts, faces, color)
110 except Exception as e:
111 print(e)
112 print('Can not create marching cubes at this time.')
113
114def adjust_learning_rate(optimizer, epoch, lr, schedule, gamma):
115 """Sets the learning rate to the initial LR decayed by schedule"""

Callers

nothing calls this directly

Calls 8

reconstructionFunction · 0.85
save_obj_mesh_with_colorFunction · 0.85
attachMethod · 0.80
get_im_featMethod · 0.80
get_predsMethod · 0.80
reshape_sample_tensorFunction · 0.70
filterMethod · 0.45
queryMethod · 0.45

Tested by

no test coverage detected