Ejemplo n.º 1
0
    def __init__(self, HR=0, nepoch=3000, model_path='trained_models/sup_human_network_last.pth', num_points=6890,
                 num_angles=100, clean=1, scale=1, project_on_target=0, save_path=None, LR_input=True):
        self.LR_input = LR_input
        self.HR = HR
        self.nepoch = nepoch
        self.model_path = model_path
        self.num_points = num_points
        self.num_angles = num_angles
        self.clean = clean
        self.scale = scale
        self.project_on_target = project_on_target
        self.distChamfer = ext.chamferDist()

        # load network
        self.network = model.AE_AtlasNet_Humans(num_points=self.num_points)
        self.network.cuda()
        self.network.apply(my_utils.weights_init)
        if self.model_path != '':
            print("Reload weights from : ", self.model_path)
            self.network.load_state_dict(torch.load(self.model_path))
        self.network.eval()

        self.neigh = NearestNeighbors(1, 0.4)
        self.mesh_ref = trimesh.load("./data/template/template_dense.ply", process=False)
        self.mesh_ref_LR = trimesh.load("./data/template/template.ply", process=False)

        # load colors
        self.red_LR = np.load("./data/template/red_LR.npy").astype("uint8")
        self.green_LR = np.load("./data/template/green_LR.npy").astype("uint8")
        self.blue_LR = np.load("./data/template/blue_LR.npy").astype("uint8")
        self.red_HR = np.load("./data/template/red_HR.npy").astype("uint8")
        self.green_HR = np.load("./data/template/green_HR.npy").astype("uint8")
        self.blue_HR = np.load("./data/template/blue_HR.npy").astype("uint8")
        self.save_path ="./results_HR_truth" #save_path
def test_chamfer():
    distChamfer = ext.chamferDist()
    p1 = torch.rand(4, 100, 3).cuda()
    p2 = torch.rand(4, 100, 3).cuda()
    points1 = Variable(p1, requires_grad=True)
    points2 = Variable(p2)
    dist1, dist2, = distChamfer(points1, points2)

    loss = torch.sum(dist1)
    print(loss)
    loss.backward()
    print(points1.grad, points2.grad)

    mydist1, mydist2 = mydistChamfer(points1, points2)
    d1 = (dist1 - mydist1)**2
    d2 = (dist2 - mydist2)**2
    assert (
        torch.sum(d1) + torch.sum(d1) < 0.00000001
    ), "chamfer cuda and chamfer normal are not giving the same results"
Ejemplo n.º 3
0
import argparse
import random
import numpy as np
import torch
import torch.optim as optim
import torch.nn as nn
import model
import ply
import time
from sklearn.neighbors import NearestNeighbors

sys.path.append("./extension/")
sys.path.append("/app/python/")
import dist_chamfer as ext

distChamfer = ext.chamferDist()
import trimesh
import torch
import pandas as pd
import os
os.environ['CUDA_VISIBLE_DEVICES'] = "0"
from mpl_toolkits import mplot3d

import matplotlib.pyplot as plt
import pointcloud_processor
class SMPL_t(object):
    def __init__(self, HR=0, nepoch=3000, num_points=6890,
                 num_angles=100,save_path=None):
        self.save_path = save_path
        self.right_arm=np.load("./data/output/left_hand_indices_t.npy")
        self.red_LR = np.load("./data/template/red_LR.npy").astype("uint8")
Ejemplo n.º 4
0
from __future__ import print_function
import sys
import torch

sys.path.append("./extension/")
import dist_chamfer as ext
distChamferL2 = ext.chamferDist()


def ChamferLoss(target, prediction):

    dist1, dist2 = distChamferL2(target, prediction)
    loss = torch.mean(dist1) + torch.mean(dist2)

    return loss


class LOSS_LIST:
    """list of all the model"""
    def __init__(self):

        self.losses = {
            "AtlasNet": ChamferLoss,
            "PatchDeformation": ChamferLoss,
            "PointTranslation": ChamferLoss,
        }

    def load(self, options):

        loss = self.losses[options.model]
        return loss
Ejemplo n.º 5
0
 def __init__(self, model):
     super(FullModel, self).__init__()
     self.model = model
     self.EMD = emd.emdModule()
     self.CD = cd.chamferDist()
Ejemplo n.º 6
0
from model import *
from utils import *
import argparse
import random
import numpy as np
import torch
import h5py
import os
import visdom
sys.path.append("./emd/")
import emd_module as emd
sys.path.append("./chamfer/")
import dist_chamfer as cd
from dataset import resample_pcd, read_points
EMD = emd.emdModule()
CD = cd.chamferDist()


def points_save(points, colors, root='pcds/regions', child='all', pfile=''):
    os.makedirs(root, exist_ok=True)
    os.makedirs(root + '/' + child, exist_ok=True)
    pcd = o3d.PointCloud()
    pcd.points = o3d.Vector3dVector(np.float32(points))
    pcd.colors = o3d.Vector3dVector(np.float32(colors))
    o3d.write_point_cloud(os.path.join(root, '%s.pcd' % pfile),
                          pcd,
                          write_ascii=True,
                          compressed=True)


parser = argparse.ArgumentParser()
Ejemplo n.º 7
0
import torch.optim as optim
import torch.utils.data
import torchvision.datasets as dset
import torchvision.transforms as transforms
import torchvision.utils as vutils
import torch.nn.functional as F
import torch.cuda as cuda
from pic2points import pic2points
from torch.nn.parallel import DataParallel
from sklearn.model_selection import train_test_split
from data_loader import ShapeNet
from torch.autograd import Variable
import torch
from dist_chamfer import chamferDist

distChamfer = chamferDist()

parser = argparse.ArgumentParser()
parser.add_argument('--batchSize',
                    type=int,
                    default=8,
                    help='input batch size')
parser.add_argument('--num_points',
                    type=int,
                    default=2048,
                    help='input batch size')
parser.add_argument('--workers',
                    type=int,
                    help='number of data loading workers',
                    default=8)
parser.add_argument('--nepoch',
Ejemplo n.º 8
0
import torch
import dist_chamfer
dist = dist_chamfer.chamferDist()

with torch.enable_grad():
    p1 = torch.rand(10, 1000, 6)
    p2 = torch.rand(10, 1500, 6)
    p1.requires_grad = True
    p2.requires_grad = True
    points1 = p1.cuda()
    points2 = p2.cuda()
    cost, _ = dist(points1, points2)
    print(cost)
    loss = torch.sum(cost)
    print(loss)
    loss.backward()
    print(points1.grad, points2.grad)
Ejemplo n.º 9
0
import torch.optim as optim
from torch.nn.parameter import Parameter
import torch.utils.data
import torchvision.transforms as transforms
import torchvision.utils as vutils
from torch.autograd import Variable
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import pdb
import torch.nn.functional as F
import resnet
import math
sys.path.append("./ext/")
import dist_chamfer as ext
cd = ext.chamferDist()
knn = ext.knn


class CurveCDLoss(nn.Module):
    def __init__(self, k=8):
        super(CurveCDLoss, self).__init__()
        self.k_ = k

    def forward(self, xyz1, xyz2, w=0.1):
        c1 = self.curve(xyz1)
        s1 = torch.cat([xyz1, w * c1], dim=2)
        c2 = self.curve(xyz2)
        s2 = torch.cat([xyz2, w * c2], dim=2)
        d1, d2 = cd(s1.contiguous(), s2.contiguous())
        loss = (torch.mean(d1)) + (torch.mean(d2))