예제 #1
0
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + 'layers')

from torch import nn
import torch.optim as optim
from torch.autograd import Function

from layers.graph_loss_layer import GraphLossLayer, Finalize
import pyDeform

source_path = sys.argv[1]
reference_path = sys.argv[2]
output_path = sys.argv[3]
rigidity = float(sys.argv[4])

src_V, src_F, src_E, src_to_graph, graph_V, graph_E\
 = pyDeform.LoadCadMesh(source_path)

tar_V, tar_F = pyDeform.LoadMesh(reference_path)

graph_deform = GraphLossLayer(graph_V, graph_E, tar_V, tar_F, rigidity)
param_id = graph_deform.param_id
graph_V = nn.Parameter(graph_V)

optimizer = optim.Adam([graph_V], lr=1e-3)

niter = 10000
for it in range(0, niter):
    optimizer.zero_grad()
    loss = graph_deform(graph_V, graph_E)
    loss.backward()
    optimizer.step()
예제 #2
0
import argparse

parser = argparse.ArgumentParser(description='Rigid Deformation.')
parser.add_argument('--source', default='../data/cad-source.obj')
parser.add_argument('--target', default='../data/cad-target.obj')
parser.add_argument('--output', default='./cad-output.obj')
parser.add_argument('--rigidity', default='1')

args = parser.parse_args()

source_path = args.source
reference_path = args.target
output_path = args.output
rigidity = float(args.rigidity)
src_V, src_F, src_E, src_to_graph, graph_V, graph_E\
 = pyDeform.LoadCadMesh(source_path)

tar_V, tar_F, tar_E, tar_to_graph, graph_V_tar, graph_E_tar\
 = pyDeform.LoadCadMesh(reference_path)

graph_deform = GraphLossLayer(graph_V, graph_E, tar_V, tar_F, rigidity)
param_id = graph_deform.param_id
reverse_deform = ReverseLossLayer()

graph_V = nn.Parameter(graph_V)
optimizer = optim.Adam([graph_V], lr=1e-3)

pyDeform.NormalizeByTemplate(graph_V_tar, param_id.tolist())
loss_src2tar, loss_tar2src = None, None
niter = 10000
prev_loss_src, prev_loss_tar = 1e30, 1e30
예제 #3
0
parser.add_argument('--target', default='../data/cad-target.obj')
parser.add_argument('--output', default='./cad-output.obj')
parser.add_argument('--rigidity', default='0.1')
parser.add_argument('--device', default='cuda')
parser.add_argument('--save_path', default='./cad-output.ckpt')

args = parser.parse_args()

source_path = args.source
reference_path = args.target
output_path = args.output
rigidity = float(args.rigidity)
save_path = args.save_path
device = torch.device(args.device)

V1, F1, E1, V2G1, GV1, GE1 = pyDeform.LoadCadMesh(source_path)
V2, F2, E2, V2G2, GV2, GE2 = pyDeform.LoadCadMesh(reference_path)

graph_loss = GraphLoss2Layer(V1, F1, GV1, GE1, V2, F2, GV2, GE2, rigidity,
                             device)
param_id1 = graph_loss.param_id1
param_id2 = graph_loss.param_id2

reverse_loss = ReverseLossLayer()

#func = MAF(5, 3, 256, 1, None, 'relu', 'sequential', batch_norm=False)
#func = func.to(device)
func = NeuralODE(device)

optimizer = optim.Adam(func.parameters(), lr=1e-3)
GV1_origin = GV1.clone()